1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/contents_scaling_layer.h"
6 #include "cc/trees/layer_tree_host.h"
7 #include "ui/gfx/geometry/size_conversions.h"
11 gfx::Size
ContentsScalingLayer::ComputeContentBoundsForScale(
13 float scale_y
) const {
14 return gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale_x
, scale_y
));
17 ContentsScalingLayer::ContentsScalingLayer()
18 : last_update_contents_scale_x_(0.f
),
19 last_update_contents_scale_y_(0.f
) {}
21 ContentsScalingLayer::~ContentsScalingLayer() {
24 void ContentsScalingLayer::CalculateContentsScale(
25 float ideal_contents_scale
,
26 float* contents_scale_x
,
27 float* contents_scale_y
,
28 gfx::Size
* content_bounds
) {
29 float old_contents_scale_x
= *contents_scale_x
;
30 float old_contents_scale_y
= *contents_scale_y
;
31 gfx::Size old_content_bounds
= *content_bounds
;
32 *contents_scale_x
= ideal_contents_scale
;
33 *contents_scale_y
= ideal_contents_scale
;
34 *content_bounds
= ComputeContentBoundsForScale(
36 ideal_contents_scale
);
38 if (!layer_tree_host())
41 if (old_contents_scale_x
!= *contents_scale_x
||
42 old_contents_scale_y
!= *contents_scale_y
||
43 old_content_bounds
!= *content_bounds
) {
44 layer_tree_host()->property_trees()->needs_rebuild
= true;
48 bool ContentsScalingLayer::Update(ResourceUpdateQueue
* queue
,
49 const OcclusionTracker
<Layer
>* occlusion
) {
50 bool updated
= Layer::Update(queue
, occlusion
);
52 if (draw_properties().contents_scale_x
== last_update_contents_scale_x_
&&
53 draw_properties().contents_scale_y
== last_update_contents_scale_y_
)
56 last_update_contents_scale_x_
= draw_properties().contents_scale_x
;
57 last_update_contents_scale_y_
= draw_properties().contents_scale_y
;
58 // Invalidate the whole layer if scale changed.
59 SetNeedsDisplayRect(gfx::Rect(paint_properties().bounds
));