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

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

Issue 1964423003: Apply viewport to dip scale to Graphics2D, Compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 7 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 12 matching lines...) Expand all
23 #include "content/renderer/pepper/host_globals.h" 23 #include "content/renderer/pepper/host_globals.h"
24 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 24 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
25 #include "content/renderer/pepper/ppb_image_data_impl.h" 25 #include "content/renderer/pepper/ppb_image_data_impl.h"
26 #include "ppapi/c/pp_errors.h" 26 #include "ppapi/c/pp_errors.h"
27 #include "ppapi/host/dispatch_host_message.h" 27 #include "ppapi/host/dispatch_host_message.h"
28 #include "ppapi/host/ppapi_host.h" 28 #include "ppapi/host/ppapi_host.h"
29 #include "ppapi/proxy/ppapi_messages.h" 29 #include "ppapi/proxy/ppapi_messages.h"
30 #include "ppapi/thunk/enter.h" 30 #include "ppapi/thunk/enter.h"
31 #include "ppapi/thunk/ppb_image_data_api.h" 31 #include "ppapi/thunk/ppb_image_data_api.h"
32 #include "third_party/khronos/GLES2/gl2.h" 32 #include "third_party/khronos/GLES2/gl2.h"
33 #include "ui/gfx/geometry/size_conversions.h"
33 #include "ui/gfx/transform.h" 34 #include "ui/gfx/transform.h"
34 35
35 using ppapi::host::HostMessageContext; 36 using ppapi::host::HostMessageContext;
36 using ppapi::thunk::EnterResourceNoLock; 37 using ppapi::thunk::EnterResourceNoLock;
37 using ppapi::thunk::PPB_ImageData_API; 38 using ppapi::thunk::PPB_ImageData_API;
38 39
39 namespace content { 40 namespace content {
40 41
41 namespace { 42 namespace {
42 43
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext(); 216 commit_layers_reply_context_ = ppapi::host::ReplyMessageContext();
216 } 217 }
217 218
218 void PepperCompositorHost::UpdateLayer( 219 void PepperCompositorHost::UpdateLayer(
219 const scoped_refptr<cc::Layer>& layer, 220 const scoped_refptr<cc::Layer>& layer,
220 const ppapi::CompositorLayerData* old_layer, 221 const ppapi::CompositorLayerData* old_layer,
221 const ppapi::CompositorLayerData* new_layer, 222 const ppapi::CompositorLayerData* new_layer,
222 std::unique_ptr<base::SharedMemory> image_shm) { 223 std::unique_ptr<base::SharedMemory> image_shm) {
223 // Always update properties on cc::Layer, because cc::Layer 224 // Always update properties on cc::Layer, because cc::Layer
224 // will ignore any setting with unchanged value. 225 // will ignore any setting with unchanged value.
226 gfx::SizeF size(PP_ToGfxSize(new_layer->common.size));
227 gfx::RectF clip_rect(PP_ToGfxRect(new_layer->common.clip_rect));
228
229 // Pepper API uses DIP, so we must scale the layer's coordinates to
230 // viewport in use-zoom-for-dsf.
231 float dip_to_viewport_scale = 1 / viewport_to_dip_scale_;
232 size.Scale(dip_to_viewport_scale);
233 clip_rect.Scale(dip_to_viewport_scale);
234
225 layer->SetIsDrawable(true); 235 layer->SetIsDrawable(true);
226 layer->SetBlendMode(SkXfermode::kSrcOver_Mode); 236 layer->SetBlendMode(SkXfermode::kSrcOver_Mode);
227 layer->SetOpacity(new_layer->common.opacity); 237 layer->SetOpacity(new_layer->common.opacity);
228 layer->SetBounds(PP_ToGfxSize(new_layer->common.size));
229 layer->SetTransformOrigin(gfx::Point3F(new_layer->common.size.width / 2,
230 new_layer->common.size.height / 2,
231 0.0f));
232 238
239 layer->SetBounds(gfx::ToRoundedSize(size));
240 layer->SetTransformOrigin(
241 gfx::Point3F(size.width() / 2, size.height() / 2, 0.0f));
233 gfx::Transform transform(gfx::Transform::kSkipInitialization); 242 gfx::Transform transform(gfx::Transform::kSkipInitialization);
234 transform.matrix().setColMajorf(new_layer->common.transform.matrix); 243 transform.matrix().setColMajorf(new_layer->common.transform.matrix);
235 layer->SetTransform(transform); 244 layer->SetTransform(transform);
236 245
237 // Consider a (0,0,0,0) rect as no clip rect. 246 // Consider a (0,0,0,0) rect as no clip rect.
238 if (new_layer->common.clip_rect.point.x != 0 || 247 if (new_layer->common.clip_rect.point.x != 0 ||
239 new_layer->common.clip_rect.point.y != 0 || 248 new_layer->common.clip_rect.point.y != 0 ||
240 new_layer->common.clip_rect.size.width != 0 || 249 new_layer->common.clip_rect.size.width != 0 ||
241 new_layer->common.clip_rect.size.height != 0) { 250 new_layer->common.clip_rect.size.height != 0) {
242 scoped_refptr<cc::Layer> clip_parent = layer->parent(); 251 scoped_refptr<cc::Layer> clip_parent = layer->parent();
243 if (clip_parent.get() == layer_.get()) { 252 if (clip_parent.get() == layer_.get()) {
244 // Create a clip parent layer, if it does not exist. 253 // Create a clip parent layer, if it does not exist.
245 clip_parent = cc::Layer::Create(); 254 clip_parent = cc::Layer::Create();
246 clip_parent->SetMasksToBounds(true); 255 clip_parent->SetMasksToBounds(true);
247 clip_parent->SetIsDrawable(true); 256 clip_parent->SetIsDrawable(true);
248 layer_->ReplaceChild(layer.get(), clip_parent); 257 layer_->ReplaceChild(layer.get(), clip_parent);
249 clip_parent->AddChild(layer); 258 clip_parent->AddChild(layer);
250 } 259 }
251 auto position = 260 auto position = clip_rect.origin();
252 gfx::PointF(PP_ToGfxPoint(new_layer->common.clip_rect.point));
253 clip_parent->SetPosition(position); 261 clip_parent->SetPosition(position);
254 clip_parent->SetBounds(PP_ToGfxSize(new_layer->common.clip_rect.size)); 262 clip_parent->SetBounds(gfx::ToRoundedSize(clip_rect.size()));
255 layer->SetPosition(gfx::PointF(-position.x(), -position.y())); 263 layer->SetPosition(gfx::PointF(-position.x(), -position.y()));
256 } else if (layer->parent() != layer_.get()) { 264 } else if (layer->parent() != layer_.get()) {
257 // Remove the clip parent layer. 265 // Remove the clip parent layer.
258 layer_->ReplaceChild(layer->parent(), layer); 266 layer_->ReplaceChild(layer->parent(), layer);
259 layer->SetPosition(gfx::PointF()); 267 layer->SetPosition(gfx::PointF());
260 } 268 }
261 269
262 if (new_layer->color) { 270 if (new_layer->color) {
263 layer->SetBackgroundColor(SkColorSetARGBMacro( 271 layer->SetBackgroundColor(SkColorSetARGBMacro(
264 new_layer->color->alpha * 255, 272 new_layer->color->alpha * 255,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 415
408 // If the host is not bound to the instance, return PP_OK immediately. 416 // If the host is not bound to the instance, return PP_OK immediately.
409 if (!bound_instance_) 417 if (!bound_instance_)
410 return PP_OK; 418 return PP_OK;
411 419
412 commit_layers_reply_context_ = context->MakeReplyMessageContext(); 420 commit_layers_reply_context_ = context->MakeReplyMessageContext();
413 return PP_OK_COMPLETIONPENDING; 421 return PP_OK_COMPLETIONPENDING;
414 } 422 }
415 423
416 } // namespace content 424 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_compositor_host.h ('k') | content/renderer/pepper/pepper_graphics_2d_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698