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

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

Issue 1873783003: Convert //content/renderer from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 <stddef.h> 7 #include <stddef.h>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 30 matching lines...) Expand all
41 namespace { 41 namespace {
42 42
43 bool CheckPPFloatRect(const PP_FloatRect& rect, float width, float height) { 43 bool CheckPPFloatRect(const PP_FloatRect& rect, float width, float height) {
44 const float kEpsilon = std::numeric_limits<float>::epsilon(); 44 const float kEpsilon = std::numeric_limits<float>::epsilon();
45 return (rect.point.x >= -kEpsilon && 45 return (rect.point.x >= -kEpsilon &&
46 rect.point.y >= -kEpsilon && 46 rect.point.y >= -kEpsilon &&
47 rect.point.x + rect.size.width <= width + kEpsilon && 47 rect.point.x + rect.size.width <= width + kEpsilon &&
48 rect.point.y + rect.size.height <= height + kEpsilon); 48 rect.point.y + rect.size.height <= height + kEpsilon);
49 } 49 }
50 50
51 int32_t VerifyCommittedLayer( 51 int32_t VerifyCommittedLayer(const ppapi::CompositorLayerData* old_layer,
52 const ppapi::CompositorLayerData* old_layer, 52 const ppapi::CompositorLayerData* new_layer,
53 const ppapi::CompositorLayerData* new_layer, 53 std::unique_ptr<base::SharedMemory>* image_shm) {
54 scoped_ptr<base::SharedMemory>* image_shm) {
55 if (!new_layer->is_valid()) 54 if (!new_layer->is_valid())
56 return PP_ERROR_BADARGUMENT; 55 return PP_ERROR_BADARGUMENT;
57 56
58 if (new_layer->color) { 57 if (new_layer->color) {
59 // Make sure the old layer is a color layer too. 58 // Make sure the old layer is a color layer too.
60 if (old_layer && !old_layer->color) 59 if (old_layer && !old_layer->color)
61 return PP_ERROR_BADARGUMENT; 60 return PP_ERROR_BADARGUMENT;
62 return PP_OK; 61 return PP_OK;
63 } 62 }
64 63
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 183
185 return true; 184 return true;
186 } 185 }
187 186
188 void PepperCompositorHost::ViewInitiatedPaint() { 187 void PepperCompositorHost::ViewInitiatedPaint() {
189 SendCommitLayersReplyIfNecessary(); 188 SendCommitLayersReplyIfNecessary();
190 } 189 }
191 190
192 void PepperCompositorHost::ImageReleased( 191 void PepperCompositorHost::ImageReleased(
193 int32_t id, 192 int32_t id,
194 scoped_ptr<base::SharedMemory> shared_memory, 193 std::unique_ptr<base::SharedMemory> shared_memory,
195 scoped_ptr<cc::SharedBitmap> bitmap, 194 std::unique_ptr<cc::SharedBitmap> bitmap,
196 const gpu::SyncToken& sync_token, 195 const gpu::SyncToken& sync_token,
197 bool is_lost) { 196 bool is_lost) {
198 bitmap.reset(); 197 bitmap.reset();
199 shared_memory.reset(); 198 shared_memory.reset();
200 ResourceReleased(id, sync_token, is_lost); 199 ResourceReleased(id, sync_token, is_lost);
201 } 200 }
202 201
203 void PepperCompositorHost::ResourceReleased(int32_t id, 202 void PepperCompositorHost::ResourceReleased(int32_t id,
204 const gpu::SyncToken& sync_token, 203 const gpu::SyncToken& sync_token,
205 bool is_lost) { 204 bool is_lost) {
206 host()->SendUnsolicitedReply( 205 host()->SendUnsolicitedReply(
207 pp_resource(), 206 pp_resource(),
208 PpapiPluginMsg_Compositor_ReleaseResource(id, sync_token, is_lost)); 207 PpapiPluginMsg_Compositor_ReleaseResource(id, sync_token, is_lost));
209 } 208 }
210 209
211 void PepperCompositorHost::SendCommitLayersReplyIfNecessary() { 210 void PepperCompositorHost::SendCommitLayersReplyIfNecessary() {
212 if (!commit_layers_reply_context_.is_valid()) 211 if (!commit_layers_reply_context_.is_valid())
213 return; 212 return;
214 host()->SendReply(commit_layers_reply_context_, 213 host()->SendReply(commit_layers_reply_context_,
215 PpapiPluginMsg_Compositor_CommitLayersReply()); 214 PpapiPluginMsg_Compositor_CommitLayersReply());
216 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); 215 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext();
217 } 216 }
218 217
219 void PepperCompositorHost::UpdateLayer( 218 void PepperCompositorHost::UpdateLayer(
220 const scoped_refptr<cc::Layer>& layer, 219 const scoped_refptr<cc::Layer>& layer,
221 const ppapi::CompositorLayerData* old_layer, 220 const ppapi::CompositorLayerData* old_layer,
222 const ppapi::CompositorLayerData* new_layer, 221 const ppapi::CompositorLayerData* new_layer,
223 scoped_ptr<base::SharedMemory> image_shm) { 222 std::unique_ptr<base::SharedMemory> image_shm) {
224 // Always update properties on cc::Layer, because cc::Layer 223 // Always update properties on cc::Layer, because cc::Layer
225 // will ignore any setting with unchanged value. 224 // will ignore any setting with unchanged value.
226 layer->SetIsDrawable(true); 225 layer->SetIsDrawable(true);
227 layer->SetBlendMode(SkXfermode::kSrcOver_Mode); 226 layer->SetBlendMode(SkXfermode::kSrcOver_Mode);
228 layer->SetOpacity(new_layer->common.opacity); 227 layer->SetOpacity(new_layer->common.opacity);
229 layer->SetBounds(PP_ToGfxSize(new_layer->common.size)); 228 layer->SetBounds(PP_ToGfxSize(new_layer->common.size));
230 layer->SetTransformOrigin(gfx::Point3F(new_layer->common.size.width / 2, 229 layer->SetTransformOrigin(gfx::Point3F(new_layer->common.size.width / 2,
231 new_layer->common.size.height / 2, 230 new_layer->common.size.height / 2,
232 0.0f)); 231 0.0f));
233 232
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 EnterResourceNoLock<PPB_ImageData_API> enter(new_layer->image->resource, 299 EnterResourceNoLock<PPB_ImageData_API> enter(new_layer->image->resource,
301 true); 300 true);
302 DCHECK(enter.succeeded()); 301 DCHECK(enter.succeeded());
303 302
304 // TODO(penghuang): support all kinds of image. 303 // TODO(penghuang): support all kinds of image.
305 PP_ImageDataDesc desc; 304 PP_ImageDataDesc desc;
306 PP_Bool rv = enter.object()->Describe(&desc); 305 PP_Bool rv = enter.object()->Describe(&desc);
307 DCHECK_EQ(rv, PP_TRUE); 306 DCHECK_EQ(rv, PP_TRUE);
308 DCHECK_EQ(desc.stride, desc.size.width * 4); 307 DCHECK_EQ(desc.stride, desc.size.width * 4);
309 DCHECK_EQ(desc.format, PP_IMAGEDATAFORMAT_RGBA_PREMUL); 308 DCHECK_EQ(desc.format, PP_IMAGEDATAFORMAT_RGBA_PREMUL);
310 scoped_ptr<cc::SharedBitmap> bitmap = 309 std::unique_ptr<cc::SharedBitmap> bitmap =
311 ChildThreadImpl::current() 310 ChildThreadImpl::current()
312 ->shared_bitmap_manager() 311 ->shared_bitmap_manager()
313 ->GetBitmapForSharedMemory(image_shm.get()); 312 ->GetBitmapForSharedMemory(image_shm.get());
314 313
315 cc::TextureMailbox mailbox(bitmap.get(), PP_ToGfxSize(desc.size)); 314 cc::TextureMailbox mailbox(bitmap.get(), PP_ToGfxSize(desc.size));
316 image_layer->SetTextureMailbox( 315 image_layer->SetTextureMailbox(
317 mailbox, 316 mailbox,
318 cc::SingleReleaseCallback::Create(base::Bind( 317 cc::SingleReleaseCallback::Create(base::Bind(
319 &PepperCompositorHost::ImageReleased, weak_factory_.GetWeakPtr(), 318 &PepperCompositorHost::ImageReleased, weak_factory_.GetWeakPtr(),
320 new_layer->common.resource_id, base::Passed(&image_shm), 319 new_layer->common.resource_id, base::Passed(&image_shm),
(...skipping 25 matching lines...) Expand all
346 return true; 345 return true;
347 } 346 }
348 347
349 int32_t PepperCompositorHost::OnHostMsgCommitLayers( 348 int32_t PepperCompositorHost::OnHostMsgCommitLayers(
350 HostMessageContext* context, 349 HostMessageContext* context,
351 const std::vector<ppapi::CompositorLayerData>& layers, 350 const std::vector<ppapi::CompositorLayerData>& layers,
352 bool reset) { 351 bool reset) {
353 if (commit_layers_reply_context_.is_valid()) 352 if (commit_layers_reply_context_.is_valid())
354 return PP_ERROR_INPROGRESS; 353 return PP_ERROR_INPROGRESS;
355 354
356 scoped_ptr<scoped_ptr<base::SharedMemory>[]> image_shms; 355 std::unique_ptr<std::unique_ptr<base::SharedMemory>[]> image_shms;
357 if (layers.size() > 0) { 356 if (layers.size() > 0) {
358 image_shms.reset(new scoped_ptr<base::SharedMemory>[layers.size()]); 357 image_shms.reset(new std::unique_ptr<base::SharedMemory>[layers.size()]);
359 if (!image_shms) 358 if (!image_shms)
360 return PP_ERROR_NOMEMORY; 359 return PP_ERROR_NOMEMORY;
361 // Verfiy the layers first, if an error happens, we will return the error to 360 // Verfiy the layers first, if an error happens, we will return the error to
362 // plugin and keep current layers set by the previous CommitLayers() 361 // plugin and keep current layers set by the previous CommitLayers()
363 // unchanged. 362 // unchanged.
364 for (size_t i = 0; i < layers.size(); ++i) { 363 for (size_t i = 0; i < layers.size(); ++i) {
365 const ppapi::CompositorLayerData* old_layer = NULL; 364 const ppapi::CompositorLayerData* old_layer = NULL;
366 if (!reset && i < layers_.size()) 365 if (!reset && i < layers_.size())
367 old_layer = &layers_[i].pp_layer; 366 old_layer = &layers_[i].pp_layer;
368 int32_t rv = VerifyCommittedLayer(old_layer, &layers[i], &image_shms[i]); 367 int32_t rv = VerifyCommittedLayer(old_layer, &layers[i], &image_shms[i]);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 407
409 // If the host is not bound to the instance, return PP_OK immediately. 408 // If the host is not bound to the instance, return PP_OK immediately.
410 if (!bound_instance_) 409 if (!bound_instance_)
411 return PP_OK; 410 return PP_OK;
412 411
413 commit_layers_reply_context_ = context->MakeReplyMessageContext(); 412 commit_layers_reply_context_ = context->MakeReplyMessageContext();
414 return PP_OK_COMPLETIONPENDING; 413 return PP_OK_COMPLETIONPENDING;
415 } 414 }
416 415
417 } // namespace content 416 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_compositor_host.h ('k') | content/renderer/pepper/pepper_device_enumeration_host_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698