12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/layers/contents_scaling_layer.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/size_conversions.h"
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc {
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size ContentsScalingLayer::ComputeContentBoundsForScale(
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    float scale_x,
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    float scale_y) const {
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale_x, scale_y));
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ContentsScalingLayer::ContentsScalingLayer()
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : last_update_contents_scale_x_(0.f),
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      last_update_contents_scale_y_(0.f) {}
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ContentsScalingLayer::~ContentsScalingLayer() {
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ContentsScalingLayer::CalculateContentsScale(
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    float ideal_contents_scale,
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    float* contents_scale_x,
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    float* contents_scale_y,
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Size* content_bounds) {
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  *contents_scale_x = ideal_contents_scale;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  *contents_scale_y = ideal_contents_scale;
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  *content_bounds = ComputeContentBoundsForScale(
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ideal_contents_scale,
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ideal_contents_scale);
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool ContentsScalingLayer::Update(ResourceUpdateQueue* queue,
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                  const OcclusionTracker<Layer>* occlusion) {
37a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  bool updated = Layer::Update(queue, occlusion);
38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (draw_properties().contents_scale_x == last_update_contents_scale_x_ &&
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      draw_properties().contents_scale_y == last_update_contents_scale_y_)
41a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return updated;
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  last_update_contents_scale_x_ = draw_properties().contents_scale_x;
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  last_update_contents_scale_y_ = draw_properties().contents_scale_y;
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invalidate the whole layer if scale changed.
46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SetNeedsDisplayRect(gfx::Rect(paint_properties().bounds));
47a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return updated;
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace cc
51