| 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 18 matching lines...) Expand all Loading... |
| 29 void ImageLayer::setBitmap(const SkBitmap& bitmap) | 29 void ImageLayer::setBitmap(const SkBitmap& bitmap) |
| 30 { | 30 { |
| 31 // setBitmap() currently gets called whenever there is any | 31 // setBitmap() currently gets called whenever there is any |
| 32 // style change that affects the layer even if that change doesn't | 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). | 33 // affect the actual contents of the image (e.g. a CSS animation). |
| 34 // With this check in place we avoid unecessary texture uploads. | 34 // With this check in place we avoid unecessary texture uploads. |
| 35 if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef()) | 35 if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef()) |
| 36 return; | 36 return; |
| 37 | 37 |
| 38 m_bitmap = bitmap; | 38 m_bitmap = bitmap; |
| 39 didUpdateBounds(); |
| 39 setNeedsDisplay(); | 40 setNeedsDisplay(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void ImageLayer::setTexturePriorities(const PriorityCalculator& priorityCalc) | 43 void ImageLayer::setTexturePriorities(const PriorityCalculator& priorityCalc) |
| 43 { | 44 { |
| 44 // Update the tile data before creating all the layer's tiles. | 45 // Update the tile data before creating all the layer's tiles. |
| 45 updateTileSizeAndTilingOption(); | 46 updateTileSizeAndTilingOption(); |
| 46 | 47 |
| 47 TiledLayer::setTexturePriorities(priorityCalc); | 48 TiledLayer::setTexturePriorities(priorityCalc); |
| 48 } | 49 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 m_updater = ImageLayerUpdater::create(); | 68 m_updater = ImageLayerUpdater::create(); |
| 68 GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFo
rmat; | 69 GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFo
rmat; |
| 69 setTextureFormat(textureFormat); | 70 setTextureFormat(textureFormat); |
| 70 } | 71 } |
| 71 | 72 |
| 72 LayerUpdater* ImageLayer::updater() const | 73 LayerUpdater* ImageLayer::updater() const |
| 73 { | 74 { |
| 74 return m_updater.get(); | 75 return m_updater.get(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 gfx::Size ImageLayer::contentBounds() const | 78 void ImageLayer::setIdealContentsScale(float ideal_contents_scale) |
| 78 { | 79 { |
| 79 return gfx::Size(m_bitmap.width(), m_bitmap.height()); | 80 m_drawProperties.ideal_contents_scale = ideal_contents_scale; |
| 81 m_drawProperties.contents_scale_x = contentsScaleX(); |
| 82 m_drawProperties.contents_scale_y = contentsScaleY(); |
| 83 m_drawProperties.content_bounds = gfx::Size(m_bitmap.width(), m_bitmap.heigh
t()); |
| 80 } | 84 } |
| 81 | 85 |
| 82 bool ImageLayer::drawsContent() const | 86 bool ImageLayer::drawsContent() const |
| 83 { | 87 { |
| 84 return !m_bitmap.isNull() && TiledLayer::drawsContent(); | 88 return !m_bitmap.isNull() && TiledLayer::drawsContent(); |
| 85 } | 89 } |
| 86 | 90 |
| 87 float ImageLayer::contentsScaleX() const | 91 float ImageLayer::contentsScaleX() const |
| 88 { | 92 { |
| 89 if (bounds().IsEmpty() || contentBounds().IsEmpty()) | 93 if (bounds().IsEmpty() || m_bitmap.width() == 0) |
| 90 return 1; | 94 return 1; |
| 91 return static_cast<float>(m_bitmap.width()) / bounds().width(); | 95 return static_cast<float>(m_bitmap.width()) / bounds().width(); |
| 92 } | 96 } |
| 93 | 97 |
| 94 float ImageLayer::contentsScaleY() const | 98 float ImageLayer::contentsScaleY() const |
| 95 { | 99 { |
| 96 if (bounds().IsEmpty() || contentBounds().IsEmpty()) | 100 if (bounds().IsEmpty() || m_bitmap.height() == 0) |
| 97 return 1; | 101 return 1; |
| 98 return static_cast<float>(m_bitmap.height()) / bounds().height(); | 102 return static_cast<float>(m_bitmap.height()) / bounds().height(); |
| 99 } | 103 } |
| 100 | 104 |
| 101 } // namespace cc | 105 } // namespace cc |
| OLD | NEW |