| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/image_layer.h" | 7 #include "cc/image_layer.h" |
| 8 | 8 |
| 9 #include "CCLayerTreeHost.h" | 9 #include "CCLayerTreeHost.h" |
| 10 #include "CCTextureUpdateQueue.h" | 10 #include "CCTextureUpdateQueue.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "cc/layer_texture_updater.h" | 12 #include "cc/layer_texture_updater.h" |
| 13 #include "cc/platform_color.h" | 13 #include "cc/platform_color.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 class ImageLayerTextureUpdater : public LayerTextureUpdater { | 17 class ImageLayerTextureUpdater : public LayerTextureUpdater { |
| 18 public: | 18 public: |
| 19 class Texture : public LayerTextureUpdater::Texture { | 19 class Texture : public LayerTextureUpdater::Texture { |
| 20 public: | 20 public: |
| 21 Texture(ImageLayerTextureUpdater* textureUpdater, scoped_ptr<CCPrioritiz
edTexture> texture) | 21 Texture(ImageLayerTextureUpdater* textureUpdater, scoped_ptr<Prioritized
Texture> texture) |
| 22 : LayerTextureUpdater::Texture(texture.Pass()) | 22 : LayerTextureUpdater::Texture(texture.Pass()) |
| 23 , m_textureUpdater(textureUpdater) | 23 , m_textureUpdater(textureUpdater) |
| 24 { | 24 { |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual void update(CCTextureUpdateQueue& queue, const IntRect& sourceRe
ct, const IntSize& destOffset, bool partialUpdate, CCRenderingStats&) OVERRIDE | 27 virtual void update(TextureUpdateQueue& queue, const IntRect& sourceRect
, const IntSize& destOffset, bool partialUpdate, RenderingStats&) OVERRIDE |
| 28 { | 28 { |
| 29 textureUpdater()->updateTexture(queue, texture(), sourceRect, destOf
fset, partialUpdate); | 29 textureUpdater()->updateTexture(queue, texture(), sourceRect, destOf
fset, partialUpdate); |
| 30 } | 30 } |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 ImageLayerTextureUpdater* textureUpdater() { return m_textureUpdater; } | 33 ImageLayerTextureUpdater* textureUpdater() { return m_textureUpdater; } |
| 34 | 34 |
| 35 ImageLayerTextureUpdater* m_textureUpdater; | 35 ImageLayerTextureUpdater* m_textureUpdater; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 static scoped_refptr<ImageLayerTextureUpdater> create() | 38 static scoped_refptr<ImageLayerTextureUpdater> create() |
| 39 { | 39 { |
| 40 return make_scoped_refptr(new ImageLayerTextureUpdater()); | 40 return make_scoped_refptr(new ImageLayerTextureUpdater()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual scoped_ptr<LayerTextureUpdater::Texture> createTexture( | 43 virtual scoped_ptr<LayerTextureUpdater::Texture> createTexture( |
| 44 CCPrioritizedTextureManager* manager) OVERRIDE | 44 PrioritizedTextureManager* manager) OVERRIDE |
| 45 { | 45 { |
| 46 return scoped_ptr<LayerTextureUpdater::Texture>(new Texture(this, CCPrio
ritizedTexture::create(manager))); | 46 return scoped_ptr<LayerTextureUpdater::Texture>(new Texture(this, Priori
tizedTexture::create(manager))); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) OVERRI
DE | 49 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) OVERRI
DE |
| 50 { | 50 { |
| 51 return PlatformColor::sameComponentOrder(textureFormat) ? | 51 return PlatformColor::sameComponentOrder(textureFormat) ? |
| 52 LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdate
r::SampledTexelFormatBGRA; | 52 LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdate
r::SampledTexelFormatBGRA; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void updateTexture(CCTextureUpdateQueue& queue, CCPrioritizedTexture* textur
e, const IntRect& sourceRect, const IntSize& destOffset, bool partialUpdate) | 55 void updateTexture(TextureUpdateQueue& queue, PrioritizedTexture* texture, c
onst IntRect& sourceRect, const IntSize& destOffset, bool partialUpdate) |
| 56 { | 56 { |
| 57 // Source rect should never go outside the image pixels, even if this | 57 // Source rect should never go outside the image pixels, even if this |
| 58 // is requested because the texture extends outside the image. | 58 // is requested because the texture extends outside the image. |
| 59 IntRect clippedSourceRect = sourceRect; | 59 IntRect clippedSourceRect = sourceRect; |
| 60 IntRect imageRect = IntRect(0, 0, m_bitmap.width(), m_bitmap.height()); | 60 IntRect imageRect = IntRect(0, 0, m_bitmap.width(), m_bitmap.height()); |
| 61 clippedSourceRect.intersect(imageRect); | 61 clippedSourceRect.intersect(imageRect); |
| 62 | 62 |
| 63 IntSize clippedDestOffset = destOffset + IntSize(clippedSourceRect.locat
ion() - sourceRect.location()); | 63 IntSize clippedDestOffset = destOffset + IntSize(clippedSourceRect.locat
ion() - sourceRect.location()); |
| 64 | 64 |
| 65 TextureUploader::Parameters upload = { texture, &m_bitmap, NULL, { image
Rect, clippedSourceRect, clippedDestOffset } }; | 65 TextureUploader::Parameters upload = { texture, &m_bitmap, NULL, { image
Rect, clippedSourceRect, clippedDestOffset } }; |
| 66 if (partialUpdate) | 66 if (partialUpdate) |
| 67 queue.appendPartialUpload(upload); | 67 queue.appendPartialUpload(upload); |
| 68 else | 68 else |
| 69 queue.appendFullUpload(upload); | 69 queue.appendFullUpload(upload); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void setBitmap(const SkBitmap& bitmap) | 72 void setBitmap(const SkBitmap& bitmap) |
| 73 { | 73 { |
| 74 m_bitmap = bitmap; | 74 m_bitmap = bitmap; |
| 75 } | 75 } |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 ImageLayerTextureUpdater() { } | 78 ImageLayerTextureUpdater() { } |
| 79 virtual ~ImageLayerTextureUpdater() { } | 79 virtual ~ImageLayerTextureUpdater() { } |
| 80 | 80 |
| 81 SkBitmap m_bitmap; | 81 SkBitmap m_bitmap; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 scoped_refptr<ImageLayerChromium> ImageLayerChromium::create() | 84 scoped_refptr<ImageLayer> ImageLayer::create() |
| 85 { | 85 { |
| 86 return make_scoped_refptr(new ImageLayerChromium()); | 86 return make_scoped_refptr(new ImageLayer()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 ImageLayerChromium::ImageLayerChromium() | 89 ImageLayer::ImageLayer() |
| 90 : TiledLayerChromium() | 90 : TiledLayer() |
| 91 { | 91 { |
| 92 } | 92 } |
| 93 | 93 |
| 94 ImageLayerChromium::~ImageLayerChromium() | 94 ImageLayer::~ImageLayer() |
| 95 { | 95 { |
| 96 } | 96 } |
| 97 | 97 |
| 98 void ImageLayerChromium::setBitmap(const SkBitmap& bitmap) | 98 void ImageLayer::setBitmap(const SkBitmap& bitmap) |
| 99 { | 99 { |
| 100 // setBitmap() currently gets called whenever there is any | 100 // setBitmap() currently gets called whenever there is any |
| 101 // style change that affects the layer even if that change doesn't | 101 // style change that affects the layer even if that change doesn't |
| 102 // affect the actual contents of the image (e.g. a CSS animation). | 102 // affect the actual contents of the image (e.g. a CSS animation). |
| 103 // With this check in place we avoid unecessary texture uploads. | 103 // With this check in place we avoid unecessary texture uploads. |
| 104 if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef()) | 104 if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef()) |
| 105 return; | 105 return; |
| 106 | 106 |
| 107 m_bitmap = bitmap; | 107 m_bitmap = bitmap; |
| 108 setNeedsDisplay(); | 108 setNeedsDisplay(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void ImageLayerChromium::setTexturePriorities(const CCPriorityCalculator& priori
tyCalc) | 111 void ImageLayer::setTexturePriorities(const PriorityCalculator& priorityCalc) |
| 112 { | 112 { |
| 113 // Update the tile data before creating all the layer's tiles. | 113 // Update the tile data before creating all the layer's tiles. |
| 114 updateTileSizeAndTilingOption(); | 114 updateTileSizeAndTilingOption(); |
| 115 | 115 |
| 116 TiledLayerChromium::setTexturePriorities(priorityCalc); | 116 TiledLayer::setTexturePriorities(priorityCalc); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void ImageLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTr
acker* occlusion, CCRenderingStats& stats) | 119 void ImageLayer::update(TextureUpdateQueue& queue, const OcclusionTracker* occlu
sion, RenderingStats& stats) |
| 120 { | 120 { |
| 121 createTextureUpdaterIfNeeded(); | 121 createTextureUpdaterIfNeeded(); |
| 122 if (m_needsDisplay) { | 122 if (m_needsDisplay) { |
| 123 m_textureUpdater->setBitmap(m_bitmap); | 123 m_textureUpdater->setBitmap(m_bitmap); |
| 124 updateTileSizeAndTilingOption(); | 124 updateTileSizeAndTilingOption(); |
| 125 invalidateContentRect(IntRect(IntPoint(), contentBounds())); | 125 invalidateContentRect(IntRect(IntPoint(), contentBounds())); |
| 126 m_needsDisplay = false; | 126 m_needsDisplay = false; |
| 127 } | 127 } |
| 128 TiledLayerChromium::update(queue, occlusion, stats); | 128 TiledLayer::update(queue, occlusion, stats); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ImageLayerChromium::createTextureUpdaterIfNeeded() | 131 void ImageLayer::createTextureUpdaterIfNeeded() |
| 132 { | 132 { |
| 133 if (m_textureUpdater) | 133 if (m_textureUpdater) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 m_textureUpdater = ImageLayerTextureUpdater::create(); | 136 m_textureUpdater = ImageLayerTextureUpdater::create(); |
| 137 GC3Denum textureFormat = layerTreeHost()->rendererCapabilities().bestTexture
Format; | 137 GC3Denum textureFormat = layerTreeHost()->rendererCapabilities().bestTexture
Format; |
| 138 setTextureFormat(textureFormat); | 138 setTextureFormat(textureFormat); |
| 139 setSampledTexelFormat(textureUpdater()->sampledTexelFormat(textureFormat)); | 139 setSampledTexelFormat(textureUpdater()->sampledTexelFormat(textureFormat)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 LayerTextureUpdater* ImageLayerChromium::textureUpdater() const | 142 LayerTextureUpdater* ImageLayer::textureUpdater() const |
| 143 { | 143 { |
| 144 return m_textureUpdater.get(); | 144 return m_textureUpdater.get(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 IntSize ImageLayerChromium::contentBounds() const | 147 IntSize ImageLayer::contentBounds() const |
| 148 { | 148 { |
| 149 return IntSize(m_bitmap.width(), m_bitmap.height()); | 149 return IntSize(m_bitmap.width(), m_bitmap.height()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool ImageLayerChromium::drawsContent() const | 152 bool ImageLayer::drawsContent() const |
| 153 { | 153 { |
| 154 return !m_bitmap.isNull() && TiledLayerChromium::drawsContent(); | 154 return !m_bitmap.isNull() && TiledLayer::drawsContent(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool ImageLayerChromium::needsContentsScale() const | 157 bool ImageLayer::needsContentsScale() const |
| 158 { | 158 { |
| 159 // Contents scale is not need for image layer because this can be done in co
mpositor more efficiently. | 159 // Contents scale is not need for image layer because this can be done in co
mpositor more efficiently. |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 | 162 |
| 163 } | 163 } |
| OLD | NEW |