| 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 TextureLayer::MailboxCallback& callbac
k, 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 TextureLayer::Mai
lboxCallback& 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() |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 TextureLayer::~TextureLayer() | 53 TextureLayer::~TextureLayer() |
| 54 { | 54 { |
| 55 if (layerTreeHost()) { | 55 if (layerTreeHost()) { |
| 56 if (m_textureId) | 56 if (m_textureId) |
| 57 layerTreeHost()->acquireLayerTextures(); | 57 layerTreeHost()->acquireLayerTextures(); |
| 58 if (m_rateLimitContext && m_client) | 58 if (m_rateLimitContext && m_client) |
| 59 layerTreeHost()->stopRateLimiter(m_client->context()); | 59 layerTreeHost()->stopRateLimiter(m_client->context()); |
| 60 } | 60 } |
| 61 if (!m_contentCommitted && !m_mailboxName.empty()) | 61 if (!m_contentCommitted) |
| 62 m_mailboxReleaseCallback.Run(0); | 62 m_textureMailbox.RunReleaseCallback(0); |
| 63 } | 63 } |
| 64 | 64 |
| 65 scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeImpl* treeImpl) | 65 scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeImpl* treeImpl) |
| 66 { | 66 { |
| 67 return TextureLayerImpl::create(treeImpl, m_layerId, m_usesMailbox).PassAs<L
ayerImpl>(); | 67 return TextureLayerImpl::create(treeImpl, m_layerId, m_usesMailbox).PassAs<L
ayerImpl>(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void TextureLayer::setFlipped(bool flipped) | 70 void TextureLayer::setFlipped(bool flipped) |
| 71 { | 71 { |
| 72 m_flipped = flipped; | 72 m_flipped = flipped; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 { | 112 { |
| 113 DCHECK(!m_usesMailbox); | 113 DCHECK(!m_usesMailbox); |
| 114 if (m_textureId == id) | 114 if (m_textureId == id) |
| 115 return; | 115 return; |
| 116 if (m_textureId && layerTreeHost()) | 116 if (m_textureId && layerTreeHost()) |
| 117 layerTreeHost()->acquireLayerTextures(); | 117 layerTreeHost()->acquireLayerTextures(); |
| 118 m_textureId = id; | 118 m_textureId = id; |
| 119 setNeedsCommit(); | 119 setNeedsCommit(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void TextureLayer::setTextureMailbox(const std::string& mailboxName, const Mailb
oxCallback& callback) | 122 void TextureLayer::setTextureMailbox(const TextureMailbox& mailbox) |
| 123 { | 123 { |
| 124 DCHECK(m_usesMailbox); | 124 DCHECK(m_usesMailbox); |
| 125 DCHECK(mailboxName.empty() == callback.is_null()); | 125 if (m_textureMailbox.Equals(mailbox)) |
| 126 if (m_mailboxName.compare(mailboxName) == 0) | |
| 127 return; | 126 return; |
| 128 // If we never commited the mailbox, we need to release it here | 127 // If we never commited the mailbox, we need to release it here |
| 129 if (!m_contentCommitted && !m_mailboxName.empty()) | 128 if (!m_contentCommitted) |
| 130 m_mailboxReleaseCallback.Run(0); | 129 m_textureMailbox.RunReleaseCallback(0); |
| 131 m_mailboxReleaseCallback = callback; | 130 m_textureMailbox = mailbox; |
| 132 m_mailboxName = mailboxName; | |
| 133 | 131 |
| 134 setNeedsCommit(); | 132 setNeedsCommit(); |
| 135 } | 133 } |
| 136 | 134 |
| 137 void TextureLayer::willModifyTexture() | 135 void TextureLayer::willModifyTexture() |
| 138 { | 136 { |
| 139 if (layerTreeHost() && (drawsContent() || m_contentCommitted)) { | 137 if (layerTreeHost() && (drawsContent() || m_contentCommitted)) { |
| 140 layerTreeHost()->acquireLayerTextures(); | 138 layerTreeHost()->acquireLayerTextures(); |
| 141 m_contentCommitted = false; | 139 m_contentCommitted = false; |
| 142 } | 140 } |
| 143 } | 141 } |
| 144 | 142 |
| 145 void TextureLayer::setNeedsDisplayRect(const gfx::RectF& dirtyRect) | 143 void TextureLayer::setNeedsDisplayRect(const gfx::RectF& dirtyRect) |
| 146 { | 144 { |
| 147 Layer::setNeedsDisplayRect(dirtyRect); | 145 Layer::setNeedsDisplayRect(dirtyRect); |
| 148 | 146 |
| 149 if (m_rateLimitContext && m_client && layerTreeHost() && drawsContent()) | 147 if (m_rateLimitContext && m_client && layerTreeHost() && drawsContent()) |
| 150 layerTreeHost()->startRateLimiter(m_client->context()); | 148 layerTreeHost()->startRateLimiter(m_client->context()); |
| 151 } | 149 } |
| 152 | 150 |
| 153 void TextureLayer::setLayerTreeHost(LayerTreeHost* host) | 151 void TextureLayer::setLayerTreeHost(LayerTreeHost* host) |
| 154 { | 152 { |
| 155 if (m_textureId && layerTreeHost() && host != layerTreeHost()) | 153 if (m_textureId && layerTreeHost() && host != layerTreeHost()) |
| 156 layerTreeHost()->acquireLayerTextures(); | 154 layerTreeHost()->acquireLayerTextures(); |
| 157 Layer::setLayerTreeHost(host); | 155 Layer::setLayerTreeHost(host); |
| 158 } | 156 } |
| 159 | 157 |
| 160 bool TextureLayer::drawsContent() const | 158 bool TextureLayer::drawsContent() const |
| 161 { | 159 { |
| 162 return (m_client || m_textureId || !m_mailboxName.empty()) && !m_contextLost
&& Layer::drawsContent(); | 160 return (m_client || m_textureId || !m_textureMailbox.IsEmpty()) && !m_contex
tLost && Layer::drawsContent(); |
| 163 } | 161 } |
| 164 | 162 |
| 165 void TextureLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*, R
enderingStats&) | 163 void TextureLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*, R
enderingStats&) |
| 166 { | 164 { |
| 167 if (m_client) { | 165 if (m_client) { |
| 168 m_textureId = m_client->prepareTexture(queue); | 166 m_textureId = m_client->prepareTexture(queue); |
| 169 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GL_N
O_ERROR; | 167 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GL_N
O_ERROR; |
| 170 } | 168 } |
| 171 | 169 |
| 172 m_needsDisplay = false; | 170 m_needsDisplay = false; |
| 173 } | 171 } |
| 174 | 172 |
| 175 void TextureLayer::pushPropertiesTo(LayerImpl* layer) | 173 void TextureLayer::pushPropertiesTo(LayerImpl* layer) |
| 176 { | 174 { |
| 177 Layer::pushPropertiesTo(layer); | 175 Layer::pushPropertiesTo(layer); |
| 178 | 176 |
| 179 TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer); | 177 TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer); |
| 180 textureLayer->setFlipped(m_flipped); | 178 textureLayer->setFlipped(m_flipped); |
| 181 textureLayer->setUVRect(m_uvRect); | 179 textureLayer->setUVRect(m_uvRect); |
| 182 textureLayer->setVertexOpacity(m_vertexOpacity); | 180 textureLayer->setVertexOpacity(m_vertexOpacity); |
| 183 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); | 181 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); |
| 184 if (m_usesMailbox) { | 182 if (m_usesMailbox) { |
| 185 Thread* mainThread = layerTreeHost()->proxy()->mainThread(); | 183 Thread* mainThread = layerTreeHost()->proxy()->mainThread(); |
| 186 textureLayer->setTextureMailbox(m_mailboxName, base::Bind(&postCallbackT
oMainThread, mainThread, m_mailboxReleaseCallback)); | 184 TextureMailbox::ReleaseCallback callback; |
| 185 if (!m_textureMailbox.IsEmpty()) |
| 186 callback = base::Bind(&postCallbackToMainThread, mainThread, m_texture
Mailbox.callback()); |
| 187 textureLayer->setTextureMailbox(TextureMailbox(m_textureMailbox.name(),
callback)); |
| 187 } else { | 188 } else { |
| 188 textureLayer->setTextureId(m_textureId); | 189 textureLayer->setTextureId(m_textureId); |
| 189 } | 190 } |
| 190 m_contentCommitted = drawsContent(); | 191 m_contentCommitted = drawsContent(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 bool TextureLayer::blocksPendingCommit() const | 194 bool TextureLayer::blocksPendingCommit() const |
| 194 { | 195 { |
| 195 // Double-buffered texture layers need to be blocked until they can be made | 196 // Double-buffered texture layers need to be blocked until they can be made |
| 196 // triple-buffered. Single-buffered layers already prevent draws, so | 197 // triple-buffered. Single-buffered layers already prevent draws, so |
| 197 // can block too for simplicity. | 198 // can block too for simplicity. |
| 198 return drawsContent(); | 199 return drawsContent(); |
| 199 } | 200 } |
| 200 | 201 |
| 201 bool TextureLayer::canClipSelf() const | 202 bool TextureLayer::canClipSelf() const |
| 202 { | 203 { |
| 203 return true; | 204 return true; |
| 204 } | 205 } |
| 205 | 206 |
| 206 } // namespace cc | 207 } // namespace cc |
| OLD | NEW |