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

Side by Side Diff: example/example.cc

Issue 2853015: Switch FlushCallback to be a PP_CompletionCallback.... (Closed) Base URL: http://ppapi.googlecode.com/svn/trunk/
Patch Set: '' Created 10 years, 6 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 | « cpp/device_context_2d.cc ('k') | tests/test_device_context_2d.cc » ('j') | 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) eraseme. 6 #include <stdio.h> // FIXME(brettw) eraseme.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "ppapi/c/pp_event.h" 10 #include "ppapi/c/pp_event.h"
11 #include "ppapi/c/pp_rect.h" 11 #include "ppapi/c/pp_rect.h"
12 #include "ppapi/c/ppp_printing.h" 12 #include "ppapi/c/ppp_printing.h"
13 #include "ppapi/cpp/completion_callback.h"
13 #include "ppapi/cpp/device_context_2d.h" 14 #include "ppapi/cpp/device_context_2d.h"
14 #include "ppapi/cpp/image_data.h" 15 #include "ppapi/cpp/image_data.h"
15 #include "ppapi/cpp/instance.h" 16 #include "ppapi/cpp/instance.h"
16 #include "ppapi/cpp/module.h" 17 #include "ppapi/cpp/module.h"
17 #include "ppapi/cpp/scriptable_object.h" 18 #include "ppapi/cpp/scriptable_object.h"
18 #include "ppapi/cpp/var.h" 19 #include "ppapi/cpp/var.h"
19 20
20 void FlushCallback(PP_Resource context, void* data); 21 void FlushCallback(void* data, int32_t result);
21 22
22 void FillRect(pp::ImageData* image, int left, int top, int width, int height, 23 void FillRect(pp::ImageData* image, int left, int top, int width, int height,
23 uint32_t color) { 24 uint32_t color) {
24 for (int y = std::max(0, top); 25 for (int y = std::max(0, top);
25 y < std::min(image->height() - 1, top + height); 26 y < std::min(image->height() - 1, top + height);
26 y++) { 27 y++) {
27 for (int x = std::max(0, left); 28 for (int x = std::max(0, left);
28 x < std::min(image->width() - 1, left + width); 29 x < std::min(image->width() - 1, left + width);
29 x++) 30 x++)
30 *image->GetAddr32(x, y) = color; 31 *image->GetAddr32(x, y) = color;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 int y = static_cast<int>(sin(radians) * radius + radius + 2); 127 int y = static_cast<int>(sin(radians) * radius + radius + 2);
127 128
128 FillRect(&image, x - 3, y - 3, 7, 7, 0x80000000); 129 FillRect(&image, x - 3, y - 3, 7, 7, 0x80000000);
129 return image; 130 return image;
130 } 131 }
131 132
132 void Paint() { 133 void Paint() {
133 pp::ImageData image = PaintImage(width_, height_); 134 pp::ImageData image = PaintImage(width_, height_);
134 if (!image.is_null()) { 135 if (!image.is_null()) {
135 device_context_.ReplaceContents(&image); 136 device_context_.ReplaceContents(&image);
136 device_context_.Flush(&FlushCallback, this); 137 device_context_.Flush(pp::CompletionCallback(&FlushCallback, this));
137 } 138 }
138 } 139 }
139 140
140 virtual void ViewChanged(const PP_Rect& position, const PP_Rect& clip) { 141 virtual void ViewChanged(const PP_Rect& position, const PP_Rect& clip) {
141 printf("ViewChanged %d,%d,%d,%d\n", position.point.x, position.point.y, 142 printf("ViewChanged %d,%d,%d,%d\n", position.point.x, position.point.y,
142 position.size.width, position.size.height); 143 position.size.width, position.size.height);
143 if (position.size.width == width_ || position.size.height == height_) 144 if (position.size.width == width_ || position.size.height == height_)
144 return; // We don't care about the position, only the size. 145 return; // We don't care about the position, only the size.
145 146
146 width_ = position.size.width; 147 width_ = position.size.width;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 231
231 int width_; 232 int width_;
232 int height_; 233 int height_;
233 234
234 // Incremented for each flush we get. 235 // Incremented for each flush we get.
235 int animation_counter_; 236 int animation_counter_;
236 bool print_settings_valid_; 237 bool print_settings_valid_;
237 PP_PrintSettings print_settings_; 238 PP_PrintSettings print_settings_;
238 }; 239 };
239 240
240 void FlushCallback(PP_Resource context, void* data) { 241 void FlushCallback(void* data, int32_t result) {
241 static_cast<MyInstance*>(data)->OnFlush(); 242 static_cast<MyInstance*>(data)->OnFlush();
242 } 243 }
243 244
244 PP_PrintOutputFormat supported_print_formats[] = { 245 PP_PrintOutputFormat supported_print_formats[] = {
245 PP_PrintOutputFormat_Raster, 246 PP_PrintOutputFormat_Raster,
246 }; 247 };
247 248
248 class MyModule : public pp::Module { 249 class MyModule : public pp::Module {
249 public: 250 public:
250 MyModule() : pp::Module() {} 251 MyModule() : pp::Module() {}
(...skipping 12 matching lines...) Expand all
263 } 264 }
264 }; 265 };
265 266
266 namespace pp { 267 namespace pp {
267 268
268 Module* CreateModule() { 269 Module* CreateModule() {
269 return new MyModule(); 270 return new MyModule();
270 } 271 }
271 272
272 } // namespace pp 273 } // namespace pp
OLDNEW
« no previous file with comments | « cpp/device_context_2d.cc ('k') | tests/test_device_context_2d.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698