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

Side by Side Diff: ppapi/examples/2d/paint_manager_example.cc

Issue 7215030: Don't copy the Graphics2D when binding a new one. This brings the (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | « ppapi/cpp/paint_manager.cc ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/c/pp_input_event.h" 5 #include "ppapi/c/pp_input_event.h"
6 #include "ppapi/cpp/graphics_2d.h" 6 #include "ppapi/cpp/graphics_2d.h"
7 #include "ppapi/cpp/image_data.h" 7 #include "ppapi/cpp/image_data.h"
8 #include "ppapi/cpp/instance.h" 8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/module.h" 9 #include "ppapi/cpp/module.h"
10 #include "ppapi/cpp/paint_manager.h" 10 #include "ppapi/cpp/paint_manager.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 default: 66 default:
67 return false; 67 return false;
68 } 68 }
69 } 69 }
70 70
71 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { 71 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) {
72 paint_manager_.SetSize(position.size()); 72 paint_manager_.SetSize(position.size());
73 } 73 }
74 74
75 // PaintManager::Client implementation. 75 // PaintManager::Client implementation.
76 virtual bool OnPaint(pp::Graphics2D&, 76 virtual bool OnPaint(pp::Graphics2D graphics_2d&,
77 const std::vector<pp::Rect>& paint_rects, 77 const std::vector<pp::Rect>& paint_rects,
78 const pp::Rect& paint_bounds) { 78 const pp::Rect& paint_bounds) {
79 // Make an image just large enough to hold all dirty rects. We won't 79 // Make an image just large enough to hold all dirty rects. We won't
80 // actually paint all of these pixels below, but rather just the dirty 80 // actually paint all of these pixels below, but rather just the dirty
81 // ones. Since image allocation can be somewhat heavyweight, we wouldn't 81 // ones. Since image allocation can be somewhat heavyweight, we wouldn't
82 // want to allocate separate images in the case of multiple dirty rects. 82 // want to allocate separate images in the case of multiple dirty rects.
83 pp::ImageData updated_image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, 83 pp::ImageData updated_image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
84 paint_bounds.size(), false); 84 paint_bounds.size(), false);
85 85
86 // We could repaint everything inside the image we made above. For this 86 // We could repaint everything inside the image we made above. For this
(...skipping 20 matching lines...) Expand all
107 // Paint the square black. Because we're lazy, we do this outside of the 107 // Paint the square black. Because we're lazy, we do this outside of the
108 // loop above. 108 // loop above.
109 pp::Rect square = SquareForPoint(last_x_, last_y_); 109 pp::Rect square = SquareForPoint(last_x_, last_y_);
110 FillRect(&updated_image, 110 FillRect(&updated_image,
111 square.x() - paint_bounds.x(), 111 square.x() - paint_bounds.x(),
112 square.y() - paint_bounds.y(), 112 square.y() - paint_bounds.y(),
113 square.width(), 113 square.width(),
114 square.height(), 114 square.height(),
115 0xFF000000); 115 0xFF000000);
116 116
117 graphics_2d.PaintImageData(updated_image, paint_bounds.point());
117 return true; 118 return true;
118 } 119 }
119 120
120 private: 121 private:
121 void UpdateSquare(int x, int y) { 122 void UpdateSquare(int x, int y) {
122 if (x == last_x_ && y == last_y_) 123 if (x == last_x_ && y == last_y_)
123 return; // Nothing changed. 124 return; // Nothing changed.
124 125
125 // Invalidate the region around the old square which needs to be repainted 126 // Invalidate the region around the old square which needs to be repainted
126 // because it's no longer there. 127 // because it's no longer there.
(...skipping 21 matching lines...) Expand all
148 }; 149 };
149 150
150 namespace pp { 151 namespace pp {
151 152
152 // Factory function for your specialization of the Module object. 153 // Factory function for your specialization of the Module object.
153 Module* CreateModule() { 154 Module* CreateModule() {
154 return new MyModule(); 155 return new MyModule();
155 } 156 }
156 157
157 } // namespace pp 158 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/paint_manager.cc ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698