OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/pepper/pepper_compositor_host.h" | 5 #include "content/renderer/pepper/pepper_compositor_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
10 #include "cc/layers/solid_color_layer.h" | 10 #include "cc/layers/solid_color_layer.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 bool PepperCompositorHost::BindToInstance( | 152 bool PepperCompositorHost::BindToInstance( |
153 PepperPluginInstanceImpl* new_instance) { | 153 PepperPluginInstanceImpl* new_instance) { |
154 if (new_instance && new_instance->pp_instance() != pp_instance()) | 154 if (new_instance && new_instance->pp_instance() != pp_instance()) |
155 return false; // Can't bind other instance's contexts. | 155 return false; // Can't bind other instance's contexts. |
156 if (bound_instance_ == new_instance) | 156 if (bound_instance_ == new_instance) |
157 return true; // Rebinding the same device, nothing to do. | 157 return true; // Rebinding the same device, nothing to do. |
158 if (bound_instance_ && new_instance) | 158 if (bound_instance_ && new_instance) |
159 return false; // Can't change a bound device. | 159 return false; // Can't change a bound device. |
160 bound_instance_ = new_instance; | 160 bound_instance_ = new_instance; |
161 if (!bound_instance_) | |
162 SendCommitLayersReplyIfNecessary(); | |
163 | |
164 return true; | 161 return true; |
165 } | 162 } |
166 | 163 |
167 void PepperCompositorHost::ViewInitiatedPaint() { | 164 void PepperCompositorHost::ViewInitiatedPaint() { |
168 SendCommitLayersReplyIfNecessary(); | |
169 } | |
170 | |
171 void PepperCompositorHost::ViewFlushedPaint() {} | |
172 | |
173 void PepperCompositorHost::ImageReleased( | |
174 int32_t id, | |
175 const scoped_ptr<base::SharedMemory>& shared_memory, | |
176 uint32_t sync_point, | |
177 bool is_lost) { | |
178 ResourceReleased(id, sync_point, is_lost); | |
179 } | |
180 | |
181 void PepperCompositorHost::ResourceReleased(int32_t id, | |
182 uint32_t sync_point, | |
183 bool is_lost) { | |
184 host()->SendUnsolicitedReply( | |
185 pp_resource(), | |
186 PpapiPluginMsg_Compositor_ReleaseResource(id, sync_point, is_lost)); | |
187 } | |
188 | |
189 void PepperCompositorHost::SendCommitLayersReplyIfNecessary() { | |
190 if (!commit_layers_reply_context_.is_valid()) | 165 if (!commit_layers_reply_context_.is_valid()) |
191 return; | 166 return; |
192 host()->SendReply(commit_layers_reply_context_, | 167 host()->SendReply(commit_layers_reply_context_, |
193 PpapiPluginMsg_Compositor_CommitLayersReply()); | 168 PpapiPluginMsg_Compositor_CommitLayersReply()); |
194 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); | 169 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); |
195 } | 170 } |
196 | 171 |
| 172 void PepperCompositorHost::ViewFlushedPaint() {} |
| 173 |
197 void PepperCompositorHost::UpdateLayer( | 174 void PepperCompositorHost::UpdateLayer( |
198 const scoped_refptr<cc::Layer>& layer, | 175 const scoped_refptr<cc::Layer>& layer, |
199 const ppapi::CompositorLayerData* old_layer, | 176 const ppapi::CompositorLayerData* old_layer, |
200 const ppapi::CompositorLayerData* new_layer, | 177 const ppapi::CompositorLayerData* new_layer, |
201 scoped_ptr<base::SharedMemory> image_shm) { | 178 scoped_ptr<base::SharedMemory> image_shm) { |
202 // Always update properties on cc::Layer, because cc::Layer | 179 // Always update properties on cc::Layer, because cc::Layer |
203 // will ignore any setting with unchanged value. | 180 // will ignore any setting with unchanged value. |
204 layer->SetIsDrawable(true); | 181 layer->SetIsDrawable(true); |
205 layer->SetBlendMode(SkXfermode::kSrcOver_Mode); | 182 layer->SetBlendMode(SkXfermode::kSrcOver_Mode); |
206 layer->SetOpacity(new_layer->common.opacity); | 183 layer->SetOpacity(new_layer->common.opacity); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 270 |
294 // ImageData is always premultiplied alpha. | 271 // ImageData is always premultiplied alpha. |
295 image_layer->SetPremultipliedAlpha(true); | 272 image_layer->SetPremultipliedAlpha(true); |
296 } | 273 } |
297 return; | 274 return; |
298 } | 275 } |
299 // Should not be reached. | 276 // Should not be reached. |
300 NOTREACHED(); | 277 NOTREACHED(); |
301 } | 278 } |
302 | 279 |
| 280 void PepperCompositorHost::ResourceReleased(int32_t id, |
| 281 uint32_t sync_point, |
| 282 bool is_lost) { |
| 283 host()->SendUnsolicitedReply( |
| 284 pp_resource(), |
| 285 PpapiPluginMsg_Compositor_ReleaseResource(id, sync_point, is_lost)); |
| 286 } |
| 287 |
| 288 void PepperCompositorHost::ImageReleased( |
| 289 int32_t id, |
| 290 const scoped_ptr<base::SharedMemory>& shared_memory, |
| 291 uint32_t sync_point, |
| 292 bool is_lost) { |
| 293 ResourceReleased(id, sync_point, is_lost); |
| 294 } |
| 295 |
303 int32_t PepperCompositorHost::OnResourceMessageReceived( | 296 int32_t PepperCompositorHost::OnResourceMessageReceived( |
304 const IPC::Message& msg, | 297 const IPC::Message& msg, |
305 HostMessageContext* context) { | 298 HostMessageContext* context) { |
306 PPAPI_BEGIN_MESSAGE_MAP(PepperCompositorHost, msg) | 299 PPAPI_BEGIN_MESSAGE_MAP(PepperCompositorHost, msg) |
307 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 300 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
308 PpapiHostMsg_Compositor_CommitLayers, OnHostMsgCommitLayers) | 301 PpapiHostMsg_Compositor_CommitLayers, OnHostMsgCommitLayers) |
309 PPAPI_END_MESSAGE_MAP() | 302 PPAPI_END_MESSAGE_MAP() |
310 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context); | 303 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context); |
311 } | 304 } |
312 | 305 |
313 bool PepperCompositorHost::IsCompositorHost() { | 306 bool PepperCompositorHost::IsCompositorHost() { |
314 return true; | 307 return true; |
315 } | 308 } |
316 | 309 |
317 int32_t PepperCompositorHost::OnHostMsgCommitLayers( | 310 int32_t PepperCompositorHost::OnHostMsgCommitLayers( |
318 HostMessageContext* context, | 311 HostMessageContext* context, |
319 const std::vector<ppapi::CompositorLayerData>& layers, | 312 const std::vector<ppapi::CompositorLayerData>& layers, |
320 bool reset) { | 313 bool reset) { |
| 314 // Do not support CommitLayers() on an unbounded compositor. |
| 315 if (!bound_instance_) |
| 316 return PP_ERROR_FAILED; |
| 317 |
321 if (commit_layers_reply_context_.is_valid()) | 318 if (commit_layers_reply_context_.is_valid()) |
322 return PP_ERROR_INPROGRESS; | 319 return PP_ERROR_INPROGRESS; |
323 | 320 |
| 321 commit_layers_reply_context_ = context->MakeReplyMessageContext(); |
| 322 |
324 scoped_ptr<scoped_ptr<base::SharedMemory>[]> image_shms; | 323 scoped_ptr<scoped_ptr<base::SharedMemory>[]> image_shms; |
325 if (layers.size() > 0) { | 324 if (layers.size() > 0) { |
326 image_shms.reset(new scoped_ptr<base::SharedMemory>[layers.size()]); | 325 image_shms.reset(new scoped_ptr<base::SharedMemory>[layers.size()]); |
327 if (!image_shms) | 326 if (!image_shms) |
328 return PP_ERROR_NOMEMORY; | 327 return PP_ERROR_NOMEMORY; |
329 // Verfiy the layers first, if an error happens, we will return the error to | 328 // Verfiy the layers first, if an error happens, we will return the error to |
330 // plugin and keep current layers set by the previous CommitLayers() | 329 // plugin and keep current layers set by the previous CommitLayers() |
331 // unchanged. | 330 // unchanged. |
332 for (size_t i = 0; i < layers.size(); ++i) { | 331 for (size_t i = 0; i < layers.size(); ++i) { |
333 const ppapi::CompositorLayerData* old_layer = NULL; | 332 const ppapi::CompositorLayerData* old_layer = NULL; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 else | 366 else |
368 layers_.push_back(LayerData(cc_layer, *pp_layer)); | 367 layers_.push_back(LayerData(cc_layer, *pp_layer)); |
369 } | 368 } |
370 | 369 |
371 // We need to force a commit for each CommitLayers() call, even if no layers | 370 // We need to force a commit for each CommitLayers() call, even if no layers |
372 // changed since the last call to CommitLayers(). This is so | 371 // changed since the last call to CommitLayers(). This is so |
373 // WiewInitiatedPaint() will always be called. | 372 // WiewInitiatedPaint() will always be called. |
374 if (layer_->layer_tree_host()) | 373 if (layer_->layer_tree_host()) |
375 layer_->layer_tree_host()->SetNeedsCommit(); | 374 layer_->layer_tree_host()->SetNeedsCommit(); |
376 | 375 |
377 // If the host is not bound to the instance, return PP_OK immediately. | |
378 if (!bound_instance_) | |
379 return PP_OK; | |
380 | |
381 commit_layers_reply_context_ = context->MakeReplyMessageContext(); | |
382 return PP_OK_COMPLETIONPENDING; | 376 return PP_OK_COMPLETIONPENDING; |
383 } | 377 } |
384 | 378 |
385 } // namespace content | 379 } // namespace content |
OLD | NEW |