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