[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 | |||||
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 5 | #include "cc/image_layer.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 7 | #include "base/compiler_specific.h" |
[email protected] | 35680c0 | 2012-11-06 05:53:00 | [diff] [blame] | 8 | #include "cc/image_layer_updater.h" |
[email protected] | 64d8d39 | 2012-10-23 18:34:51 | [diff] [blame] | 9 | #include "cc/layer_updater.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 10 | #include "cc/layer_tree_host.h" |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 11 | #include "cc/resource_update_queue.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 12 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 13 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 14 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 15 | scoped_refptr<ImageLayer> ImageLayer::create() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 16 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 17 | return make_scoped_refptr(new ImageLayer()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 18 | } |
19 | |||||
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 20 | ImageLayer::ImageLayer() |
21 | : TiledLayer() | ||||
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 22 | { |
23 | } | ||||
24 | |||||
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 25 | ImageLayer::~ImageLayer() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 26 | { |
27 | } | ||||
28 | |||||
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 29 | void ImageLayer::setBitmap(const SkBitmap& bitmap) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 30 | { |
31 | // setBitmap() currently gets called whenever there is any | ||||
32 | // style change that affects the layer even if that change doesn't | ||||
33 | // affect the actual contents of the image (e.g. a CSS animation). | ||||
34 | // With this check in place we avoid unecessary texture uploads. | ||||
35 | if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef()) | ||||
36 | return; | ||||
37 | |||||
38 | m_bitmap = bitmap; | ||||
39 | setNeedsDisplay(); | ||||
40 | } | ||||
41 | |||||
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 42 | void ImageLayer::setTexturePriorities(const PriorityCalculator& priorityCalc) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 43 | { |
44 | // Update the tile data before creating all the layer's tiles. | ||||
45 | updateTileSizeAndTilingOption(); | ||||
46 | |||||
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 47 | TiledLayer::setTexturePriorities(priorityCalc); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | } |
49 | |||||
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 50 | void ImageLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker* occlusion, RenderingStats& stats) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 51 | { |
[email protected] | 64d8d39 | 2012-10-23 18:34:51 | [diff] [blame] | 52 | createUpdaterIfNeeded(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 53 | if (m_needsDisplay) { |
[email protected] | 64d8d39 | 2012-10-23 18:34:51 | [diff] [blame] | 54 | m_updater->setBitmap(m_bitmap); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 55 | updateTileSizeAndTilingOption(); |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 56 | invalidateContentRect(gfx::Rect(gfx::Point(), contentBounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 57 | m_needsDisplay = false; |
58 | } | ||||
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 59 | TiledLayer::update(queue, occlusion, stats); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 60 | } |
61 | |||||
[email protected] | 64d8d39 | 2012-10-23 18:34:51 | [diff] [blame] | 62 | void ImageLayer::createUpdaterIfNeeded() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 63 | { |
[email protected] | 64d8d39 | 2012-10-23 18:34:51 | [diff] [blame] | 64 | if (m_updater) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 65 | return; |
66 | |||||
[email protected] | 64d8d39 | 2012-10-23 18:34:51 | [diff] [blame] | 67 | m_updater = ImageLayerUpdater::create(); |
[email protected] | d9c2852 | 2012-10-18 23:35:43 | [diff] [blame] | 68 | GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 69 | setTextureFormat(textureFormat); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 70 | } |
71 | |||||
[email protected] | 64d8d39 | 2012-10-23 18:34:51 | [diff] [blame] | 72 | LayerUpdater* ImageLayer::updater() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 73 | { |
[email protected] | 64d8d39 | 2012-10-23 18:34:51 | [diff] [blame] | 74 | return m_updater.get(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 75 | } |
76 | |||||
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 77 | gfx::Size ImageLayer::contentBounds() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 78 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 79 | return gfx::Size(m_bitmap.width(), m_bitmap.height()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 80 | } |
81 | |||||
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 82 | bool ImageLayer::drawsContent() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 83 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 84 | return !m_bitmap.isNull() && TiledLayer::drawsContent(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 85 | } |
86 | |||||
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 87 | float ImageLayer::contentsScaleX() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 88 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 89 | if (bounds().IsEmpty() || contentBounds().IsEmpty()) |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 90 | return 1; |
91 | return static_cast<float>(m_bitmap.width()) / bounds().width(); | ||||
92 | } | ||||
93 | |||||
94 | float ImageLayer::contentsScaleY() const | ||||
95 | { | ||||
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 96 | if (bounds().IsEmpty() || contentBounds().IsEmpty()) |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 97 | return 1; |
98 | return static_cast<float>(m_bitmap.height()) / bounds().height(); | ||||
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 99 | } |
100 | |||||
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 101 | } // namespace cc |