[safe browsing] Push missing download BINHASH histograms.
[chromium-blink-merge.git] / cc / layers / image_layer.cc
blob2f90bfc50a8f2725378a541436a16cc8085c0402
1 // Copyright 2010 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/image_layer.h"
7 #include "base/compiler_specific.h"
8 #include "cc/resources/image_layer_updater.h"
9 #include "cc/resources/layer_updater.h"
10 #include "cc/resources/prioritized_resource.h"
11 #include "cc/resources/resource_update_queue.h"
12 #include "cc/trees/layer_tree_host.h"
14 namespace cc {
16 scoped_refptr<ImageLayer> ImageLayer::Create() {
17 return make_scoped_refptr(new ImageLayer());
20 ImageLayer::ImageLayer() : TiledLayer() {}
22 ImageLayer::~ImageLayer() {}
24 void ImageLayer::SetBitmap(const SkBitmap& bitmap) {
25 // SetBitmap() currently gets called whenever there is any
26 // style change that affects the layer even if that change doesn't
27 // affect the actual contents of the image (e.g. a CSS animation).
28 // With this check in place we avoid unecessary texture uploads.
29 if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef())
30 return;
32 bitmap_ = bitmap;
33 SetNeedsDisplay();
36 void ImageLayer::SetTexturePriorities(const PriorityCalculator& priority_calc) {
37 // Update the tile data before creating all the layer's tiles.
38 UpdateTileSizeAndTilingOption();
40 TiledLayer::SetTexturePriorities(priority_calc);
43 bool ImageLayer::Update(ResourceUpdateQueue* queue,
44 const OcclusionTracker* occlusion) {
45 CreateUpdaterIfNeeded();
46 if (!updater_->UsingBitmap(bitmap_)) {
47 updater_->SetBitmap(bitmap_);
48 UpdateTileSizeAndTilingOption();
49 InvalidateContentRect(gfx::Rect(content_bounds()));
51 return TiledLayer::Update(queue, occlusion);
54 void ImageLayer::CreateUpdaterIfNeeded() {
55 if (updater_.get())
56 return;
58 updater_ = ImageLayerUpdater::Create();
59 SetTextureFormat(
60 layer_tree_host()->GetRendererCapabilities().best_texture_format);
63 LayerUpdater* ImageLayer::Updater() const {
64 return updater_.get();
67 void ImageLayer::CalculateContentsScale(float ideal_contents_scale,
68 float device_scale_factor,
69 float page_scale_factor,
70 bool animating_transform_to_screen,
71 float* contents_scale_x,
72 float* contents_scale_y,
73 gfx::Size* content_bounds) {
74 *contents_scale_x = ImageContentsScaleX();
75 *contents_scale_y = ImageContentsScaleY();
76 *content_bounds = gfx::Size(bitmap_.width(), bitmap_.height());
79 bool ImageLayer::DrawsContent() const {
80 return !bitmap_.isNull() && TiledLayer::DrawsContent();
83 void ImageLayer::OnOutputSurfaceCreated() {
84 SetTextureFormat(
85 layer_tree_host()->GetRendererCapabilities().best_texture_format);
86 TiledLayer::OnOutputSurfaceCreated();
89 float ImageLayer::ImageContentsScaleX() const {
90 if (bounds().IsEmpty() || bitmap_.width() == 0)
91 return 1;
92 return static_cast<float>(bitmap_.width()) / bounds().width();
95 float ImageLayer::ImageContentsScaleY() const {
96 if (bounds().IsEmpty() || bitmap_.height() == 0)
97 return 1;
98 return static_cast<float>(bitmap_.height()) / bounds().height();
101 } // namespace cc