12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 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/picture_image_layer_impl.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include <algorithm> 8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/debug/debug_colors.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/trees/layer_tree_impl.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc { 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PictureImageLayerImpl::PictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : PictureLayerImpl(tree_impl, id) { 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PictureImageLayerImpl::~PictureImageLayerImpl() { 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char* PictureImageLayerImpl::LayerTypeAsString() const { 22a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) return "cc::PictureImageLayerImpl"; 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_ptr<LayerImpl> PictureImageLayerImpl::CreateLayerImpl( 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LayerTreeImpl* tree_impl) { 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return PictureImageLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 30c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.orgvoid PictureImageLayerImpl::CalculateContentsScale( 31c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org float ideal_contents_scale, 32c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org float device_scale_factor, 33c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org float page_scale_factor, 34c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org bool animating_transform_to_screen, 35c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org float* contents_scale_x, 36c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org float* contents_scale_y, 37c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org gfx::Size* content_bounds) { 38c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org // CalculateRasterContentsScale always returns 1.f, so make that the ideal 39c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org // scale. 40c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org ideal_contents_scale = 1.f; 41c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org PictureLayerImpl::CalculateContentsScale(ideal_contents_scale, 42c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org device_scale_factor, 43c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org page_scale_factor, 44c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org animating_transform_to_screen, 45c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org contents_scale_x, 46c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org contents_scale_y, 47c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org content_bounds); 48c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org} 49c0a2024fa1318649ee7d91c4e630f1e529444550boliu@chromium.org 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void PictureImageLayerImpl::GetDebugBorderProperties( 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SkColor* color, float* width) const { 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *color = DebugColors::ImageLayerBorderColor(); 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *width = DebugColors::ImageLayerBorderWidth(layer_tree_impl()); 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 56c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool PictureImageLayerImpl::ShouldAdjustRasterScale( 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool animating_transform_to_screen) const { 58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return false; 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void PictureImageLayerImpl::CalculateRasterContentsScale( 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool animating_transform_to_screen, 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float* raster_contents_scale, 64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) float* low_res_raster_contents_scale) const { 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Don't scale images during rastering to ensure image quality, save memory 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and avoid frequent re-rastering on change of scale. 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *raster_contents_scale = std::max(1.f, MinimumContentsScale()); 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // We don't need low res tiles. 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *low_res_raster_contents_scale = *raster_contents_scale; 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace cc 73