| 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/texture_layer.h" | 5 #include "cc/texture_layer.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_host.h" | 7 #include "cc/layer_tree_host.h" |
| 8 #include "cc/texture_layer_client.h" | 8 #include "cc/texture_layer_client.h" |
| 9 #include "cc/texture_layer_impl.h" | 9 #include "cc/texture_layer_impl.h" |
| 10 #include "cc/thread.h" | 10 #include "cc/thread.h" |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 static void runCallbackOnMainThread(const TextureMailbox::ReleaseCallback& callb
ack, unsigned syncPoint) | 15 static void runCallbackOnMainThread(const TextureMailbox::ReleaseCallback& callb
ack, unsigned syncPoint) |
| 16 { | 16 { |
| 17 callback.Run(syncPoint); | 17 callback.Run(syncPoint); |
| 18 } | 18 } |
| 19 | 19 |
| 20 static void postCallbackToMainThread(Thread *mainThread, const TextureMailbox::R
eleaseCallback& callback, unsigned syncPoint) | 20 static void postCallbackToMainThread(Thread *mainThread, const TextureMailbox::R
eleaseCallback& callback, unsigned syncPoint) |
| 21 { | 21 { |
| 22 mainThread->postTask(base::Bind(&runCallbackOnMainThread, callback, syncPoin
t)); | 22 mainThread->postTask(base::Bind(&runCallbackOnMainThread, callback, syncPoin
t)); |
| 23 } | 23 } |
| 24 | 24 |
| 25 scoped_refptr<TextureLayer> TextureLayer::create(TextureLayerClient* client) | 25 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) |
| 26 { | 26 { |
| 27 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); | 27 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 scoped_refptr<TextureLayer> TextureLayer::createForMailbox() | 30 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox() |
| 31 { | 31 { |
| 32 return scoped_refptr<TextureLayer>(new TextureLayer(0, true)); | 32 return scoped_refptr<TextureLayer>(new TextureLayer(0, true)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TextureLayer::TextureLayer(TextureLayerClient* client, bool usesMailbox) | 35 TextureLayer::TextureLayer(TextureLayerClient* client, bool usesMailbox) |
| 36 : Layer() | 36 : Layer() |
| 37 , m_client(client) | 37 , m_client(client) |
| 38 , m_usesMailbox(usesMailbox) | 38 , m_usesMailbox(usesMailbox) |
| 39 , m_flipped(true) | 39 , m_flipped(true) |
| 40 , m_uvTopLeft(0.f, 0.f) | 40 , m_uvTopLeft(0.f, 0.f) |
| 41 , m_uvBottomRight(1.f, 1.f) | 41 , m_uvBottomRight(1.f, 1.f) |
| 42 , m_premultipliedAlpha(true) | 42 , m_premultipliedAlpha(true) |
| 43 , m_rateLimitContext(false) | 43 , m_rateLimitContext(false) |
| 44 , m_contextLost(false) | 44 , m_contextLost(false) |
| 45 , m_textureId(0) | 45 , m_textureId(0) |
| 46 , m_contentCommitted(false) | 46 , m_contentCommitted(false) |
| 47 , m_ownMailbox(false) | 47 , m_ownMailbox(false) |
| 48 { | 48 { |
| 49 m_vertexOpacity[0] = 1.0f; | 49 m_vertexOpacity[0] = 1.0f; |
| 50 m_vertexOpacity[1] = 1.0f; | 50 m_vertexOpacity[1] = 1.0f; |
| 51 m_vertexOpacity[2] = 1.0f; | 51 m_vertexOpacity[2] = 1.0f; |
| 52 m_vertexOpacity[3] = 1.0f; | 52 m_vertexOpacity[3] = 1.0f; |
| 53 } | 53 } |
| 54 | 54 |
| 55 TextureLayer::~TextureLayer() | 55 TextureLayer::~TextureLayer() |
| 56 { | 56 { |
| 57 if (layerTreeHost()) { | 57 if (layer_tree_host()) { |
| 58 if (m_textureId) | 58 if (m_textureId) |
| 59 layerTreeHost()->acquireLayerTextures(); | 59 layer_tree_host()->acquireLayerTextures(); |
| 60 if (m_rateLimitContext && m_client) | 60 if (m_rateLimitContext && m_client) |
| 61 layerTreeHost()->stopRateLimiter(m_client->context()); | 61 layer_tree_host()->stopRateLimiter(m_client->context()); |
| 62 } | 62 } |
| 63 if (m_ownMailbox) | 63 if (m_ownMailbox) |
| 64 m_textureMailbox.RunReleaseCallback(m_textureMailbox.sync_point()); | 64 m_textureMailbox.RunReleaseCallback(m_textureMailbox.sync_point()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeImpl* treeImpl) | 67 scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* treeImpl) |
| 68 { | 68 { |
| 69 return TextureLayerImpl::create(treeImpl, m_layerId, m_usesMailbox).PassAs<L
ayerImpl>(); | 69 return TextureLayerImpl::Create(treeImpl, id(), m_usesMailbox).PassAs<LayerI
mpl>(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void TextureLayer::setFlipped(bool flipped) | 72 void TextureLayer::setFlipped(bool flipped) |
| 73 { | 73 { |
| 74 m_flipped = flipped; | 74 m_flipped = flipped; |
| 75 setNeedsCommit(); | 75 SetNeedsCommit(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void TextureLayer::setUV(gfx::PointF topLeft, gfx::PointF bottomRight) | 78 void TextureLayer::setUV(gfx::PointF topLeft, gfx::PointF bottomRight) |
| 79 { | 79 { |
| 80 m_uvTopLeft = topLeft; | 80 m_uvTopLeft = topLeft; |
| 81 m_uvBottomRight = bottomRight; | 81 m_uvBottomRight = bottomRight; |
| 82 setNeedsCommit(); | 82 SetNeedsCommit(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void TextureLayer::setVertexOpacity(float bottomLeft, | 85 void TextureLayer::setVertexOpacity(float bottomLeft, |
| 86 float topLeft, | 86 float topLeft, |
| 87 float topRight, | 87 float topRight, |
| 88 float bottomRight) { | 88 float bottomRight) { |
| 89 // Indexing according to the quad vertex generation: | 89 // Indexing according to the quad vertex generation: |
| 90 // 1--2 | 90 // 1--2 |
| 91 // | | | 91 // | | |
| 92 // 0--3 | 92 // 0--3 |
| 93 m_vertexOpacity[0] = bottomLeft; | 93 m_vertexOpacity[0] = bottomLeft; |
| 94 m_vertexOpacity[1] = topLeft; | 94 m_vertexOpacity[1] = topLeft; |
| 95 m_vertexOpacity[2] = topRight; | 95 m_vertexOpacity[2] = topRight; |
| 96 m_vertexOpacity[3] = bottomRight; | 96 m_vertexOpacity[3] = bottomRight; |
| 97 setNeedsCommit(); | 97 SetNeedsCommit(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void TextureLayer::setPremultipliedAlpha(bool premultipliedAlpha) | 100 void TextureLayer::setPremultipliedAlpha(bool premultipliedAlpha) |
| 101 { | 101 { |
| 102 m_premultipliedAlpha = premultipliedAlpha; | 102 m_premultipliedAlpha = premultipliedAlpha; |
| 103 setNeedsCommit(); | 103 SetNeedsCommit(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void TextureLayer::setRateLimitContext(bool rateLimit) | 106 void TextureLayer::setRateLimitContext(bool rateLimit) |
| 107 { | 107 { |
| 108 if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost()) | 108 if (!rateLimit && m_rateLimitContext && m_client && layer_tree_host()) |
| 109 layerTreeHost()->stopRateLimiter(m_client->context()); | 109 layer_tree_host()->stopRateLimiter(m_client->context()); |
| 110 | 110 |
| 111 m_rateLimitContext = rateLimit; | 111 m_rateLimitContext = rateLimit; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void TextureLayer::setTextureId(unsigned id) | 114 void TextureLayer::setTextureId(unsigned id) |
| 115 { | 115 { |
| 116 DCHECK(!m_usesMailbox); | 116 DCHECK(!m_usesMailbox); |
| 117 if (m_textureId == id) | 117 if (m_textureId == id) |
| 118 return; | 118 return; |
| 119 if (m_textureId && layerTreeHost()) | 119 if (m_textureId && layer_tree_host()) |
| 120 layerTreeHost()->acquireLayerTextures(); | 120 layer_tree_host()->acquireLayerTextures(); |
| 121 m_textureId = id; | 121 m_textureId = id; |
| 122 setNeedsCommit(); | 122 SetNeedsCommit(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void TextureLayer::setTextureMailbox(const TextureMailbox& mailbox) | 125 void TextureLayer::setTextureMailbox(const TextureMailbox& mailbox) |
| 126 { | 126 { |
| 127 DCHECK(m_usesMailbox); | 127 DCHECK(m_usesMailbox); |
| 128 DCHECK(mailbox.IsEmpty() || !mailbox.Equals(m_textureMailbox)); | 128 DCHECK(mailbox.IsEmpty() || !mailbox.Equals(m_textureMailbox)); |
| 129 // If we never commited the mailbox, we need to release it here | 129 // If we never commited the mailbox, we need to release it here |
| 130 if (m_ownMailbox) | 130 if (m_ownMailbox) |
| 131 m_textureMailbox.RunReleaseCallback(m_textureMailbox.sync_point()); | 131 m_textureMailbox.RunReleaseCallback(m_textureMailbox.sync_point()); |
| 132 m_textureMailbox = mailbox; | 132 m_textureMailbox = mailbox; |
| 133 m_ownMailbox = true; | 133 m_ownMailbox = true; |
| 134 | 134 |
| 135 setNeedsCommit(); | 135 SetNeedsCommit(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void TextureLayer::willModifyTexture() | 138 void TextureLayer::willModifyTexture() |
| 139 { | 139 { |
| 140 if (layerTreeHost() && (drawsContent() || m_contentCommitted)) { | 140 if (layer_tree_host() && (DrawsContent() || m_contentCommitted)) { |
| 141 layerTreeHost()->acquireLayerTextures(); | 141 layer_tree_host()->acquireLayerTextures(); |
| 142 m_contentCommitted = false; | 142 m_contentCommitted = false; |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 void TextureLayer::setNeedsDisplayRect(const gfx::RectF& dirtyRect) | 146 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirtyRect) |
| 147 { | 147 { |
| 148 Layer::setNeedsDisplayRect(dirtyRect); | 148 Layer::SetNeedsDisplayRect(dirtyRect); |
| 149 | 149 |
| 150 if (m_rateLimitContext && m_client && layerTreeHost() && drawsContent()) | 150 if (m_rateLimitContext && m_client && layer_tree_host() && DrawsContent()) |
| 151 layerTreeHost()->startRateLimiter(m_client->context()); | 151 layer_tree_host()->startRateLimiter(m_client->context()); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void TextureLayer::setLayerTreeHost(LayerTreeHost* host) | 154 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) |
| 155 { | 155 { |
| 156 if (m_textureId && layerTreeHost() && host != layerTreeHost()) | 156 if (m_textureId && layer_tree_host() && host != layer_tree_host()) |
| 157 layerTreeHost()->acquireLayerTextures(); | 157 layer_tree_host()->acquireLayerTextures(); |
| 158 Layer::setLayerTreeHost(host); | 158 Layer::SetLayerTreeHost(host); |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool TextureLayer::drawsContent() const | 161 bool TextureLayer::DrawsContent() const |
| 162 { | 162 { |
| 163 return (m_client || m_textureId || !m_textureMailbox.IsEmpty()) && !m_contex
tLost && Layer::drawsContent(); | 163 return (m_client || m_textureId || !m_textureMailbox.IsEmpty()) && !m_contex
tLost && Layer::DrawsContent(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void TextureLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*, R
enderingStats*) | 166 void TextureLayer::Update(ResourceUpdateQueue* queue, const OcclusionTracker*, R
enderingStats*) |
| 167 { | 167 { |
| 168 if (m_client) { | 168 if (m_client) { |
| 169 m_textureId = m_client->prepareTexture(queue); | 169 m_textureId = m_client->prepareTexture(*queue); |
| 170 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GL_N
O_ERROR; | 170 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GL_N
O_ERROR; |
| 171 } | 171 } |
| 172 | 172 |
| 173 m_needsDisplay = false; | 173 needs_display_ = false; |
| 174 } | 174 } |
| 175 | 175 |
| 176 void TextureLayer::pushPropertiesTo(LayerImpl* layer) | 176 void TextureLayer::PushPropertiesTo(LayerImpl* layer) |
| 177 { | 177 { |
| 178 Layer::pushPropertiesTo(layer); | 178 Layer::PushPropertiesTo(layer); |
| 179 | 179 |
| 180 TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer); | 180 TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer); |
| 181 textureLayer->setFlipped(m_flipped); | 181 textureLayer->setFlipped(m_flipped); |
| 182 textureLayer->setUVTopLeft(m_uvTopLeft); | 182 textureLayer->setUVTopLeft(m_uvTopLeft); |
| 183 textureLayer->setUVBottomRight(m_uvBottomRight); | 183 textureLayer->setUVBottomRight(m_uvBottomRight); |
| 184 textureLayer->setVertexOpacity(m_vertexOpacity); | 184 textureLayer->setVertexOpacity(m_vertexOpacity); |
| 185 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); | 185 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); |
| 186 if (m_usesMailbox && m_ownMailbox) { | 186 if (m_usesMailbox && m_ownMailbox) { |
| 187 Thread* mainThread = layerTreeHost()->proxy()->MainThread(); | 187 Thread* mainThread = layer_tree_host()->proxy()->MainThread(); |
| 188 TextureMailbox::ReleaseCallback callback; | 188 TextureMailbox::ReleaseCallback callback; |
| 189 if (!m_textureMailbox.IsEmpty()) | 189 if (!m_textureMailbox.IsEmpty()) |
| 190 callback = base::Bind(&postCallbackToMainThread, mainThread, m_texture
Mailbox.callback()); | 190 callback = base::Bind(&postCallbackToMainThread, mainThread, m_texture
Mailbox.callback()); |
| 191 textureLayer->setTextureMailbox(TextureMailbox(m_textureMailbox.name(),
callback, m_textureMailbox.sync_point())); | 191 textureLayer->setTextureMailbox(TextureMailbox(m_textureMailbox.name(),
callback, m_textureMailbox.sync_point())); |
| 192 m_ownMailbox = false; | 192 m_ownMailbox = false; |
| 193 } else { | 193 } else { |
| 194 textureLayer->setTextureId(m_textureId); | 194 textureLayer->setTextureId(m_textureId); |
| 195 } | 195 } |
| 196 m_contentCommitted = drawsContent(); | 196 m_contentCommitted = DrawsContent(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool TextureLayer::blocksPendingCommit() const | 199 bool TextureLayer::BlocksPendingCommit() const |
| 200 { | 200 { |
| 201 // Double-buffered texture layers need to be blocked until they can be made | 201 // Double-buffered texture layers need to be blocked until they can be made |
| 202 // triple-buffered. Single-buffered layers already prevent draws, so | 202 // triple-buffered. Single-buffered layers already prevent draws, so |
| 203 // can block too for simplicity. | 203 // can block too for simplicity. |
| 204 return drawsContent(); | 204 return DrawsContent(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 bool TextureLayer::canClipSelf() const | 207 bool TextureLayer::CanClipSelf() const |
| 208 { | 208 { |
| 209 return true; | 209 return true; |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace cc | 212 } // namespace cc |
| OLD | NEW |