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

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

Issue 10874024: Revert the changes to the paint manager example. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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) 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/input_event.h" 8 #include "ppapi/cpp/input_event.h"
9 #include "ppapi/cpp/instance.h" 9 #include "ppapi/cpp/instance.h"
10 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 } 72 }
73 73
74 virtual void DidChangeView(const pp::View& view) { 74 virtual void DidChangeView(const pp::View& view) {
75 paint_manager_.SetSize(view.GetRect().size()); 75 paint_manager_.SetSize(view.GetRect().size());
76 } 76 }
77 77
78 // PaintManager::Client implementation. 78 // PaintManager::Client implementation.
79 virtual bool OnPaint(pp::Graphics2D& graphics_2d, 79 virtual bool OnPaint(pp::Graphics2D& graphics_2d,
80 const std::vector<pp::Rect>& paint_rects, 80 const std::vector<pp::Rect>& paint_rects,
81 const pp::Rect& paint_bounds_unused) { 81 const pp::Rect& paint_bounds) {
82 pp::Rect paint_bounds(paint_manager_.GetEffectiveSize());
83
84 // Make an image just large enough to hold all dirty rects. We won't 82 // Make an image just large enough to hold all dirty rects. We won't
85 // actually paint all of these pixels below, but rather just the dirty 83 // actually paint all of these pixels below, but rather just the dirty
86 // ones. Since image allocation can be somewhat heavyweight, we wouldn't 84 // ones. Since image allocation can be somewhat heavyweight, we wouldn't
87 // want to allocate separate images in the case of multiple dirty rects. 85 // want to allocate separate images in the case of multiple dirty rects.
88 pp::ImageData updated_image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, 86 pp::ImageData updated_image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
89 paint_bounds.size(), false); 87 paint_bounds.size(), false);
90 88
91 // We could repaint everything inside the image we made above. For this 89 // We could repaint everything inside the image we made above. For this
92 // example, that would probably be the easiest thing since updates are 90 // example, that would probably be the easiest thing since updates are
93 // small and typically close to each other. However, for the purposes of 91 // small and typically close to each other. However, for the purposes of
94 // demonstration, here we only actually paint the pixels that changed, 92 // demonstration, here we only actually paint the pixels that changed,
95 // which may be the entire update region, or could be multiple discontigous 93 // which may be the entire update region, or could be multiple discontigous
96 // regions inside the update region. 94 // regions inside the update region.
97 // 95 //
98 // Note that the aggregator used by the paint manager won't give us 96 // Note that the aggregator used by the paint manager won't give us
99 // multiple regions that overlap, so we don't have to worry about double 97 // multiple regions that overlap, so we don't have to worry about double
100 // painting in this code. 98 // painting in this code.
101 /*
102 for (size_t i = 0; i < paint_rects.size(); i++) { 99 for (size_t i = 0; i < paint_rects.size(); i++) {
103 // Since our image is just the invalid region, we need to offset the 100 // Since our image is just the invalid region, we need to offset the
104 // areas we paint by that much. This is just a light blue background. 101 // areas we paint by that much. This is just a light blue background.
105 FillRect(&updated_image, 102 FillRect(&updated_image,
106 paint_rects[i].x() - paint_bounds.x(), 103 paint_rects[i].x() - paint_bounds.x(),
107 paint_rects[i].y() - paint_bounds.y(), 104 paint_rects[i].y() - paint_bounds.y(),
108 paint_rects[i].width(), 105 paint_rects[i].width(),
109 paint_rects[i].height(), 106 paint_rects[i].height(),
110 0xFFAAAAFF); 107 0xFFAAAAFF);
111 } 108 }
112 */
113 109
114 // Paint the square black. Because we're lazy, we do this outside of the 110 // Paint the square black. Because we're lazy, we do this outside of the
115 // loop above. 111 // loop above.
116 pp::Rect square = SquareForPoint(last_x_, last_y_); 112 pp::Rect square = SquareForPoint(last_x_, last_y_);
117 FillRect(&updated_image, 113 FillRect(&updated_image,
118 square.x() - paint_bounds.x(), 114 square.x() - paint_bounds.x(),
119 square.y() - paint_bounds.y(), 115 square.y() - paint_bounds.y(),
120 square.width(), 116 square.width(),
121 square.height(), 117 square.height(),
122 0xFF000000); 118 0xFF000000);
123 119
124 graphics_2d.ReplaceContents(&updated_image); 120 graphics_2d.PaintImageData(updated_image, paint_bounds.point());
125 return true; 121 return true;
126 } 122 }
127 123
128 private: 124 private:
129 void UpdateSquare(int x, int y) { 125 void UpdateSquare(int x, int y) {
130 if (x == last_x_ && y == last_y_) 126 if (x == last_x_ && y == last_y_)
131 return; // Nothing changed. 127 return; // Nothing changed.
132 128
133 // Invalidate the region around the old square which needs to be repainted 129 // Invalidate the region around the old square which needs to be repainted
134 // because it's no longer there. 130 // because it's no longer there.
(...skipping 21 matching lines...) Expand all
156 }; 152 };
157 153
158 namespace pp { 154 namespace pp {
159 155
160 // Factory function for your specialization of the Module object. 156 // Factory function for your specialization of the Module object.
161 Module* CreateModule() { 157 Module* CreateModule() {
162 return new MyModule(); 158 return new MyModule();
163 } 159 }
164 160
165 } // namespace pp 161 } // 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