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

Side by Side Diff: cc/layers/texture_layer.cc

Issue 15001027: [Aura] Added Support for rendering software compositor frames as cc::TextureLayers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/layers/texture_layer.h" 5 #include "cc/layers/texture_layer.h"
6 6
7 #include "cc/base/thread.h" 7 #include "cc/base/thread.h"
8 #include "cc/layers/texture_layer_client.h" 8 #include "cc/layers/texture_layer_client.h"
9 #include "cc/layers/texture_layer_impl.h" 9 #include "cc/layers/texture_layer_impl.h"
10 #include "cc/trees/layer_tree_host.h" 10 #include "cc/trees/layer_tree_host.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( 15 namespace {
16
17 void RunCallback(
16 const TextureMailbox::ReleaseCallback& callback, 18 const TextureMailbox::ReleaseCallback& callback,
17 unsigned sync_point, 19 unsigned sync_point,
18 bool lost_resource) { 20 bool lost_resource) {
19 callback.Run(sync_point, lost_resource); 21 callback.Run(sync_point, lost_resource);
20 } 22 }
21 23
22 static void PostCallbackToMainThread( 24 void PostCallbackToThread(
23 Thread* main_thread, 25 Thread* thread,
24 const TextureMailbox::ReleaseCallback& callback, 26 const TextureMailbox::ReleaseCallback& callback,
25 unsigned sync_point, 27 unsigned sync_point,
26 bool lost_resource) { 28 bool lost_resource) {
27 main_thread->PostTask(base::Bind(&RunCallbackOnMainThread, 29 if (!callback.is_null())
piman 2013/05/28 20:58:57 nit: braces needed. I'm not sure that this new for
slavi 2013/05/29 18:31:48 Done.
28 callback, 30 thread->PostTask(base::Bind(&RunCallback, callback,
29 sync_point, 31 sync_point, lost_resource));
30 lost_resource));
31 } 32 }
32 33
34 } // namespace
35
33 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) { 36 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) {
34 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); 37 return scoped_refptr<TextureLayer>(new TextureLayer(client, false));
35 } 38 }
36 39
37 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox( 40 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox(
38 TextureLayerClient* client) { 41 TextureLayerClient* client) {
39 return scoped_refptr<TextureLayer>(new TextureLayer(client, true)); 42 return scoped_refptr<TextureLayer>(new TextureLayer(client, true));
40 } 43 }
41 44
42 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) 45 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (texture_id_ == id) 139 if (texture_id_ == id)
137 return; 140 return;
138 if (texture_id_ && layer_tree_host()) 141 if (texture_id_ && layer_tree_host())
139 layer_tree_host()->AcquireLayerTextures(); 142 layer_tree_host()->AcquireLayerTextures();
140 texture_id_ = id; 143 texture_id_ = id;
141 SetNeedsCommit(); 144 SetNeedsCommit();
142 } 145 }
143 146
144 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { 147 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) {
145 DCHECK(uses_mailbox_); 148 DCHECK(uses_mailbox_);
146 DCHECK(mailbox.IsEmpty() || !mailbox.Equals(texture_mailbox_)); 149 DCHECK(!mailbox.IsValid() || !mailbox.Equals(texture_mailbox_));
147 // If we never commited the mailbox, we need to release it here 150 // If we never commited the mailbox, we need to release it here
148 if (own_mailbox_) 151 if (own_mailbox_)
149 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false); 152 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false);
150 texture_mailbox_ = mailbox; 153 texture_mailbox_ = mailbox;
151 own_mailbox_ = true; 154 own_mailbox_ = true;
152
153 SetNeedsCommit(); 155 SetNeedsCommit();
154 } 156 }
155 157
156 void TextureLayer::WillModifyTexture() { 158 void TextureLayer::WillModifyTexture() {
157 if (layer_tree_host() && (DrawsContent() || content_committed_)) { 159 if (layer_tree_host() && (DrawsContent() || content_committed_)) {
158 layer_tree_host()->AcquireLayerTextures(); 160 layer_tree_host()->AcquireLayerTextures();
159 content_committed_ = false; 161 content_committed_ = false;
160 } 162 }
161 } 163 }
162 164
163 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { 165 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) {
164 Layer::SetNeedsDisplayRect(dirty_rect); 166 Layer::SetNeedsDisplayRect(dirty_rect);
165 167
166 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) 168 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent())
167 layer_tree_host()->StartRateLimiter(client_->Context3d()); 169 layer_tree_host()->StartRateLimiter(client_->Context3d());
168 } 170 }
169 171
170 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { 172 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) {
171 if (texture_id_ && layer_tree_host() && host != layer_tree_host()) 173 if (texture_id_ && layer_tree_host() && host != layer_tree_host())
172 layer_tree_host()->AcquireLayerTextures(); 174 layer_tree_host()->AcquireLayerTextures();
173 Layer::SetLayerTreeHost(host); 175 Layer::SetLayerTreeHost(host);
174 } 176 }
175 177
176 bool TextureLayer::DrawsContent() const { 178 bool TextureLayer::DrawsContent() const {
177 return (client_ || texture_id_ || !texture_mailbox_.IsEmpty()) && 179 return (client_ || texture_id_ || texture_mailbox_.IsValid()) &&
178 !context_lost_ && Layer::DrawsContent(); 180 !context_lost_ && Layer::DrawsContent();
179 } 181 }
180 182
181 void TextureLayer::Update(ResourceUpdateQueue* queue, 183 void TextureLayer::Update(ResourceUpdateQueue* queue,
182 const OcclusionTracker* occlusion, 184 const OcclusionTracker* occlusion,
183 RenderingStats* stats) { 185 RenderingStats* stats) {
184 if (client_) { 186 if (client_) {
185 if (uses_mailbox_) { 187 if (uses_mailbox_) {
186 TextureMailbox mailbox; 188 TextureMailbox mailbox;
187 if (client_->PrepareTextureMailbox(&mailbox)) 189 if (client_->PrepareTextureMailbox(&mailbox)) {
190 if (mailbox.IsTexture())
191 DCHECK(client_->Context3d());
188 SetTextureMailbox(mailbox); 192 SetTextureMailbox(mailbox);
193 }
189 } else { 194 } else {
195 DCHECK(client_->Context3d());
190 texture_id_ = client_->PrepareTexture(queue); 196 texture_id_ = client_->PrepareTexture(queue);
191 } 197 }
192 context_lost_ = 198 context_lost_ = client_->Context3d() &&
193 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR; 199 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR;
194 } 200 }
195 201
196 needs_display_ = false; 202 needs_display_ = false;
197 } 203 }
198 204
199 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { 205 void TextureLayer::PushPropertiesTo(LayerImpl* layer) {
200 Layer::PushPropertiesTo(layer); 206 Layer::PushPropertiesTo(layer);
201 207
202 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); 208 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer);
203 texture_layer->set_flipped(flipped_); 209 texture_layer->set_flipped(flipped_);
204 texture_layer->set_uv_top_left(uv_top_left_); 210 texture_layer->set_uv_top_left(uv_top_left_);
205 texture_layer->set_uv_bottom_right(uv_bottom_right_); 211 texture_layer->set_uv_bottom_right(uv_bottom_right_);
206 texture_layer->set_vertex_opacity(vertex_opacity_); 212 texture_layer->set_vertex_opacity(vertex_opacity_);
207 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); 213 texture_layer->set_premultiplied_alpha(premultiplied_alpha_);
208 if (uses_mailbox_ && own_mailbox_) { 214 if (uses_mailbox_ && own_mailbox_) {
209 Thread* main_thread = layer_tree_host()->proxy()->MainThread(); 215 Thread* main_thread = layer_tree_host()->proxy()->MainThread();
210 TextureMailbox::ReleaseCallback callback; 216 TextureMailbox::ReleaseCallback callback = base::Bind(
211 if (!texture_mailbox_.IsEmpty()) 217 &PostCallbackToThread, main_thread, texture_mailbox_.callback());
212 callback = base::Bind( 218 if (texture_mailbox_.IsTexture()) {
213 &PostCallbackToMainThread, main_thread, texture_mailbox_.callback()); 219 texture_layer->SetTextureMailbox(TextureMailbox(
214 texture_layer->SetTextureMailbox(TextureMailbox( 220 texture_mailbox_.name(), callback, texture_mailbox_.sync_point()));
215 texture_mailbox_.name(), callback, texture_mailbox_.sync_point())); 221 } else if (texture_mailbox_.IsSharedMemory()) {
222 texture_layer->SetTextureMailbox(TextureMailbox(
223 texture_mailbox_.handle(), texture_mailbox_.size(), callback));
224 } else {
225 DCHECK(!texture_mailbox_.IsValid());
226 texture_layer->SetTextureMailbox(TextureMailbox());
227 }
piman 2013/05/28 20:58:57 It seems that this whole block could be simplified
slavi 2013/05/29 18:31:48 Done.
216 own_mailbox_ = false; 228 own_mailbox_ = false;
217 } else { 229 } else {
218 texture_layer->set_texture_id(texture_id_); 230 texture_layer->set_texture_id(texture_id_);
219 } 231 }
220 content_committed_ = DrawsContent(); 232 content_committed_ = DrawsContent();
221 } 233 }
222 234
223 bool TextureLayer::BlocksPendingCommit() const { 235 bool TextureLayer::BlocksPendingCommit() const {
224 // Double-buffered texture layers need to be blocked until they can be made 236 // Double-buffered texture layers need to be blocked until they can be made
225 // triple-buffered. Single-buffered layers already prevent draws, so 237 // triple-buffered. Single-buffered layers already prevent draws, so
226 // can block too for simplicity. 238 // can block too for simplicity.
227 return DrawsContent(); 239 return DrawsContent();
228 } 240 }
229 241
230 bool TextureLayer::CanClipSelf() const { 242 bool TextureLayer::CanClipSelf() const {
231 return true; 243 return true;
232 } 244 }
233 245
234 } // namespace cc 246 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698