Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Side by Side Diff: cc/texture_layer.cc

Issue 11638028: Mailbox support for texture layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback, callback runs on main. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 runCallback(const base::Callback<void(unsigned)>& callback, unsigned syncPoint) {
danakj 2013/01/02 20:09:44 This one would be runCallbackOnMainThread (it's al
16 callback.Run(syncPoint);
17 }
18
19 static void runCallbackOnMain(Thread *mainThread, const base::Callback<void(unsi gned)>& callback, unsigned syncPoint) {
danakj 2013/01/02 20:09:44 This would postCallbackToMainThread or something.
20 mainThread->postTask(base::Bind(&runCallback, callback, syncPoint));
21 }
22
15 scoped_refptr<TextureLayer> TextureLayer::create(TextureLayerClient* client) 23 scoped_refptr<TextureLayer> TextureLayer::create(TextureLayerClient* client)
16 { 24 {
17 return scoped_refptr<TextureLayer>(new TextureLayer(client)); 25 return scoped_refptr<TextureLayer>(new TextureLayer(client, false));
18 } 26 }
19 27
20 TextureLayer::TextureLayer(TextureLayerClient* client) 28 scoped_refptr<TextureLayer> TextureLayer::createForMailbox()
29 {
30 return scoped_refptr<TextureLayer>(new TextureLayer(0, true));
31 }
32
33 TextureLayer::TextureLayer(TextureLayerClient* client, bool usesMailbox)
21 : Layer() 34 : Layer()
22 , m_client(client) 35 , m_client(client)
36 , m_usesMailbox(usesMailbox)
23 , m_flipped(true) 37 , m_flipped(true)
24 , m_uvRect(0, 0, 1, 1) 38 , m_uvRect(0, 0, 1, 1)
25 , m_premultipliedAlpha(true) 39 , m_premultipliedAlpha(true)
26 , m_rateLimitContext(false) 40 , m_rateLimitContext(false)
27 , m_contextLost(false) 41 , m_contextLost(false)
28 , m_textureId(0) 42 , m_textureId(0)
29 , m_contentCommitted(false) 43 , m_contentCommitted(false)
30 { 44 {
31 m_vertexOpacity[0] = 1.0f; 45 m_vertexOpacity[0] = 1.0f;
32 m_vertexOpacity[1] = 1.0f; 46 m_vertexOpacity[1] = 1.0f;
33 m_vertexOpacity[2] = 1.0f; 47 m_vertexOpacity[2] = 1.0f;
34 m_vertexOpacity[3] = 1.0f; 48 m_vertexOpacity[3] = 1.0f;
35 } 49 }
36 50
37 TextureLayer::~TextureLayer() 51 TextureLayer::~TextureLayer()
38 { 52 {
39 if (layerTreeHost()) { 53 if (layerTreeHost()) {
40 if (m_textureId) 54 if (m_textureId)
41 layerTreeHost()->acquireLayerTextures(); 55 layerTreeHost()->acquireLayerTextures();
42 if (m_rateLimitContext && m_client) 56 if (m_rateLimitContext && m_client)
43 layerTreeHost()->stopRateLimiter(m_client->context()); 57 layerTreeHost()->stopRateLimiter(m_client->context());
44 } 58 }
59 if (!m_contentCommitted && !m_mailboxName.empty())
60 m_mailboxReleaseCallback.Run(0);
45 } 61 }
46 62
47 scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeImpl* treeImpl) 63 scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeImpl* treeImpl)
48 { 64 {
49 return TextureLayerImpl::create(treeImpl, m_layerId).PassAs<LayerImpl>(); 65 return TextureLayerImpl::create(treeImpl, m_layerId, m_usesMailbox).PassAs<L ayerImpl>();
50 } 66 }
51 67
52 void TextureLayer::setFlipped(bool flipped) 68 void TextureLayer::setFlipped(bool flipped)
53 { 69 {
54 m_flipped = flipped; 70 m_flipped = flipped;
55 setNeedsCommit(); 71 setNeedsCommit();
56 } 72 }
57 73
58 void TextureLayer::setUVRect(const gfx::RectF& rect) 74 void TextureLayer::setUVRect(const gfx::RectF& rect)
59 { 75 {
(...skipping 25 matching lines...) Expand all
85 void TextureLayer::setRateLimitContext(bool rateLimit) 101 void TextureLayer::setRateLimitContext(bool rateLimit)
86 { 102 {
87 if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost()) 103 if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost())
88 layerTreeHost()->stopRateLimiter(m_client->context()); 104 layerTreeHost()->stopRateLimiter(m_client->context());
89 105
90 m_rateLimitContext = rateLimit; 106 m_rateLimitContext = rateLimit;
91 } 107 }
92 108
93 void TextureLayer::setTextureId(unsigned id) 109 void TextureLayer::setTextureId(unsigned id)
94 { 110 {
111 DCHECK(!m_usesMailbox);
95 if (m_textureId == id) 112 if (m_textureId == id)
96 return; 113 return;
97 if (m_textureId && layerTreeHost()) 114 if (m_textureId && layerTreeHost())
98 layerTreeHost()->acquireLayerTextures(); 115 layerTreeHost()->acquireLayerTextures();
99 m_textureId = id; 116 m_textureId = id;
100 setNeedsCommit(); 117 setNeedsCommit();
101 } 118 }
102 119
120 void TextureLayer::setTextureMailbox(const std::string& mailboxName, const base: :Callback<void(unsigned)>& callback)
121 {
122 DCHECK(m_usesMailbox);
123 DCHECK(mailboxName.empty() == callback.is_null());
124 if (m_mailboxName.compare(mailboxName) == 0)
125 return;
126 // If we never commited the mailbox, we need to release it here
127 if (!m_contentCommitted && !m_mailboxName.empty())
128 m_mailboxReleaseCallback.Run(0);
129 m_mailboxReleaseCallback = callback;
130 m_mailboxName = mailboxName;
131
132 setNeedsCommit();
133 }
134
103 void TextureLayer::willModifyTexture() 135 void TextureLayer::willModifyTexture()
104 { 136 {
105 if (layerTreeHost() && (drawsContent() || m_contentCommitted)) { 137 if (layerTreeHost() && (drawsContent() || m_contentCommitted)) {
106 layerTreeHost()->acquireLayerTextures(); 138 layerTreeHost()->acquireLayerTextures();
107 m_contentCommitted = false; 139 m_contentCommitted = false;
108 } 140 }
109 } 141 }
110 142
111 void TextureLayer::setNeedsDisplayRect(const gfx::RectF& dirtyRect) 143 void TextureLayer::setNeedsDisplayRect(const gfx::RectF& dirtyRect)
112 { 144 {
113 Layer::setNeedsDisplayRect(dirtyRect); 145 Layer::setNeedsDisplayRect(dirtyRect);
114 146
115 if (m_rateLimitContext && m_client && layerTreeHost() && drawsContent()) 147 if (m_rateLimitContext && m_client && layerTreeHost() && drawsContent())
116 layerTreeHost()->startRateLimiter(m_client->context()); 148 layerTreeHost()->startRateLimiter(m_client->context());
117 } 149 }
118 150
119 void TextureLayer::setLayerTreeHost(LayerTreeHost* host) 151 void TextureLayer::setLayerTreeHost(LayerTreeHost* host)
120 { 152 {
121 if (m_textureId && layerTreeHost() && host != layerTreeHost()) 153 if (m_textureId && layerTreeHost() && host != layerTreeHost())
122 layerTreeHost()->acquireLayerTextures(); 154 layerTreeHost()->acquireLayerTextures();
123 Layer::setLayerTreeHost(host); 155 Layer::setLayerTreeHost(host);
124 } 156 }
125 157
126 bool TextureLayer::drawsContent() const 158 bool TextureLayer::drawsContent() const
127 { 159 {
128 return (m_client || m_textureId) && !m_contextLost && Layer::drawsContent(); 160 return (m_client || m_textureId || !m_mailboxName.empty()) && !m_contextLost && Layer::drawsContent();
129 } 161 }
130 162
131 void TextureLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*, R enderingStats&) 163 void TextureLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker*, R enderingStats&)
132 { 164 {
133 if (m_client) { 165 if (m_client) {
134 m_textureId = m_client->prepareTexture(queue); 166 m_textureId = m_client->prepareTexture(queue);
135 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GL_N O_ERROR; 167 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GL_N O_ERROR;
136 } 168 }
137 169
138 m_needsDisplay = false; 170 m_needsDisplay = false;
139 } 171 }
140 172
141 void TextureLayer::pushPropertiesTo(LayerImpl* layer) 173 void TextureLayer::pushPropertiesTo(LayerImpl* layer)
142 { 174 {
143 Layer::pushPropertiesTo(layer); 175 Layer::pushPropertiesTo(layer);
144 176
145 TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer); 177 TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer);
146 textureLayer->setFlipped(m_flipped); 178 textureLayer->setFlipped(m_flipped);
147 textureLayer->setUVRect(m_uvRect); 179 textureLayer->setUVRect(m_uvRect);
148 textureLayer->setVertexOpacity(m_vertexOpacity); 180 textureLayer->setVertexOpacity(m_vertexOpacity);
149 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); 181 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha);
150 textureLayer->setTextureId(m_textureId); 182 if (m_usesMailbox) {
183 Thread* mainThread = layerTreeHost()->proxy()->mainThread();
184 textureLayer->setTextureMailbox(m_mailboxName, base::Bind(&runCallbackOn Main, mainThread, m_mailboxReleaseCallback));
185 } else {
186 textureLayer->setTextureId(m_textureId);
187 }
151 m_contentCommitted = drawsContent(); 188 m_contentCommitted = drawsContent();
152 } 189 }
153 190
154 bool TextureLayer::blocksPendingCommit() const 191 bool TextureLayer::blocksPendingCommit() const
155 { 192 {
156 // Double-buffered texture layers need to be blocked until they can be made 193 // Double-buffered texture layers need to be blocked until they can be made
157 // triple-buffered. Single-buffered layers already prevent draws, so 194 // triple-buffered. Single-buffered layers already prevent draws, so
158 // can block too for simplicity. 195 // can block too for simplicity.
159 return true; 196 return true;
160 } 197 }
161 198
162 } // namespace cc 199 } // namespace cc
OLDNEW
« no previous file with comments | « cc/texture_layer.h ('k') | cc/texture_layer_impl.h » ('j') | cc/texture_layer_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698