OLD | NEW |
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 "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 25 matching lines...) Loading... |
36 class MyInstance : public pp::Instance, public pp::PaintManager::Client { | 36 class MyInstance : public pp::Instance, public pp::PaintManager::Client { |
37 public: | 37 public: |
38 MyInstance(PP_Instance instance) | 38 MyInstance(PP_Instance instance) |
39 : pp::Instance(instance), | 39 : pp::Instance(instance), |
40 paint_manager_(), | 40 paint_manager_(), |
41 last_x_(0), | 41 last_x_(0), |
42 last_y_(0) { | 42 last_y_(0) { |
43 paint_manager_.Initialize(this, this, false); | 43 paint_manager_.Initialize(this, this, false); |
44 } | 44 } |
45 | 45 |
46 virtual bool HandleEvent(const PP_InputEvent& event) { | 46 virtual bool HandleInputEvent(const PP_InputEvent& event) { |
47 switch (event.type) { | 47 switch (event.type) { |
48 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { | 48 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { |
49 const PP_InputEvent_Mouse& mouse_event = event.u.mouse; | 49 const PP_InputEvent_Mouse& mouse_event = event.u.mouse; |
50 // Update the square on a mouse down. | 50 // Update the square on a mouse down. |
51 if (mouse_event.button == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { | 51 if (mouse_event.button == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { |
52 UpdateSquare(static_cast<int>(mouse_event.x), | 52 UpdateSquare(static_cast<int>(mouse_event.x), |
53 static_cast<int>(mouse_event.y)); | 53 static_cast<int>(mouse_event.y)); |
54 } | 54 } |
55 return true; | 55 return true; |
56 } | 56 } |
57 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { | 57 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { |
58 const PP_InputEvent_Mouse& mouse_event = event.u.mouse; | 58 const PP_InputEvent_Mouse& mouse_event = event.u.mouse; |
59 // Update the square on a drag. | 59 // Update the square on a drag. |
60 if (mouse_event.button == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { | 60 if (mouse_event.button == PP_INPUTEVENT_MOUSEBUTTON_LEFT) { |
61 UpdateSquare(static_cast<int>(mouse_event.x), | 61 UpdateSquare(static_cast<int>(mouse_event.x), |
62 static_cast<int>(mouse_event.y)); | 62 static_cast<int>(mouse_event.y)); |
63 } | 63 } |
64 return true; | 64 return true; |
65 } | 65 } |
66 default: | 66 default: |
67 return false; | 67 return false; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 virtual void ViewChanged(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& device, | 76 virtual bool OnPaint(pp::Graphics2D&, |
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(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 |
87 // example, that would probably be the easiest thing since updates are | 87 // example, that would probably be the easiest thing since updates are |
88 // small and typically close to each other. However, for the purposes of | 88 // small and typically close to each other. However, for the purposes of |
89 // demonstration, here we only actually paint the pixels that changed, | 89 // demonstration, here we only actually paint the pixels that changed, |
90 // which may be the entire update region, or could be multiple discontigous | 90 // which may be the entire update region, or could be multiple discontigous |
91 // regions inside the update region. | 91 // regions inside the update region. |
92 // | 92 // |
93 // Note that the aggregator used by the paint manager won't give us | 93 // Note that the aggregator used by the paint manager won't give us |
(...skipping 54 matching lines...) Loading... |
148 }; | 148 }; |
149 | 149 |
150 namespace pp { | 150 namespace pp { |
151 | 151 |
152 // Factory function for your specialization of the Module object. | 152 // Factory function for your specialization of the Module object. |
153 Module* CreateModule() { | 153 Module* CreateModule() { |
154 return new MyModule(); | 154 return new MyModule(); |
155 } | 155 } |
156 | 156 |
157 } // namespace pp | 157 } // namespace pp |
OLD | NEW |