| 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 "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
| 11 #include "third_party/khronos/GLES2/gl2.h" | |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 static void runCallbackOnMainThread(const TextureLayer::MailboxCallback& callbac
k, unsigned syncPoint) |
| 16 { |
| 17 callback.Run(syncPoint); |
| 18 } |
| 19 |
| 20 static void postCallbackToMainThread(Thread *mainThread, const TextureLayer::Mai
lboxCallback& callback, unsigned syncPoint) |
| 21 { |
| 22 mainThread->postTask(base::Bind(&runCallbackOnMainThread, callback, syncPoin
t)); |
| 23 } |
| 24 |
| 15 scoped_refptr<TextureLayer> TextureLayer::create(TextureLayerClient* client) | 25 scoped_refptr<TextureLayer> TextureLayer::create(TextureLayerClient* client) |
| 16 { | 26 { |
| 17 return scoped_refptr<TextureLayer>(new TextureLayer(client)); | 27 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); |
| 18 } | 28 } |
| 19 | 29 |
| 20 TextureLayer::TextureLayer(TextureLayerClient* client) | 30 scoped_refptr<TextureLayer> TextureLayer::createForMailbox() |
| 31 { |
| 32 return scoped_refptr<TextureLayer>(new TextureLayer(0, true)); |
| 33 } |
| 34 |
| 35 TextureLayer::TextureLayer(TextureLayerClient* client, bool usesMailbox) |
| 21 : Layer() | 36 : Layer() |
| 22 , m_client(client) | 37 , m_client(client) |
| 38 , m_usesMailbox(usesMailbox) |
| 23 , m_flipped(true) | 39 , m_flipped(true) |
| 24 , m_uvRect(0, 0, 1, 1) | 40 , m_uvRect(0, 0, 1, 1) |
| 25 , m_premultipliedAlpha(true) | 41 , m_premultipliedAlpha(true) |
| 26 , m_rateLimitContext(false) | 42 , m_rateLimitContext(false) |
| 27 , m_contextLost(false) | 43 , m_contextLost(false) |
| 28 , m_textureId(0) | 44 , m_textureId(0) |
| 29 , m_contentCommitted(false) | 45 , m_contentCommitted(false) |
| 30 { | 46 { |
| 31 m_vertexOpacity[0] = 1.0f; | 47 m_vertexOpacity[0] = 1.0f; |
| 32 m_vertexOpacity[1] = 1.0f; | 48 m_vertexOpacity[1] = 1.0f; |
| 33 m_vertexOpacity[2] = 1.0f; | 49 m_vertexOpacity[2] = 1.0f; |
| 34 m_vertexOpacity[3] = 1.0f; | 50 m_vertexOpacity[3] = 1.0f; |
| 35 } | 51 } |
| 36 | 52 |
| 37 TextureLayer::~TextureLayer() | 53 TextureLayer::~TextureLayer() |
| 38 { | 54 { |
| 39 if (layerTreeHost()) { | 55 if (layerTreeHost()) { |
| 40 if (m_textureId) | 56 if (m_textureId) |
| 41 layerTreeHost()->acquireLayerTextures(); | 57 layerTreeHost()->acquireLayerTextures(); |
| 42 if (m_rateLimitContext && m_client) | 58 if (m_rateLimitContext && m_client) |
| 43 layerTreeHost()->stopRateLimiter(m_client->context()); | 59 layerTreeHost()->stopRateLimiter(m_client->context()); |
| 44 } | 60 } |
| 61 if (!m_contentCommitted && !m_mailboxName.empty()) |
| 62 m_mailboxReleaseCallback.Run(0); |
| 45 } | 63 } |
| 46 | 64 |
| 47 scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeImpl* treeImpl) | 65 scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeImpl* treeImpl) |
| 48 { | 66 { |
| 49 return TextureLayerImpl::create(treeImpl, m_layerId).PassAs<LayerImpl>(); | 67 return TextureLayerImpl::create(treeImpl, m_layerId, m_usesMailbox).PassAs<L
ayerImpl>(); |
| 50 } | 68 } |
| 51 | 69 |
| 52 void TextureLayer::setFlipped(bool flipped) | 70 void TextureLayer::setFlipped(bool flipped) |
| 53 { | 71 { |
| 54 m_flipped = flipped; | 72 m_flipped = flipped; |
| 55 setNeedsCommit(); | 73 setNeedsCommit(); |
| 56 } | 74 } |
| 57 | 75 |
| 58 void TextureLayer::setUVRect(const gfx::RectF& rect) | 76 void TextureLayer::setUVRect(const gfx::RectF& rect) |
| 59 { | 77 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 85 void TextureLayer::setRateLimitContext(bool rateLimit) | 103 void TextureLayer::setRateLimitContext(bool rateLimit) |
| 86 { | 104 { |
| 87 if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost()) | 105 if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost()) |
| 88 layerTreeHost()->stopRateLimiter(m_client->context()); | 106 layerTreeHost()->stopRateLimiter(m_client->context()); |
| 89 | 107 |
| 90 m_rateLimitContext = rateLimit; | 108 m_rateLimitContext = rateLimit; |
| 91 } | 109 } |
| 92 | 110 |
| 93 void TextureLayer::setTextureId(unsigned id) | 111 void TextureLayer::setTextureId(unsigned id) |
| 94 { | 112 { |
| 113 DCHECK(!m_usesMailbox); |
| 95 if (m_textureId == id) | 114 if (m_textureId == id) |
| 96 return; | 115 return; |
| 97 if (m_textureId && layerTreeHost()) | 116 if (m_textureId && layerTreeHost()) |
| 98 layerTreeHost()->acquireLayerTextures(); | 117 layerTreeHost()->acquireLayerTextures(); |
| 99 m_textureId = id; | 118 m_textureId = id; |
| 100 setNeedsCommit(); | 119 setNeedsCommit(); |
| 101 } | 120 } |
| 102 | 121 |
| 122 void TextureLayer::setTextureMailbox(const std::string& mailboxName, const Mailb
oxCallback& callback) |
| 123 { |
| 124 DCHECK(m_usesMailbox); |
| 125 DCHECK(mailboxName.empty() == callback.is_null()); |
| 126 if (m_mailboxName.compare(mailboxName) == 0) |
| 127 return; |
| 128 // If we never commited the mailbox, we need to release it here |
| 129 if (!m_contentCommitted && !m_mailboxName.empty()) |
| 130 m_mailboxReleaseCallback.Run(0); |
| 131 m_mailboxReleaseCallback = callback; |
| 132 m_mailboxName = mailboxName; |
| 133 |
| 134 setNeedsCommit(); |
| 135 } |
| 136 |
| 103 void TextureLayer::willModifyTexture() | 137 void TextureLayer::willModifyTexture() |
| 104 { | 138 { |
| 105 if (layerTreeHost() && (drawsContent() || m_contentCommitted)) { | 139 if (layerTreeHost() && (drawsContent() || m_contentCommitted)) { |
| 106 layerTreeHost()->acquireLayerTextures(); | 140 layerTreeHost()->acquireLayerTextures(); |
| 107 m_contentCommitted = false; | 141 m_contentCommitted = false; |
| 108 } | 142 } |
| 109 } | 143 } |
| 110 | 144 |
| 111 void TextureLayer::setNeedsDisplayRect(const gfx::RectF& dirtyRect) | 145 void TextureLayer::setNeedsDisplayRect(const gfx::RectF& dirtyRect) |
| 112 { | 146 { |
| 113 Layer::setNeedsDisplayRect(dirtyRect); | 147 Layer::setNeedsDisplayRect(dirtyRect); |
| 114 | 148 |
| 115 if (m_rateLimitContext && m_client && layerTreeHost() && drawsContent()) | 149 if (m_rateLimitContext && m_client && layerTreeHost() && drawsContent()) |
| 116 layerTreeHost()->startRateLimiter(m_client->context()); | 150 layerTreeHost()->startRateLimiter(m_client->context()); |
| 117 } | 151 } |
| 118 | 152 |
| 119 void TextureLayer::setLayerTreeHost(LayerTreeHost* host) | 153 void TextureLayer::setLayerTreeHost(LayerTreeHost* host) |
| 120 { | 154 { |
| 121 if (m_textureId && layerTreeHost() && host != layerTreeHost()) | 155 if (m_textureId && layerTreeHost() && host != layerTreeHost()) |
| 122 layerTreeHost()->acquireLayerTextures(); | 156 layerTreeHost()->acquireLayerTextures(); |
| 123 Layer::setLayerTreeHost(host); | 157 Layer::setLayerTreeHost(host); |
| 124 } | 158 } |
| 125 | 159 |
| 126 bool TextureLayer::drawsContent() const | 160 bool TextureLayer::drawsContent() const |
| 127 { | 161 { |
| 128 return (m_client || m_textureId) && !m_contextLost && Layer::drawsContent(); | 162 return (m_client || m_textureId || !m_mailboxName.empty()) && !m_contextLost
&& Layer::drawsContent(); |
| 129 } | 163 } |
| 130 | 164 |
| 131 void TextureLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*, R
enderingStats&) | 165 void TextureLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*, R
enderingStats&) |
| 132 { | 166 { |
| 133 if (m_client) { | 167 if (m_client) { |
| 134 m_textureId = m_client->prepareTexture(queue); | 168 m_textureId = m_client->prepareTexture(queue); |
| 135 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GL_N
O_ERROR; | 169 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GL_N
O_ERROR; |
| 136 } | 170 } |
| 137 | 171 |
| 138 m_needsDisplay = false; | 172 m_needsDisplay = false; |
| 139 } | 173 } |
| 140 | 174 |
| 141 void TextureLayer::pushPropertiesTo(LayerImpl* layer) | 175 void TextureLayer::pushPropertiesTo(LayerImpl* layer) |
| 142 { | 176 { |
| 143 Layer::pushPropertiesTo(layer); | 177 Layer::pushPropertiesTo(layer); |
| 144 | 178 |
| 145 TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer); | 179 TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer); |
| 146 textureLayer->setFlipped(m_flipped); | 180 textureLayer->setFlipped(m_flipped); |
| 147 textureLayer->setUVRect(m_uvRect); | 181 textureLayer->setUVRect(m_uvRect); |
| 148 textureLayer->setVertexOpacity(m_vertexOpacity); | 182 textureLayer->setVertexOpacity(m_vertexOpacity); |
| 149 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); | 183 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); |
| 150 textureLayer->setTextureId(m_textureId); | 184 if (m_usesMailbox) { |
| 185 Thread* mainThread = layerTreeHost()->proxy()->mainThread(); |
| 186 textureLayer->setTextureMailbox(m_mailboxName, base::Bind(&postCallbackT
oMainThread, mainThread, m_mailboxReleaseCallback)); |
| 187 } else { |
| 188 textureLayer->setTextureId(m_textureId); |
| 189 } |
| 151 m_contentCommitted = drawsContent(); | 190 m_contentCommitted = drawsContent(); |
| 152 } | 191 } |
| 153 | 192 |
| 154 bool TextureLayer::blocksPendingCommit() const | 193 bool TextureLayer::blocksPendingCommit() const |
| 155 { | 194 { |
| 156 // Double-buffered texture layers need to be blocked until they can be made | 195 // Double-buffered texture layers need to be blocked until they can be made |
| 157 // triple-buffered. Single-buffered layers already prevent draws, so | 196 // triple-buffered. Single-buffered layers already prevent draws, so |
| 158 // can block too for simplicity. | 197 // can block too for simplicity. |
| 159 return true; | 198 return true; |
| 160 } | 199 } |
| 161 | 200 |
| 162 } // namespace cc | 201 } // namespace cc |
| OLD | NEW |