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

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: Removed SharedMemory::DuplicateHandle. 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/public/platform/WebGraphicsContext3D.h" 11 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.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()) {
28 callback, 30 thread->PostTask(base::Bind(&RunCallback, callback,
29 sync_point, 31 sync_point, lost_resource));
30 lost_resource)); 32 }
31 } 33 }
32 34
35 } // namespace
36
33 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) { 37 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) {
34 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); 38 return scoped_refptr<TextureLayer>(new TextureLayer(client, false));
35 } 39 }
36 40
37 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox( 41 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox(
38 TextureLayerClient* client) { 42 TextureLayerClient* client) {
39 return scoped_refptr<TextureLayer>(new TextureLayer(client, true)); 43 return scoped_refptr<TextureLayer>(new TextureLayer(client, true));
40 } 44 }
41 45
42 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) 46 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (texture_id_ == id) 140 if (texture_id_ == id)
137 return; 141 return;
138 if (texture_id_ && layer_tree_host()) 142 if (texture_id_ && layer_tree_host())
139 layer_tree_host()->AcquireLayerTextures(); 143 layer_tree_host()->AcquireLayerTextures();
140 texture_id_ = id; 144 texture_id_ = id;
141 SetNeedsCommit(); 145 SetNeedsCommit();
142 } 146 }
143 147
144 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { 148 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) {
145 DCHECK(uses_mailbox_); 149 DCHECK(uses_mailbox_);
146 DCHECK(mailbox.IsEmpty() || !mailbox.Equals(texture_mailbox_)); 150 DCHECK(!mailbox.IsValid() ||
151 mailbox.IsSharedMemory() ||
piman 2013/06/07 01:26:28 In which case do you need to call SetTextureMailbo
slavi 2013/06/07 21:49:21 This check was failing after tab detach/reattach.
piman 2013/06/07 23:29:59 What this means is that detaching/reattaching a ta
152 !mailbox.ContainsMailbox(texture_mailbox_.name()));
147 // If we never commited the mailbox, we need to release it here 153 // If we never commited the mailbox, we need to release it here
148 if (own_mailbox_) 154 if (own_mailbox_)
149 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false); 155 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false);
150 texture_mailbox_ = mailbox; 156 texture_mailbox_ = mailbox;
151 own_mailbox_ = true; 157 own_mailbox_ = true;
152
153 SetNeedsCommit(); 158 SetNeedsCommit();
154 } 159 }
155 160
156 void TextureLayer::WillModifyTexture() { 161 void TextureLayer::WillModifyTexture() {
157 if (layer_tree_host() && (DrawsContent() || content_committed_)) { 162 if (layer_tree_host() && (DrawsContent() || content_committed_)) {
158 layer_tree_host()->AcquireLayerTextures(); 163 layer_tree_host()->AcquireLayerTextures();
159 content_committed_ = false; 164 content_committed_ = false;
160 } 165 }
161 } 166 }
162 167
163 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { 168 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) {
164 Layer::SetNeedsDisplayRect(dirty_rect); 169 Layer::SetNeedsDisplayRect(dirty_rect);
165 170
166 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) 171 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent())
167 layer_tree_host()->StartRateLimiter(client_->Context3d()); 172 layer_tree_host()->StartRateLimiter(client_->Context3d());
168 } 173 }
169 174
170 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { 175 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) {
171 if (texture_id_ && layer_tree_host() && host != layer_tree_host()) 176 if (texture_id_ && layer_tree_host() && host != layer_tree_host())
172 layer_tree_host()->AcquireLayerTextures(); 177 layer_tree_host()->AcquireLayerTextures();
173 Layer::SetLayerTreeHost(host); 178 Layer::SetLayerTreeHost(host);
174 } 179 }
175 180
176 bool TextureLayer::DrawsContent() const { 181 bool TextureLayer::DrawsContent() const {
177 return (client_ || texture_id_ || !texture_mailbox_.IsEmpty()) && 182 return (client_ || texture_id_ || texture_mailbox_.IsValid()) &&
178 !context_lost_ && Layer::DrawsContent(); 183 !context_lost_ && Layer::DrawsContent();
179 } 184 }
180 185
181 void TextureLayer::Update(ResourceUpdateQueue* queue, 186 void TextureLayer::Update(ResourceUpdateQueue* queue,
182 const OcclusionTracker* occlusion, 187 const OcclusionTracker* occlusion,
183 RenderingStats* stats) { 188 RenderingStats* stats) {
184 if (client_) { 189 if (client_) {
185 if (uses_mailbox_) { 190 if (uses_mailbox_) {
186 TextureMailbox mailbox; 191 TextureMailbox mailbox;
187 if (client_->PrepareTextureMailbox(&mailbox)) 192 if (client_->PrepareTextureMailbox(&mailbox)) {
193 if (mailbox.IsTexture())
194 DCHECK(client_->Context3d());
188 SetTextureMailbox(mailbox); 195 SetTextureMailbox(mailbox);
196 }
189 } else { 197 } else {
198 DCHECK(client_->Context3d());
190 texture_id_ = client_->PrepareTexture(queue); 199 texture_id_ = client_->PrepareTexture(queue);
191 } 200 }
192 context_lost_ = 201 context_lost_ = client_->Context3d() &&
193 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR; 202 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR;
194 } 203 }
195 204
196 needs_display_ = false; 205 needs_display_ = false;
197 } 206 }
198 207
199 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { 208 void TextureLayer::PushPropertiesTo(LayerImpl* layer) {
200 Layer::PushPropertiesTo(layer); 209 Layer::PushPropertiesTo(layer);
201 210
202 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); 211 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer);
203 texture_layer->set_flipped(flipped_); 212 texture_layer->set_flipped(flipped_);
204 texture_layer->set_uv_top_left(uv_top_left_); 213 texture_layer->set_uv_top_left(uv_top_left_);
205 texture_layer->set_uv_bottom_right(uv_bottom_right_); 214 texture_layer->set_uv_bottom_right(uv_bottom_right_);
206 texture_layer->set_vertex_opacity(vertex_opacity_); 215 texture_layer->set_vertex_opacity(vertex_opacity_);
207 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); 216 texture_layer->set_premultiplied_alpha(premultiplied_alpha_);
208 if (uses_mailbox_ && own_mailbox_) { 217 if (uses_mailbox_ && own_mailbox_) {
209 Thread* main_thread = layer_tree_host()->proxy()->MainThread(); 218 Thread* main_thread = layer_tree_host()->proxy()->MainThread();
210 TextureMailbox::ReleaseCallback callback; 219 TextureMailbox::ReleaseCallback callback = base::Bind(
211 if (!texture_mailbox_.IsEmpty()) 220 &PostCallbackToThread, main_thread, texture_mailbox_.callback());
212 callback = base::Bind( 221 texture_layer->SetTextureMailbox(
213 &PostCallbackToMainThread, main_thread, texture_mailbox_.callback()); 222 texture_mailbox_.CopyWithNewCallback(callback));
214 texture_layer->SetTextureMailbox(TextureMailbox(
215 texture_mailbox_.name(), callback, texture_mailbox_.sync_point()));
216 own_mailbox_ = false; 223 own_mailbox_ = false;
217 } else { 224 } else {
218 texture_layer->set_texture_id(texture_id_); 225 texture_layer->set_texture_id(texture_id_);
219 } 226 }
220 content_committed_ = DrawsContent(); 227 content_committed_ = DrawsContent();
221 } 228 }
222 229
223 bool TextureLayer::BlocksPendingCommit() const { 230 bool TextureLayer::BlocksPendingCommit() const {
224 // Double-buffered texture layers need to be blocked until they can be made 231 // Double-buffered texture layers need to be blocked until they can be made
225 // triple-buffered. Single-buffered layers already prevent draws, so 232 // triple-buffered. Single-buffered layers already prevent draws, so
226 // can block too for simplicity. 233 // can block too for simplicity.
227 return DrawsContent(); 234 return DrawsContent();
228 } 235 }
229 236
230 bool TextureLayer::CanClipSelf() const { 237 bool TextureLayer::CanClipSelf() const {
231 return true; 238 return true;
232 } 239 }
233 240
234 } // namespace cc 241 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698