Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: content/renderer/pepper/pepper_compositor_host.cc

Issue 324983005: [PPAPI] Add browser tests for compositor API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@compositor_api_impl_new
Patch Set: Remove change in base folder. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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)
309 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
310 PpapiHostMsg_Compositor_Release, OnHostMsgRelease)
302 PPAPI_END_MESSAGE_MAP() 311 PPAPI_END_MESSAGE_MAP()
303 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context); 312 return ppapi::host::ResourceHost::OnResourceMessageReceived(msg, context);
304 } 313 }
305 314
306 bool PepperCompositorHost::IsCompositorHost() { 315 bool PepperCompositorHost::IsCompositorHost() {
307 return true; 316 return true;
308 } 317 }
309 318
310 int32_t PepperCompositorHost::OnHostMsgCommitLayers( 319 int32_t PepperCompositorHost::OnHostMsgCommitLayers(
311 HostMessageContext* context, 320 HostMessageContext* context,
312 const std::vector<ppapi::CompositorLayerData>& layers, 321 const std::vector<ppapi::CompositorLayerData>& layers,
313 bool reset) { 322 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()) 323 if (commit_layers_reply_context_.is_valid())
319 return PP_ERROR_INPROGRESS; 324 return PP_ERROR_INPROGRESS;
320 325
321 commit_layers_reply_context_ = context->MakeReplyMessageContext();
322
323 scoped_ptr<scoped_ptr<base::SharedMemory>[]> image_shms; 326 scoped_ptr<scoped_ptr<base::SharedMemory>[]> image_shms;
324 if (layers.size() > 0) { 327 if (layers.size() > 0) {
325 image_shms.reset(new scoped_ptr<base::SharedMemory>[layers.size()]); 328 image_shms.reset(new scoped_ptr<base::SharedMemory>[layers.size()]);
326 if (!image_shms) 329 if (!image_shms)
327 return PP_ERROR_NOMEMORY; 330 return PP_ERROR_NOMEMORY;
328 // Verfiy the layers first, if an error happens, we will return the error to 331 // 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() 332 // plugin and keep current layers set by the previous CommitLayers()
330 // unchanged. 333 // unchanged.
331 for (size_t i = 0; i < layers.size(); ++i) { 334 for (size_t i = 0; i < layers.size(); ++i) {
332 const ppapi::CompositorLayerData* old_layer = NULL; 335 const ppapi::CompositorLayerData* old_layer = NULL;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 else 369 else
367 layers_.push_back(LayerData(cc_layer, *pp_layer)); 370 layers_.push_back(LayerData(cc_layer, *pp_layer));
368 } 371 }
369 372
370 // We need to force a commit for each CommitLayers() call, even if no layers 373 // 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 374 // changed since the last call to CommitLayers(). This is so
372 // WiewInitiatedPaint() will always be called. 375 // WiewInitiatedPaint() will always be called.
373 if (layer_->layer_tree_host()) 376 if (layer_->layer_tree_host())
374 layer_->layer_tree_host()->SetNeedsCommit(); 377 layer_->layer_tree_host()->SetNeedsCommit();
375 378
379 // If the host is not bound to the instance, return PP_OK immediately.
380 if (!bound_instance_)
381 return PP_OK;
382
383 commit_layers_reply_context_ = context->MakeReplyMessageContext();
376 return PP_OK_COMPLETIONPENDING; 384 return PP_OK_COMPLETIONPENDING;
377 } 385 }
378 386
387 int32_t PepperCompositorHost::OnHostMsgRelease(HostMessageContext* context) {
388 SendCommitLayersReplyIfNecessary();
389 layer_->RemoveAllChildren();
390 layers_.clear();
391 return PP_OK;
392 }
393
379 } // namespace content 394 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698