Add test for clicking bookmark star in presence of ctrl-D keybinding
[chromium-blink-merge.git] / cc / layers / image_layer.cc
blob67e620c6e2ed7cf44f3029e44e87e9df9e73488f
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 UpdateDrawsContent(HasDrawableContent());
34 SetNeedsDisplay();
37 bool ImageLayer::HasDrawableContent() const {
38 return !bitmap_.isNull() && TiledLayer::HasDrawableContent();
41 void ImageLayer::SetTexturePriorities(const PriorityCalculator& priority_calc) {
42 // Update the tile data before creating all the layer's tiles.
43 UpdateTileSizeAndTilingOption();
45 TiledLayer::SetTexturePriorities(priority_calc);
48 bool ImageLayer::Update(ResourceUpdateQueue* queue,
49 const OcclusionTracker<Layer>* occlusion) {
50 CreateUpdaterIfNeeded();
51 if (!updater_->UsingBitmap(bitmap_)) {
52 updater_->SetBitmap(bitmap_);
53 UpdateTileSizeAndTilingOption();
54 InvalidateContentRect(gfx::Rect(content_bounds()));
56 return TiledLayer::Update(queue, occlusion);
59 void ImageLayer::CreateUpdaterIfNeeded() {
60 if (updater_.get())
61 return;
63 updater_ = ImageLayerUpdater::Create();
64 SetTextureFormat(
65 layer_tree_host()->GetRendererCapabilities().best_texture_format);
68 LayerUpdater* ImageLayer::Updater() const {
69 return updater_.get();
72 void ImageLayer::CalculateContentsScale(float ideal_contents_scale,
73 float* contents_scale_x,
74 float* contents_scale_y,
75 gfx::Size* content_bounds) {
76 *contents_scale_x = ImageContentsScaleX();
77 *contents_scale_y = ImageContentsScaleY();
78 *content_bounds = gfx::Size(bitmap_.width(), bitmap_.height());
81 void ImageLayer::OnOutputSurfaceCreated() {
82 SetTextureFormat(
83 layer_tree_host()->GetRendererCapabilities().best_texture_format);
84 TiledLayer::OnOutputSurfaceCreated();
87 float ImageLayer::ImageContentsScaleX() const {
88 if (bounds().IsEmpty() || bitmap_.width() == 0)
89 return 1;
90 return static_cast<float>(bitmap_.width()) / bounds().width();
93 float ImageLayer::ImageContentsScaleY() const {
94 if (bounds().IsEmpty() || bitmap_.height() == 0)
95 return 1;
96 return static_cast<float>(bitmap_.height()) / bounds().height();
99 } // namespace cc