aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmedia/llmediaimplexample1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmedia/llmediaimplexample1.cpp')
-rw-r--r--linden/indra/llmedia/llmediaimplexample1.cpp231
1 files changed, 0 insertions, 231 deletions
diff --git a/linden/indra/llmedia/llmediaimplexample1.cpp b/linden/indra/llmedia/llmediaimplexample1.cpp
deleted file mode 100644
index fe7b7e2..0000000
--- a/linden/indra/llmedia/llmediaimplexample1.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
1/**
2 * @file llmediaimplexample1.cpp
3 * @brief Example 1 of a media impl concrete class
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2009, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at
21 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
22 *
23 * By copying, modifying or distributing this software, you acknowledge
24 * that you have read and understood your obligations described above,
25 * and agree to abide by those obligations.
26 *
27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
29 * COMPLETENESS OR PERFORMANCE.
30 * $/LicenseInfo$
31 */
32
33#include "llmediaimplexample1.h"
34#include "llmediaimplregister.h"
35
36#include <cstring>
37
38// register this impl with media manager factory
39static LLMediaImplRegister sLLMediaImplExample1Reg( "LLMediaImplExample1", new LLMediaImplExample1Maker() );
40
41#include <iostream>
42
43#include <time.h>
44
45///////////////////////////////////////////////////////////////////////////////
46//
47LLMediaImplExample1Maker::LLMediaImplExample1Maker()
48{
49 // Register to handle the scheme
50 mSchema.push_back( "example1" );
51}
52
53///////////////////////////////////////////////////////////////////////////////
54//
55LLMediaImplExample1::LLMediaImplExample1() :
56 mMediaPixels( 0 )
57{
58 setRequestedMediaSize( 400, 200 );
59 setMediaDepth( 3 );
60
61 srand( (unsigned int)(time( NULL )) );
62}
63
64////////////////////////////////////////////////////////////////////////////////
65// (static) super-initialization - called once at application startup
66bool LLMediaImplExample1::startup( LLMediaManagerData* init_data )
67{
68 return true;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72// (static) super-uninitialization - called once at application closedown
73bool LLMediaImplExample1::closedown()
74{
75 return true;
76}
77
78////////////////////////////////////////////////////////////////////////////////
79// virtual
80bool LLMediaImplExample1::init()
81{
82 int buffer_size = getMediaBufferSize();
83
84 mMediaPixels = new unsigned char[ buffer_size ];
85
86 memset( mMediaPixels, 0xAA, buffer_size );
87
88 return true;
89}
90
91////////////////////////////////////////////////////////////////////////////////
92// virtual
93bool LLMediaImplExample1::navigateTo( const std::string url )
94{
95 std::cout << "LLMediaImplExample1::navigateTo" << std::endl;
96
97 setStatus( LLMediaBase::STATUS_NAVIGATING );
98
99 // force a size change event for new URL
100 LLMediaEvent event( this );
101 mEventEmitter.update( &LLMediaObserver::onMediaSizeChange, event );
102
103 return true;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107// virtual
108std::string LLMediaImplExample1::getVersion()
109{
110 std::string version_string = "[" + sLLMediaImplExample1Reg.getImplName() + "] - " + "1.0.0.0";
111
112 return version_string;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116// virtual
117bool LLMediaImplExample1::updateMedia()
118{
119 if ( mMediaPixels && getStatus() == LLMediaBase::STATUS_STARTED )
120 {
121 // first time - make sure it's a few seconds back so first update happens immediately
122 static time_t t = time( 0 ) - 4;
123
124 // selected time period elapsed (1 second)
125 if ( time( 0 ) - t > 1 )
126 {
127 // display checkerboard
128 const int num_squares = rand() % 20 + 4;
129 int sqr1_r = rand() % 0x80;
130 int sqr1_g = rand() % 0x80;
131 int sqr1_b = rand() % 0x80;
132 int sqr2_r = rand() % 0x80;
133 int sqr2_g = rand() % 0x80;
134 int sqr2_b = rand() % 0x80;
135
136 for ( int y1 = 0; y1 < num_squares; ++y1 )
137 {
138 for ( int x1 = 0; x1 < num_squares; ++x1 )
139 {
140 int px_start = getMediaWidth() * x1 / num_squares;
141 int px_end = ( getMediaWidth() * ( x1 + 1 ) ) / num_squares;
142 int py_start = getMediaHeight() * y1 / num_squares;
143 int py_end = ( getMediaHeight() * ( y1 + 1 ) ) / num_squares;
144
145 for( int y2 = py_start; y2 < py_end; ++y2 )
146 {
147 for( int x2 = px_start; x2 < px_end; ++x2 )
148 {
149 int rowspan = getMediaWidth() * getMediaDepth();
150
151 if ( ( y1 % 2 ) ^ ( x1 % 2 ) )
152 {
153 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 0 ] = sqr1_r;
154 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 1 ] = sqr1_g;
155 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 2 ] = sqr1_b;
156 }
157 else
158 {
159 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 0 ] = sqr2_r;
160 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 1 ] = sqr2_g;
161 mMediaPixels[ y2 * rowspan + x2 * getMediaDepth() + 2 ] = sqr2_b;
162 };
163 };
164 };
165 };
166 };
167
168 // emit an event to say that something in the media stream changed
169 LLMediaEvent event( this );
170 mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event );
171
172 // reset time
173 t = time( 0 );
174
175 return true;
176 };
177 };
178
179 // update the command (e.g. transport controls) state
180 updateCommand();
181
182 return false;
183}
184
185////////////////////////////////////////////////////////////////////////////////
186// virtual
187unsigned char* LLMediaImplExample1::getMediaData()
188{
189 return mMediaPixels;
190}
191
192////////////////////////////////////////////////////////////////////////////////
193// virtual
194bool LLMediaImplExample1::reset()
195{
196 if ( mMediaPixels )
197 {
198 delete [] mMediaPixels;
199 };
200
201 return true;
202}
203
204////////////////////////////////////////////////////////////////////////////////
205// virtual
206bool LLMediaImplExample1::mouseMove( int x_pos, int y_pos )
207{
208 if ( mMediaPixels && getStatus() == LLMediaBase::STATUS_STARTED )
209 {
210 int base_pos = x_pos * getMediaDepth() + y_pos * getMediaDepth() * getMediaWidth();
211 // example: write a bright pixel to the display when we move the mouse
212 mMediaPixels[ base_pos + 0 ] = rand() % 0x80 + 0x80;
213 mMediaPixels[ base_pos + 1 ] = rand() % 0x80 + 0x80;
214 mMediaPixels[ base_pos + 2 ] = rand() % 0x80 + 0x80;
215
216 // emit an event to say that something in the media stream changed
217 LLMediaEvent event( this );
218 mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event );
219 };
220
221 return true;
222}
223
224
225////////////////////////////////////////////////////////////////////////////////
226// virtual
227bool LLMediaImplExample1::setRequestedMediaSize( int width, int height )
228{
229 // we accept any size:
230 return setMediaSize(width, height);
231}