Chromium Code Reviews| Index: cc/texture_layer.cc |
| diff --git a/cc/texture_layer.cc b/cc/texture_layer.cc |
| index 36c4220371d6f5653a7dedae16ed17b414504f96..7df01efbdb6b67dc5137162407fef412e1937cda 100644 |
| --- a/cc/texture_layer.cc |
| +++ b/cc/texture_layer.cc |
| @@ -7,19 +7,33 @@ |
| #include "cc/layer_tree_host.h" |
| #include "cc/texture_layer_client.h" |
| #include "cc/texture_layer_impl.h" |
| +#include "cc/thread.h" |
| #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" |
| -#include "third_party/khronos/GLES2/gl2.h" |
| namespace cc { |
| +static void runCallback(const base::Callback<void(unsigned)>& callback, unsigned syncPoint) { |
|
danakj
2013/01/02 20:09:44
This one would be runCallbackOnMainThread (it's al
|
| + callback.Run(syncPoint); |
| +} |
| + |
| +static void runCallbackOnMain(Thread *mainThread, const base::Callback<void(unsigned)>& callback, unsigned syncPoint) { |
|
danakj
2013/01/02 20:09:44
This would postCallbackToMainThread or something.
|
| + mainThread->postTask(base::Bind(&runCallback, callback, syncPoint)); |
| +} |
| + |
| scoped_refptr<TextureLayer> TextureLayer::create(TextureLayerClient* client) |
| { |
| - return scoped_refptr<TextureLayer>(new TextureLayer(client)); |
| + return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); |
| +} |
| + |
| +scoped_refptr<TextureLayer> TextureLayer::createForMailbox() |
| +{ |
| + return scoped_refptr<TextureLayer>(new TextureLayer(0, true)); |
| } |
| -TextureLayer::TextureLayer(TextureLayerClient* client) |
| +TextureLayer::TextureLayer(TextureLayerClient* client, bool usesMailbox) |
| : Layer() |
| , m_client(client) |
| + , m_usesMailbox(usesMailbox) |
| , m_flipped(true) |
| , m_uvRect(0, 0, 1, 1) |
| , m_premultipliedAlpha(true) |
| @@ -42,11 +56,13 @@ TextureLayer::~TextureLayer() |
| if (m_rateLimitContext && m_client) |
| layerTreeHost()->stopRateLimiter(m_client->context()); |
| } |
| + if (!m_contentCommitted && !m_mailboxName.empty()) |
| + m_mailboxReleaseCallback.Run(0); |
| } |
| scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeImpl* treeImpl) |
| { |
| - return TextureLayerImpl::create(treeImpl, m_layerId).PassAs<LayerImpl>(); |
| + return TextureLayerImpl::create(treeImpl, m_layerId, m_usesMailbox).PassAs<LayerImpl>(); |
| } |
| void TextureLayer::setFlipped(bool flipped) |
| @@ -92,6 +108,7 @@ void TextureLayer::setRateLimitContext(bool rateLimit) |
| void TextureLayer::setTextureId(unsigned id) |
| { |
| + DCHECK(!m_usesMailbox); |
| if (m_textureId == id) |
| return; |
| if (m_textureId && layerTreeHost()) |
| @@ -100,6 +117,21 @@ void TextureLayer::setTextureId(unsigned id) |
| setNeedsCommit(); |
| } |
| +void TextureLayer::setTextureMailbox(const std::string& mailboxName, const base::Callback<void(unsigned)>& callback) |
| +{ |
| + DCHECK(m_usesMailbox); |
| + DCHECK(mailboxName.empty() == callback.is_null()); |
| + if (m_mailboxName.compare(mailboxName) == 0) |
| + return; |
| + // If we never commited the mailbox, we need to release it here |
| + if (!m_contentCommitted && !m_mailboxName.empty()) |
| + m_mailboxReleaseCallback.Run(0); |
| + m_mailboxReleaseCallback = callback; |
| + m_mailboxName = mailboxName; |
| + |
| + setNeedsCommit(); |
| +} |
| + |
| void TextureLayer::willModifyTexture() |
| { |
| if (layerTreeHost() && (drawsContent() || m_contentCommitted)) { |
| @@ -125,7 +157,7 @@ void TextureLayer::setLayerTreeHost(LayerTreeHost* host) |
| bool TextureLayer::drawsContent() const |
| { |
| - return (m_client || m_textureId) && !m_contextLost && Layer::drawsContent(); |
| + return (m_client || m_textureId || !m_mailboxName.empty()) && !m_contextLost && Layer::drawsContent(); |
| } |
| void TextureLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*, RenderingStats&) |
| @@ -147,7 +179,12 @@ void TextureLayer::pushPropertiesTo(LayerImpl* layer) |
| textureLayer->setUVRect(m_uvRect); |
| textureLayer->setVertexOpacity(m_vertexOpacity); |
| textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); |
| - textureLayer->setTextureId(m_textureId); |
| + if (m_usesMailbox) { |
| + Thread* mainThread = layerTreeHost()->proxy()->mainThread(); |
| + textureLayer->setTextureMailbox(m_mailboxName, base::Bind(&runCallbackOnMain, mainThread, m_mailboxReleaseCallback)); |
| + } else { |
| + textureLayer->setTextureId(m_textureId); |
| + } |
| m_contentCommitted = drawsContent(); |
| } |