Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: cc/image_layer.cc

Issue 12603013: Part 10 of cc/ directory shuffles: layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/image_layer.h ('k') | cc/input/top_controls_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "cc/image_layer.h"
6
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"
13
14 namespace cc {
15
16 scoped_refptr<ImageLayer> ImageLayer::Create() {
17 return make_scoped_refptr(new ImageLayer());
18 }
19
20 ImageLayer::ImageLayer() : TiledLayer() {}
21
22 ImageLayer::~ImageLayer() {}
23
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;
31
32 bitmap_ = bitmap;
33 SetNeedsDisplay();
34 }
35
36 void ImageLayer::SetTexturePriorities(const PriorityCalculator& priority_calc) {
37 // Update the tile data before creating all the layer's tiles.
38 UpdateTileSizeAndTilingOption();
39
40 TiledLayer::SetTexturePriorities(priority_calc);
41 }
42
43 void ImageLayer::Update(ResourceUpdateQueue* queue,
44 const OcclusionTracker* occlusion,
45 RenderingStats* stats) {
46 CreateUpdaterIfNeeded();
47 if (needs_display_) {
48 updater_->set_bitmap(bitmap_);
49 UpdateTileSizeAndTilingOption();
50 InvalidateContentRect(gfx::Rect(content_bounds()));
51 needs_display_ = false;
52 }
53 TiledLayer::Update(queue, occlusion, stats);
54 }
55
56 void ImageLayer::CreateUpdaterIfNeeded() {
57 if (updater_)
58 return;
59
60 updater_ = ImageLayerUpdater::Create();
61 GLenum texture_format =
62 layer_tree_host()->GetRendererCapabilities().best_texture_format;
63 SetTextureFormat(texture_format);
64 }
65
66 LayerUpdater* ImageLayer::Updater() const {
67 return updater_.get();
68 }
69
70 void ImageLayer::CalculateContentsScale(float ideal_contents_scale,
71 bool animating_transform_to_screen,
72 float* contents_scale_x,
73 float* contents_scale_y,
74 gfx::Size* content_bounds) {
75 *contents_scale_x = ImageContentsScaleX();
76 *contents_scale_y = ImageContentsScaleY();
77 *content_bounds = gfx::Size(bitmap_.width(), bitmap_.height());
78 }
79
80 bool ImageLayer::DrawsContent() const {
81 return !bitmap_.isNull() && TiledLayer::DrawsContent();
82 }
83
84 float ImageLayer::ImageContentsScaleX() const {
85 if (bounds().IsEmpty() || bitmap_.width() == 0)
86 return 1;
87 return static_cast<float>(bitmap_.width()) / bounds().width();
88 }
89
90 float ImageLayer::ImageContentsScaleY() const {
91 if (bounds().IsEmpty() || bitmap_.height() == 0)
92 return 1;
93 return static_cast<float>(bitmap_.height()) / bounds().height();
94 }
95
96 } // namespace cc
OLDNEW
« no previous file with comments | « cc/image_layer.h ('k') | cc/input/top_controls_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698