OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/proxy/graphics_2d_resource.h" | 5 #include "ppapi/proxy/graphics_2d_resource.h" |
6 | 6 |
7 #include "ppapi/c/pp_bool.h" | 7 #include "ppapi/c/pp_bool.h" |
8 #include "ppapi/c/pp_point.h" | 8 #include "ppapi/c/pp_point.h" |
9 #include "ppapi/c/pp_rect.h" | 9 #include "ppapi/c/pp_rect.h" |
10 #include "ppapi/c/pp_resource.h" | 10 #include "ppapi/c/pp_resource.h" |
11 #include "ppapi/c/pp_size.h" | 11 #include "ppapi/c/pp_size.h" |
12 #include "ppapi/c/ppb_graphics_2d.h" | 12 #include "ppapi/c/ppb_graphics_2d.h" |
13 #include "ppapi/proxy/dispatch_reply_message.h" | 13 #include "ppapi/proxy/dispatch_reply_message.h" |
14 #include "ppapi/proxy/plugin_dispatcher.h" | 14 #include "ppapi/proxy/plugin_dispatcher.h" |
| 15 #include "ppapi/proxy/plugin_globals.h" |
15 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
16 #include "ppapi/shared_impl/ppapi_globals.h" | 17 #include "ppapi/shared_impl/ppapi_globals.h" |
17 #include "ppapi/shared_impl/resource_tracker.h" | 18 #include "ppapi/shared_impl/resource_tracker.h" |
18 #include "ppapi/shared_impl/tracked_callback.h" | 19 #include "ppapi/shared_impl/tracked_callback.h" |
19 #include "ppapi/thunk/enter.h" | 20 #include "ppapi/thunk/enter.h" |
20 #include "ppapi/thunk/ppb_image_data_api.h" | 21 #include "ppapi/thunk/ppb_image_data_api.h" |
21 | 22 |
22 namespace ppapi { | 23 namespace ppapi { |
23 namespace proxy { | 24 namespace proxy { |
24 | 25 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 const PP_Point* top_left, | 59 const PP_Point* top_left, |
59 const PP_Rect* src_rect) { | 60 const PP_Rect* src_rect) { |
60 Resource* image_object = | 61 Resource* image_object = |
61 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); | 62 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); |
62 if (!image_object || pp_instance() != image_object->pp_instance()) { | 63 if (!image_object || pp_instance() != image_object->pp_instance()) { |
63 Log(PP_LOGLEVEL_ERROR, | 64 Log(PP_LOGLEVEL_ERROR, |
64 "Graphics2DResource.PaintImageData: Bad image resource."); | 65 "Graphics2DResource.PaintImageData: Bad image resource."); |
65 return; | 66 return; |
66 } | 67 } |
67 | 68 |
| 69 PluginGlobals::Get()->OnGraphicsInvalidation(pp_instance()); |
| 70 |
68 PP_Rect dummy; | 71 PP_Rect dummy; |
69 memset(&dummy, 0, sizeof(PP_Rect)); | 72 memset(&dummy, 0, sizeof(PP_Rect)); |
70 Post(RENDERER, PpapiHostMsg_Graphics2D_PaintImageData( | 73 Post(RENDERER, PpapiHostMsg_Graphics2D_PaintImageData( |
71 image_object->host_resource(), *top_left, | 74 image_object->host_resource(), *top_left, |
72 !!src_rect, src_rect ? *src_rect : dummy)); | 75 !!src_rect, src_rect ? *src_rect : dummy)); |
73 } | 76 } |
74 | 77 |
75 void Graphics2DResource::Scroll(const PP_Rect* clip_rect, | 78 void Graphics2DResource::Scroll(const PP_Rect* clip_rect, |
76 const PP_Point* amount) { | 79 const PP_Point* amount) { |
| 80 PluginGlobals::Get()->OnGraphicsInvalidation(pp_instance()); |
77 PP_Rect dummy; | 81 PP_Rect dummy; |
78 memset(&dummy, 0, sizeof(PP_Rect)); | 82 memset(&dummy, 0, sizeof(PP_Rect)); |
79 Post(RENDERER, PpapiHostMsg_Graphics2D_Scroll( | 83 Post(RENDERER, PpapiHostMsg_Graphics2D_Scroll( |
80 !!clip_rect, clip_rect ? *clip_rect : dummy, *amount)); | 84 !!clip_rect, clip_rect ? *clip_rect : dummy, *amount)); |
81 } | 85 } |
82 | 86 |
83 void Graphics2DResource::ReplaceContents(PP_Resource image_data) { | 87 void Graphics2DResource::ReplaceContents(PP_Resource image_data) { |
84 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image( | 88 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image( |
85 image_data, true); | 89 image_data, true); |
86 if (enter_image.failed()) | 90 if (enter_image.failed()) |
87 return; | 91 return; |
88 | 92 |
89 // Check that the PP_Instance matches. | 93 // Check that the PP_Instance matches. |
90 Resource* image_object = | 94 Resource* image_object = |
91 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); | 95 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); |
92 if (!image_object || pp_instance() != image_object->pp_instance()) { | 96 if (!image_object || pp_instance() != image_object->pp_instance()) { |
93 Log(PP_LOGLEVEL_ERROR, | 97 Log(PP_LOGLEVEL_ERROR, |
94 "Graphics2DResource.PaintImageData: Bad image resource."); | 98 "Graphics2DResource.PaintImageData: Bad image resource."); |
95 return; | 99 return; |
96 } | 100 } |
| 101 PluginGlobals::Get()->OnGraphicsInvalidation(pp_instance()); |
97 enter_image.object()->SetIsCandidateForReuse(); | 102 enter_image.object()->SetIsCandidateForReuse(); |
98 | 103 |
99 Post(RENDERER, PpapiHostMsg_Graphics2D_ReplaceContents( | 104 Post(RENDERER, PpapiHostMsg_Graphics2D_ReplaceContents( |
100 image_object->host_resource())); | 105 image_object->host_resource())); |
101 } | 106 } |
102 | 107 |
103 PP_Bool Graphics2DResource::SetScale(float scale) { | 108 PP_Bool Graphics2DResource::SetScale(float scale) { |
104 if (scale <= 0.0f) | 109 if (scale <= 0.0f) |
105 return PP_FALSE; | 110 return PP_FALSE; |
106 Post(RENDERER, PpapiHostMsg_Graphics2D_SetScale(scale)); | 111 Post(RENDERER, PpapiHostMsg_Graphics2D_SetScale(scale)); |
107 scale_ = scale; | 112 scale_ = scale; |
108 return PP_TRUE; | 113 return PP_TRUE; |
109 } | 114 } |
110 | 115 |
111 float Graphics2DResource::GetScale() { | 116 float Graphics2DResource::GetScale() { |
112 return scale_; | 117 return scale_; |
113 } | 118 } |
114 | 119 |
115 int32_t Graphics2DResource::Flush(scoped_refptr<TrackedCallback> callback) { | 120 int32_t Graphics2DResource::Flush(scoped_refptr<TrackedCallback> callback) { |
116 // If host is not even created, return failure immediately. This can happen | 121 // If host is not even created, return failure immediately. This can happen |
117 // when failed to initialize (in constructor). | 122 // when failed to initialize (in constructor). |
118 if (!sent_create_to_renderer()) | 123 if (!sent_create_to_renderer()) |
119 return PP_ERROR_FAILED; | 124 return PP_ERROR_FAILED; |
120 | 125 |
121 if (TrackedCallback::IsPending(current_flush_callback_)) | 126 if (TrackedCallback::IsPending(current_flush_callback_)) |
122 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. | 127 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. |
123 current_flush_callback_ = callback; | 128 current_flush_callback_ = callback; |
124 | 129 |
| 130 std::vector<ui::LatencyInfo> latency_info; |
| 131 PluginGlobals::Get()->OnGraphicsFlush(&latency_info, pp_instance()); |
| 132 |
125 Call<PpapiPluginMsg_Graphics2D_FlushAck>( | 133 Call<PpapiPluginMsg_Graphics2D_FlushAck>( |
126 RENDERER, | 134 RENDERER, |
127 PpapiHostMsg_Graphics2D_Flush(), | 135 PpapiHostMsg_Graphics2D_Flush(latency_info), |
128 base::Bind(&Graphics2DResource::OnPluginMsgFlushACK, this)); | 136 base::Bind(&Graphics2DResource::OnPluginMsgFlushACK, this)); |
129 return PP_OK_COMPLETIONPENDING; | 137 return PP_OK_COMPLETIONPENDING; |
130 } | 138 } |
131 | 139 |
132 bool Graphics2DResource::ReadImageData(PP_Resource image, | 140 bool Graphics2DResource::ReadImageData(PP_Resource image, |
133 const PP_Point* top_left) { | 141 const PP_Point* top_left) { |
134 if (!top_left) | 142 if (!top_left) |
135 return false; | 143 return false; |
136 int32_t result = SyncCall<PpapiPluginMsg_Graphics2D_ReadImageDataAck>( | 144 int32_t result = SyncCall<PpapiPluginMsg_Graphics2D_ReadImageDataAck>( |
137 RENDERER, | 145 RENDERER, |
138 PpapiHostMsg_Graphics2D_ReadImageData(image, *top_left)); | 146 PpapiHostMsg_Graphics2D_ReadImageData(image, *top_left)); |
139 return result == PP_OK; | 147 return result == PP_OK; |
140 } | 148 } |
141 | 149 |
142 void Graphics2DResource::OnPluginMsgFlushACK( | 150 void Graphics2DResource::OnPluginMsgFlushACK( |
143 const ResourceMessageReplyParams& params) { | 151 const ResourceMessageReplyParams& params) { |
144 current_flush_callback_->Run(params.result()); | 152 current_flush_callback_->Run(params.result()); |
145 } | 153 } |
146 | 154 |
147 } // namespace proxy | 155 } // namespace proxy |
148 } // namespace ppapi | 156 } // namespace ppapi |
OLD | NEW |