Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: ppapi/example/example.cc

Issue 6214007: Added plugin size to error logging and a logging statement when the plugin size changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <math.h> 5 #include <math.h>
6 #include <stdio.h> // FIXME(brettw) erase me. 6 #include <stdio.h> // FIXME(brettw) erase me.
7 #ifndef _WIN32 7 #ifndef _WIN32
8 #include <sys/time.h> 8 #include <sys/time.h>
9 #endif 9 #endif
10 #include <time.h> 10 #include <time.h>
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 192
193 virtual pp::Var GetInstanceObject() { 193 virtual pp::Var GetInstanceObject() {
194 return new MyScriptableObject(); 194 return new MyScriptableObject();
195 } 195 }
196 196
197 pp::ImageData PaintImage(int width, int height) { 197 pp::ImageData PaintImage(int width, int height) {
198 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, 198 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL,
199 pp::Size(width, height), false); 199 pp::Size(width, height), false);
200 if (image.is_null()) { 200 if (image.is_null()) {
201 printf("Couldn't allocate the image data\n"); 201 printf("Couldn't allocate the image data: %d, %d\n", width, height);
202 return image; 202 return image;
203 } 203 }
204 204
205 // Fill with semitransparent gradient. 205 // Fill with semitransparent gradient.
206 for (int y = 0; y < image.size().height(); y++) { 206 for (int y = 0; y < image.size().height(); y++) {
207 char* row = &static_cast<char*>(image.data())[y * image.stride()]; 207 char* row = &static_cast<char*>(image.data())[y * image.stride()];
208 for (int x = 0; x < image.size().width(); x++) { 208 for (int x = 0; x < image.size().width(); x++) {
209 row[x * 4 + 0] = y; 209 row[x * 4 + 0] = y;
210 row[x * 4 + 1] = y; 210 row[x * 4 + 1] = y;
211 row[x * 4 + 2] = 0; 211 row[x * 4 + 2] = 0;
212 row[x * 4 + 3] = y; 212 row[x * 4 + 3] = y;
213 } 213 }
214 } 214 }
215 215
216 // Draw the orbiting box.
216 float radians = static_cast<float>(animation_counter_) / kStepsPerCircle * 217 float radians = static_cast<float>(animation_counter_) / kStepsPerCircle *
217 2 * 3.14159265358979F; 218 2 * 3.14159265358979F;
218 219
219 float radius = static_cast<float>(std::min(width, height)) / 2.0f - 3.0f; 220 float radius = static_cast<float>(std::min(width, height)) / 2.0f - 3.0f;
220 int x = static_cast<int>(cos(radians) * radius + radius + 2); 221 int x = static_cast<int>(cos(radians) * radius + radius + 2);
221 int y = static_cast<int>(sin(radians) * radius + radius + 2); 222 int y = static_cast<int>(sin(radians) * radius + radius + 2);
222 223
223 FillRect(&image, x - 3, y - 3, 7, 7, 0x80000000); 224 const uint32_t box_bgra = 0x80000000; // Alpha 50%.
225 FillRect(&image, x - 3, y - 3, 7, 7, box_bgra);
224 return image; 226 return image;
225 } 227 }
226 228
227 void Paint() { 229 void Paint() {
228 pp::ImageData image = PaintImage(width_, height_); 230 pp::ImageData image = PaintImage(width_, height_);
229 if (!image.is_null()) { 231 if (!image.is_null()) {
230 device_context_.ReplaceContents(&image); 232 device_context_.ReplaceContents(&image);
231 device_context_.Flush(pp::CompletionCallback(&FlushCallback, this)); 233 device_context_.Flush(pp::CompletionCallback(&FlushCallback, this));
234 } else {
235 printf("NullImage: %d, %d\n", width_, height_);
232 } 236 }
233 } 237 }
234 238
235 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { 239 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) {
236 if (position.size().width() == width_ && 240 if (position.size().width() == width_ &&
237 position.size().height() == height_) 241 position.size().height() == height_)
238 return; // We don't care about the position, only the size. 242 return; // We don't care about the position, only the size.
239 243
240 width_ = position.size().width(); 244 width_ = position.size().width();
241 height_ = position.size().height(); 245 height_ = position.size().height();
246 printf("DidChangeView relevant change: width=%d height:%d\n",
247 width_, height_);
242 248
243 device_context_ = pp::Graphics2D(pp::Size(width_, height_), false); 249 device_context_ = pp::Graphics2D(pp::Size(width_, height_), false);
244 if (!BindGraphics(device_context_)) { 250 if (!BindGraphics(device_context_)) {
245 printf("Couldn't bind the device context\n"); 251 printf("Couldn't bind the device context\n");
246 return; 252 return;
247 } 253 }
248 254
249 Paint(); 255 Paint();
250 } 256 }
251 257
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 }; 423 };
418 424
419 namespace pp { 425 namespace pp {
420 426
421 // Factory function for your specialization of the Module object. 427 // Factory function for your specialization of the Module object.
422 Module* CreateModule() { 428 Module* CreateModule() {
423 return new MyModule(); 429 return new MyModule();
424 } 430 }
425 431
426 } // namespace pp 432 } // namespace pp
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698