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 |
161 return true; | 164 return true; |
162 } | 165 } |
163 | 166 |
164 void PepperCompositorHost::ViewInitiatedPaint() { | 167 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() { |
165 if (!commit_layers_reply_context_.is_valid()) | 190 if (!commit_layers_reply_context_.is_valid()) |
166 return; | 191 return; |
167 host()->SendReply(commit_layers_reply_context_, | 192 host()->SendReply(commit_layers_reply_context_, |
168 PpapiPluginMsg_Compositor_CommitLayersReply()); | 193 PpapiPluginMsg_Compositor_CommitLayersReply()); |
169 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); | 194 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); |
170 } | 195 } |
171 | 196 |
172 void PepperCompositorHost::ViewFlushedPaint() {} | |
173 | |
174 void PepperCompositorHost::UpdateLayer( | 197 void PepperCompositorHost::UpdateLayer( |
175 const scoped_refptr<cc::Layer>& layer, | 198 const scoped_refptr<cc::Layer>& layer, |
176 const ppapi::CompositorLayerData* old_layer, | 199 const ppapi::CompositorLayerData* old_layer, |
177 const ppapi::CompositorLayerData* new_layer, | 200 const ppapi::CompositorLayerData* new_layer, |
178 scoped_ptr<base::SharedMemory> image_shm) { | 201 scoped_ptr<base::SharedMemory> image_shm) { |
179 // Always update properties on cc::Layer, because cc::Layer | 202 // Always update properties on cc::Layer, because cc::Layer |
180 // will ignore any setting with unchanged value. | 203 // will ignore any setting with unchanged value. |
181 layer->SetIsDrawable(true); | 204 layer->SetIsDrawable(true); |
182 layer->SetBlendMode(SkXfermode::kSrcOver_Mode); | 205 layer->SetBlendMode(SkXfermode::kSrcOver_Mode); |
183 layer->SetOpacity(new_layer->common.opacity); | 206 layer->SetOpacity(new_layer->common.opacity); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 293 |
271 // ImageData is always premultiplied alpha. | 294 // ImageData is always premultiplied alpha. |
272 image_layer->SetPremultipliedAlpha(true); | 295 image_layer->SetPremultipliedAlpha(true); |
273 } | 296 } |
274 return; | 297 return; |
275 } | 298 } |
276 // Should not be reached. | 299 // Should not be reached. |
277 NOTREACHED(); | 300 NOTREACHED(); |
278 } | 301 } |
279 | 302 |
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 | |
296 int32_t PepperCompositorHost::OnResourceMessageReceived( | 303 int32_t PepperCompositorHost::OnResourceMessageReceived( |
297 const IPC::Message& msg, | 304 const IPC::Message& msg, |
298 HostMessageContext* context) { | 305 HostMessageContext* context) { |
299 PPAPI_BEGIN_MESSAGE_MAP(PepperCompositorHost, msg) | 306 PPAPI_BEGIN_MESSAGE_MAP(PepperCompositorHost, msg) |
300 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 307 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
301 PpapiHostMsg_Compositor_CommitLayers, OnHostMsgCommitLayers) | 308 PpapiHostMsg_Compositor_CommitLayers, OnHostMsgCommitLayers) |
302 PPAPI_END_MESSAGE_MAP() | 309 PPAPI_END_MESSAGE_MAP() |
303 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context); | 310 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context); |
304 } | 311 } |
305 | 312 |
306 bool PepperCompositorHost::IsCompositorHost() { | 313 bool PepperCompositorHost::IsCompositorHost() { |
307 return true; | 314 return true; |
308 } | 315 } |
309 | 316 |
310 int32_t PepperCompositorHost::OnHostMsgCommitLayers( | 317 int32_t PepperCompositorHost::OnHostMsgCommitLayers( |
311 HostMessageContext* context, | 318 HostMessageContext* context, |
312 const std::vector<ppapi::CompositorLayerData>& layers, | 319 const std::vector<ppapi::CompositorLayerData>& layers, |
313 bool reset) { | 320 bool reset) { |
314 // Do not support CommitLayers() on an unbounded compositor. | |
315 if (!bound_instance_) | |
316 return PP_ERROR_FAILED; | |
317 | |
318 if (commit_layers_reply_context_.is_valid()) | 321 if (commit_layers_reply_context_.is_valid()) |
319 return PP_ERROR_INPROGRESS; | 322 return PP_ERROR_INPROGRESS; |
320 | 323 |
321 commit_layers_reply_context_ = context->MakeReplyMessageContext(); | |
322 | |
323 scoped_ptr<scoped_ptr<base::SharedMemory>[]> image_shms; | 324 scoped_ptr<scoped_ptr<base::SharedMemory>[]> image_shms; |
324 if (layers.size() > 0) { | 325 if (layers.size() > 0) { |
325 image_shms.reset(new scoped_ptr<base::SharedMemory>[layers.size()]); | 326 image_shms.reset(new scoped_ptr<base::SharedMemory>[layers.size()]); |
326 if (!image_shms) | 327 if (!image_shms) |
327 return PP_ERROR_NOMEMORY; | 328 return PP_ERROR_NOMEMORY; |
328 // Verfiy the layers first, if an error happens, we will return the error to | 329 // Verfiy the layers first, if an error happens, we will return the error to |
329 // plugin and keep current layers set by the previous CommitLayers() | 330 // plugin and keep current layers set by the previous CommitLayers() |
330 // unchanged. | 331 // unchanged. |
331 for (size_t i = 0; i < layers.size(); ++i) { | 332 for (size_t i = 0; i < layers.size(); ++i) { |
332 const ppapi::CompositorLayerData* old_layer = NULL; | 333 const ppapi::CompositorLayerData* old_layer = NULL; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 else | 367 else |
367 layers_.push_back(LayerData(cc_layer, *pp_layer)); | 368 layers_.push_back(LayerData(cc_layer, *pp_layer)); |
368 } | 369 } |
369 | 370 |
370 // We need to force a commit for each CommitLayers() call, even if no layers | 371 // We need to force a commit for each CommitLayers() call, even if no layers |
371 // changed since the last call to CommitLayers(). This is so | 372 // changed since the last call to CommitLayers(). This is so |
372 // WiewInitiatedPaint() will always be called. | 373 // WiewInitiatedPaint() will always be called. |
373 if (layer_->layer_tree_host()) | 374 if (layer_->layer_tree_host()) |
374 layer_->layer_tree_host()->SetNeedsCommit(); | 375 layer_->layer_tree_host()->SetNeedsCommit(); |
375 | 376 |
| 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(); |
376 return PP_OK_COMPLETIONPENDING; | 382 return PP_OK_COMPLETIONPENDING; |
377 } | 383 } |
378 | 384 |
379 } // namespace content | 385 } // namespace content |
OLD | NEW |