| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/image_layer.h" | 5 #include "cc/image_layer.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "cc/image_layer_updater.h" | 8 #include "cc/image_layer_updater.h" |
| 9 #include "cc/layer_updater.h" | 9 #include "cc/layer_updater.h" |
| 10 #include "cc/layer_tree_host.h" | 10 #include "cc/layer_tree_host.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 void ImageLayer::SetBitmap(const SkBitmap& bitmap) { | 24 void ImageLayer::SetBitmap(const SkBitmap& bitmap) { |
| 25 // SetBitmap() currently gets called whenever there is any | 25 // SetBitmap() currently gets called whenever there is any |
| 26 // style change that affects the layer even if that change doesn't | 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). | 27 // affect the actual contents of the image (e.g. a CSS animation). |
| 28 // With this check in place we avoid unecessary texture uploads. | 28 // With this check in place we avoid unecessary texture uploads. |
| 29 if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef()) | 29 if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef()) |
| 30 return; | 30 return; |
| 31 | 31 |
| 32 bitmap_ = bitmap; | 32 bitmap_ = bitmap; |
| 33 setNeedsDisplay(); | 33 SetNeedsDisplay(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void ImageLayer::setTexturePriorities(const PriorityCalculator& priority_calc) { | 36 void ImageLayer::SetTexturePriorities(const PriorityCalculator& priority_calc) { |
| 37 // Update the tile data before creating all the layer's tiles. | 37 // Update the tile data before creating all the layer's tiles. |
| 38 updateTileSizeAndTilingOption(); | 38 updateTileSizeAndTilingOption(); |
| 39 | 39 |
| 40 TiledLayer::setTexturePriorities(priority_calc); | 40 TiledLayer::SetTexturePriorities(priority_calc); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ImageLayer::update(ResourceUpdateQueue& queue, | 43 void ImageLayer::Update(ResourceUpdateQueue* queue, |
| 44 const OcclusionTracker* occlusion, | 44 const OcclusionTracker* occlusion, |
| 45 RenderingStats* stats) { | 45 RenderingStats* stats) { |
| 46 createUpdaterIfNeeded(); | 46 createUpdaterIfNeeded(); |
| 47 if (m_needsDisplay) { | 47 if (needs_display_) { |
| 48 updater_->setBitmap(bitmap_); | 48 updater_->setBitmap(bitmap_); |
| 49 updateTileSizeAndTilingOption(); | 49 updateTileSizeAndTilingOption(); |
| 50 invalidateContentRect(gfx::Rect(gfx::Point(), contentBounds())); | 50 invalidateContentRect(gfx::Rect(content_bounds())); |
| 51 m_needsDisplay = false; | 51 needs_display_ = false; |
| 52 } | 52 } |
| 53 TiledLayer::update(queue, occlusion, stats); | 53 TiledLayer::Update(queue, occlusion, stats); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ImageLayer::createUpdaterIfNeeded() { | 56 void ImageLayer::createUpdaterIfNeeded() { |
| 57 if (updater_) | 57 if (updater_) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 updater_ = ImageLayerUpdater::create(); | 60 updater_ = ImageLayerUpdater::create(); |
| 61 GLenum texture_format = | 61 GLenum texture_format = |
| 62 layerTreeHost()->rendererCapabilities().bestTextureFormat; | 62 layer_tree_host()->rendererCapabilities().bestTextureFormat; |
| 63 setTextureFormat(texture_format); | 63 setTextureFormat(texture_format); |
| 64 } | 64 } |
| 65 | 65 |
| 66 LayerUpdater* ImageLayer::updater() const { | 66 LayerUpdater* ImageLayer::updater() const { |
| 67 return updater_.get(); | 67 return updater_.get(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ImageLayer::calculateContentsScale(float ideal_contents_scale, | 70 void ImageLayer::CalculateContentsScale(float ideal_contents_scale, |
| 71 bool animating_transform_to_screen, | 71 bool animating_transform_to_screen, |
| 72 float* contents_scale_x, | 72 float* contents_scale_x, |
| 73 float* contents_scale_y, | 73 float* contents_scale_y, |
| 74 gfx::Size* contentBounds) { | 74 gfx::Size* contentBounds) { |
| 75 *contents_scale_x = ImageContentsScaleX(); | 75 *contents_scale_x = ImageContentsScaleX(); |
| 76 *contents_scale_y = ImageContentsScaleY(); | 76 *contents_scale_y = ImageContentsScaleY(); |
| 77 *contentBounds = gfx::Size(bitmap_.width(), bitmap_.height()); | 77 *contentBounds = gfx::Size(bitmap_.width(), bitmap_.height()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool ImageLayer::drawsContent() const { | 80 bool ImageLayer::DrawsContent() const { |
| 81 return !bitmap_.isNull() && TiledLayer::drawsContent(); | 81 return !bitmap_.isNull() && TiledLayer::DrawsContent(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 float ImageLayer::ImageContentsScaleX() const { | 84 float ImageLayer::ImageContentsScaleX() const { |
| 85 if (bounds().IsEmpty() || bitmap_.width() == 0) | 85 if (bounds().IsEmpty() || bitmap_.width() == 0) |
| 86 return 1; | 86 return 1; |
| 87 return static_cast<float>(bitmap_.width()) / bounds().width(); | 87 return static_cast<float>(bitmap_.width()) / bounds().width(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 float ImageLayer::ImageContentsScaleY() const { | 90 float ImageLayer::ImageContentsScaleY() const { |
| 91 if (bounds().IsEmpty() || bitmap_.height() == 0) | 91 if (bounds().IsEmpty() || bitmap_.height() == 0) |
| 92 return 1; | 92 return 1; |
| 93 return static_cast<float>(bitmap_.height()) / bounds().height(); | 93 return static_cast<float>(bitmap_.height()) / bounds().height(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace cc | 96 } // namespace cc |
| OLD | NEW |