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