GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / cc / layers / contents_scaling_layer.cc
blob733bac094f696552d470472ee07b9ee1b47c642e
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 "ui/gfx/geometry/size_conversions.h"
8 namespace cc {
10 gfx::Size ContentsScalingLayer::ComputeContentBoundsForScale(
11 float scale_x,
12 float scale_y) const {
13 return gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale_x, scale_y));
16 ContentsScalingLayer::ContentsScalingLayer()
17 : last_update_contents_scale_x_(0.f),
18 last_update_contents_scale_y_(0.f) {}
20 ContentsScalingLayer::~ContentsScalingLayer() {
23 void ContentsScalingLayer::CalculateContentsScale(
24 float ideal_contents_scale,
25 float* contents_scale_x,
26 float* contents_scale_y,
27 gfx::Size* content_bounds) {
28 *contents_scale_x = ideal_contents_scale;
29 *contents_scale_y = ideal_contents_scale;
30 *content_bounds = ComputeContentBoundsForScale(
31 ideal_contents_scale,
32 ideal_contents_scale);
35 bool ContentsScalingLayer::Update(ResourceUpdateQueue* queue,
36 const OcclusionTracker<Layer>* occlusion) {
37 bool updated = Layer::Update(queue, occlusion);
39 if (draw_properties().contents_scale_x == last_update_contents_scale_x_ &&
40 draw_properties().contents_scale_y == last_update_contents_scale_y_)
41 return updated;
43 last_update_contents_scale_x_ = draw_properties().contents_scale_x;
44 last_update_contents_scale_y_ = draw_properties().contents_scale_y;
45 // Invalidate the whole layer if scale changed.
46 SetNeedsDisplayRect(gfx::Rect(paint_properties().bounds));
47 return updated;
50 } // namespace cc