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