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

Side by Side Diff: content/common/gpu/texture_image_transport_surface.cc

Issue 10103021: aura/texture transport: Keep ref to texture infos to avoid races with the UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make clang happy Created 8 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/gpu/texture_image_transport_surface.h" 5 #include "content/common/gpu/texture_image_transport_surface.h"
6 6
7 #include "content/common/gpu/gpu_channel.h" 7 #include "content/common/gpu/gpu_channel.h"
8 #include "content/common/gpu/gpu_channel_manager.h" 8 #include "content/common/gpu/gpu_channel_manager.h"
9 #include "content/common/gpu/gpu_messages.h" 9 #include "content/common/gpu/gpu_messages.h"
10 #include "gpu/command_buffer/service/context_group.h" 10 #include "gpu/command_buffer/service/context_group.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 ~ScopedTextureBinder() { 43 ~ScopedTextureBinder() {
44 glBindTexture(GL_TEXTURE_2D, old_id_); 44 glBindTexture(GL_TEXTURE_2D, old_id_);
45 } 45 }
46 46
47 private: 47 private:
48 int old_id_; 48 int old_id_;
49 }; 49 };
50 50
51 } // anonymous namespace 51 } // anonymous namespace
52 52
53 TextureImageTransportSurface::Texture::Texture()
54 : client_id(0),
55 sent_to_client(false) {
56 }
57
58 TextureImageTransportSurface::Texture::~Texture() {
59 }
60
53 TextureImageTransportSurface::TextureImageTransportSurface( 61 TextureImageTransportSurface::TextureImageTransportSurface(
54 GpuChannelManager* manager, 62 GpuChannelManager* manager,
55 GpuCommandBufferStub* stub, 63 GpuCommandBufferStub* stub,
56 const gfx::GLSurfaceHandle& handle) 64 const gfx::GLSurfaceHandle& handle)
57 : fbo_id_(0), 65 : fbo_id_(0),
58 front_(0), 66 front_(0),
59 stub_destroyed_(false) { 67 stub_destroyed_(false),
68 parent_stub_(NULL) {
60 GpuChannel* parent_channel = manager->LookupChannel(handle.parent_client_id); 69 GpuChannel* parent_channel = manager->LookupChannel(handle.parent_client_id);
61 DCHECK(parent_channel); 70 DCHECK(parent_channel);
62 GpuCommandBufferStub* parent_stub = parent_channel->LookupCommandBuffer( 71 parent_stub_ = parent_channel->LookupCommandBuffer(handle.parent_context_id);
63 handle.parent_context_id); 72 DCHECK(parent_stub_);
64 DCHECK(parent_stub); 73 parent_stub_->AddDestructionObserver(this);
65 parent_stub_ = parent_stub->AsWeakPtr();
66 TextureManager* texture_manager = 74 TextureManager* texture_manager =
67 parent_stub_->decoder()->GetContextGroup()->texture_manager(); 75 parent_stub_->decoder()->GetContextGroup()->texture_manager();
68 DCHECK(texture_manager); 76 DCHECK(texture_manager);
69 77
70 for (int i = 0; i < 2; ++i) { 78 for (int i = 0; i < 2; ++i) {
71 Texture& texture = textures_[i]; 79 Texture& texture = textures_[i];
72 texture.client_id = handle.parent_texture_id[i]; 80 texture.client_id = handle.parent_texture_id[i];
73 TextureInfo* info = texture_manager->GetTextureInfo(texture.client_id); 81 texture.info = texture_manager->GetTextureInfo(texture.client_id);
74 DCHECK(info); 82 DCHECK(texture.info);
75 if (!info->target()) 83 if (!texture.info->target())
76 texture_manager->SetInfoTarget(info, GL_TEXTURE_2D); 84 texture_manager->SetInfoTarget(texture.info, GL_TEXTURE_2D);
77 texture_manager->SetParameter(info, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 85 texture_manager->SetParameter(
78 texture_manager->SetParameter(info, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 86 texture.info, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
79 texture_manager->SetParameter(info, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 87 texture_manager->SetParameter(
80 texture_manager->SetParameter(info, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 88 texture.info, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
89 texture_manager->SetParameter(
90 texture.info, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
91 texture_manager->SetParameter(
92 texture.info, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
81 } 93 }
82 94
83 helper_.reset(new ImageTransportHelper(this, 95 helper_.reset(new ImageTransportHelper(this,
84 manager, 96 manager,
85 stub, 97 stub,
86 gfx::kNullPluginWindow)); 98 gfx::kNullPluginWindow));
87 99
88 stub->AddDestructionObserver(this); 100 stub->AddDestructionObserver(this);
89 } 101 }
90 102
91 TextureImageTransportSurface::~TextureImageTransportSurface() { 103 TextureImageTransportSurface::~TextureImageTransportSurface() {
92 DCHECK(stub_destroyed_); 104 DCHECK(stub_destroyed_);
93 Destroy(); 105 Destroy();
94 } 106 }
95 107
96 bool TextureImageTransportSurface::Initialize() { 108 bool TextureImageTransportSurface::Initialize() {
97 return helper_->Initialize(); 109 return helper_->Initialize();
98 } 110 }
99 111
100 void TextureImageTransportSurface::Destroy() { 112 void TextureImageTransportSurface::Destroy() {
113 if (parent_stub_) {
114 parent_stub_->RemoveDestructionObserver(this);
115 parent_stub_ = NULL;
116 }
101 for (int i = 0; i < 2; ++i) { 117 for (int i = 0; i < 2; ++i) {
102 Texture& texture = textures_[i]; 118 Texture& texture = textures_[i];
103 if (!texture.sent_to_client) 119 if (!texture.sent_to_client)
104 continue; 120 continue;
105 GpuHostMsg_AcceleratedSurfaceRelease_Params params; 121 GpuHostMsg_AcceleratedSurfaceRelease_Params params;
106 params.identifier = texture.client_id; 122 params.identifier = texture.client_id;
107 helper_->SendAcceleratedSurfaceRelease(params); 123 helper_->SendAcceleratedSurfaceRelease(params);
124 texture.info = NULL;
108 } 125 }
109 126
110 helper_->Destroy(); 127 helper_->Destroy();
111 } 128 }
112 129
113 bool TextureImageTransportSurface::Resize(const gfx::Size&) { 130 bool TextureImageTransportSurface::Resize(const gfx::Size&) {
114 return true; 131 return true;
115 } 132 }
116 133
117 bool TextureImageTransportSurface::IsOffscreen() { 134 bool TextureImageTransportSurface::IsOffscreen() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ReleaseBackTexture(); 177 ReleaseBackTexture();
161 break; 178 break;
162 }; 179 };
163 } 180 }
164 181
165 void* TextureImageTransportSurface::GetShareHandle() { 182 void* TextureImageTransportSurface::GetShareHandle() {
166 return GetHandle(); 183 return GetHandle();
167 } 184 }
168 185
169 void* TextureImageTransportSurface::GetDisplay() { 186 void* TextureImageTransportSurface::GetDisplay() {
170 return parent_stub_.get() ? parent_stub_->surface()->GetDisplay() : NULL; 187 return parent_stub_ ? parent_stub_->surface()->GetDisplay() : NULL;
171 } 188 }
172 189
173 void* TextureImageTransportSurface::GetConfig() { 190 void* TextureImageTransportSurface::GetConfig() {
174 return parent_stub_.get() ? parent_stub_->surface()->GetConfig() : NULL; 191 return parent_stub_ ? parent_stub_->surface()->GetConfig() : NULL;
175 } 192 }
176 193
177 void TextureImageTransportSurface::OnResize(gfx::Size size) { 194 void TextureImageTransportSurface::OnResize(gfx::Size size) {
178 CreateBackTexture(size); 195 CreateBackTexture(size);
179 } 196 }
180 197
181 void TextureImageTransportSurface::OnWillDestroyStub( 198 void TextureImageTransportSurface::OnWillDestroyStub(
182 GpuCommandBufferStub* stub) { 199 GpuCommandBufferStub* stub) {
183 glDeleteFramebuffersEXT(1, &fbo_id_); 200 stub->RemoveDestructionObserver(this);
184 CHECK_GL_ERROR(); 201 if (stub == parent_stub_) {
185 fbo_id_ = 0; 202 // We are losing the parent stub, we need to clear the reference on the
203 // infos (they are not allowed to outlive the stub).
204 textures_[0].info = NULL;
205 textures_[1].info = NULL;
jonathan.backer 2012/04/17 17:21:50 parent_stub_ = NULL so that we don't access a stal
piman 2012/04/17 17:37:24 Done.
206 } else {
207 // We are losing the stub owning us, this is our last chance to clean up the
208 // resources we allocated in the stub's context.
209 glDeleteFramebuffersEXT(1, &fbo_id_);
210 CHECK_GL_ERROR();
211 fbo_id_ = 0;
186 212
187 stub->RemoveDestructionObserver(this); 213 stub_destroyed_ = true;
188 stub_destroyed_ = true; 214 }
189 } 215 }
190 216
191 bool TextureImageTransportSurface::SwapBuffers() { 217 bool TextureImageTransportSurface::SwapBuffers() {
218 if (!parent_stub_) {
219 LOG(ERROR) << "SwapBuffers failed because no parent stub.";
220 return false;
221 }
222
192 glFlush(); 223 glFlush();
193 front_ = back(); 224 front_ = back();
194 previous_damage_rect_ = gfx::Rect(textures_[front_].size); 225 previous_damage_rect_ = gfx::Rect(textures_[front_].size);
195 226
196 DCHECK(textures_[front_].client_id != 0); 227 DCHECK(textures_[front_].client_id != 0);
197 228
198 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; 229 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
199 params.surface_handle = textures_[front_].client_id; 230 params.surface_handle = textures_[front_].client_id;
200 helper_->SendAcceleratedSurfaceBuffersSwapped(params); 231 helper_->SendAcceleratedSurfaceBuffersSwapped(params);
201 helper_->SetScheduled(false); 232 helper_->SetScheduled(false);
202 return true; 233 return true;
203 } 234 }
204 235
205 bool TextureImageTransportSurface::PostSubBuffer( 236 bool TextureImageTransportSurface::PostSubBuffer(
206 int x, int y, int width, int height) { 237 int x, int y, int width, int height) {
207 if (!parent_stub_.get()) 238 if (!parent_stub_) {
239 LOG(ERROR) << "PostSubBuffer failed because no parent stub.";
208 return false; 240 return false;
241 }
209 242
210 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 243 DCHECK(textures_[back()].info);
211 if (!info) 244 int back_texture_service_id = textures_[back()].info->service_id();
212 return false;
213 int back_texture_service_id = info->service_id();
214 245
215 info = GetParentInfo(textures_[front_].client_id); 246 DCHECK(textures_[front_].info);
216 if (!info) 247 int front_texture_service_id = textures_[front_].info->service_id();
217 return false;
218 int front_texture_service_id = info->service_id();
219 248
220 gfx::Size expected_size = textures_[back()].size; 249 gfx::Size expected_size = textures_[back()].size;
221 bool surfaces_same_size = textures_[front_].size == expected_size; 250 bool surfaces_same_size = textures_[front_].size == expected_size;
222 251
223 const gfx::Rect new_damage_rect(x, y, width, height); 252 const gfx::Rect new_damage_rect(x, y, width, height);
224 253
225 // An empty damage rect is a successful no-op. 254 // An empty damage rect is a successful no-op.
226 if (new_damage_rect.IsEmpty()) 255 if (new_damage_rect.IsEmpty())
227 return true; 256 return true;
228 257
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 extensions += "GL_CHROMIUM_front_buffer_cached "; 301 extensions += "GL_CHROMIUM_front_buffer_cached ";
273 extensions += "GL_CHROMIUM_post_sub_buffer"; 302 extensions += "GL_CHROMIUM_post_sub_buffer";
274 return extensions; 303 return extensions;
275 } 304 }
276 305
277 gfx::Size TextureImageTransportSurface::GetSize() { 306 gfx::Size TextureImageTransportSurface::GetSize() {
278 return textures_[back()].size; 307 return textures_[back()].size;
279 } 308 }
280 309
281 void* TextureImageTransportSurface::GetHandle() { 310 void* TextureImageTransportSurface::GetHandle() {
282 return parent_stub_.get() ? parent_stub_->surface()->GetHandle() : NULL; 311 return parent_stub_ ? parent_stub_->surface()->GetHandle() : NULL;
283 } 312 }
284 313
285 314
286 void TextureImageTransportSurface::OnNewSurfaceACK( 315 void TextureImageTransportSurface::OnNewSurfaceACK(
287 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { 316 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) {
288 } 317 }
289 318
290 void TextureImageTransportSurface::OnBuffersSwappedACK() { 319 void TextureImageTransportSurface::OnBuffersSwappedACK() {
291 if (helper_->MakeCurrent()) { 320 if (helper_->MakeCurrent()) {
292 if (textures_[front_].size != textures_[back()].size) { 321 if (textures_[front_].size != textures_[back()].size) {
(...skipping 10 matching lines...) Expand all
303 332
304 void TextureImageTransportSurface::OnPostSubBufferACK() { 333 void TextureImageTransportSurface::OnPostSubBufferACK() {
305 OnBuffersSwappedACK(); 334 OnBuffersSwappedACK();
306 } 335 }
307 336
308 void TextureImageTransportSurface::OnResizeViewACK() { 337 void TextureImageTransportSurface::OnResizeViewACK() {
309 NOTREACHED(); 338 NOTREACHED();
310 } 339 }
311 340
312 void TextureImageTransportSurface::ReleaseBackTexture() { 341 void TextureImageTransportSurface::ReleaseBackTexture() {
313 if (!parent_stub_.get()) 342 if (!parent_stub_)
314 return; 343 return;
315 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 344 TextureInfo* info = textures_[back()].info;
316 if (!info) 345 DCHECK(info);
317 return;
318 346
319 GLuint service_id = info->service_id(); 347 GLuint service_id = info->service_id();
320 if (!service_id) 348 if (!service_id)
321 return; 349 return;
322 info->SetServiceId(0); 350 info->SetServiceId(0);
323 351
324 { 352 {
325 ScopedFrameBufferBinder fbo_binder(fbo_id_); 353 ScopedFrameBufferBinder fbo_binder(fbo_id_);
326 glDeleteTextures(1, &service_id); 354 glDeleteTextures(1, &service_id);
327 } 355 }
328 glFlush(); 356 glFlush();
329 CHECK_GL_ERROR(); 357 CHECK_GL_ERROR();
330 } 358 }
331 359
332 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { 360 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) {
333 if (!parent_stub_.get()) 361 if (!parent_stub_)
334 return; 362 return;
335 Texture& texture = textures_[back()]; 363 Texture& texture = textures_[back()];
336 TextureInfo* info = GetParentInfo(texture.client_id); 364 TextureInfo* info = texture.info;
337 if (!info) 365 DCHECK(info);
338 return;
339 366
340 GLuint service_id = info->service_id(); 367 GLuint service_id = info->service_id();
341 368
342 if (service_id && texture.size == size) 369 if (service_id && texture.size == size)
343 return; 370 return;
344 371
345 if (!service_id) { 372 if (!service_id) {
346 glGenTextures(1, &service_id); 373 glGenTextures(1, &service_id);
347 info->SetServiceId(service_id); 374 info->SetServiceId(service_id);
348 } 375 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 408
382 GpuHostMsg_AcceleratedSurfaceNew_Params params; 409 GpuHostMsg_AcceleratedSurfaceNew_Params params;
383 params.width = size.width(); 410 params.width = size.width();
384 params.height = size.height(); 411 params.height = size.height();
385 params.surface_handle = texture.client_id; 412 params.surface_handle = texture.client_id;
386 helper_->SendAcceleratedSurfaceNew(params); 413 helper_->SendAcceleratedSurfaceNew(params);
387 texture.sent_to_client = true; 414 texture.sent_to_client = true;
388 } 415 }
389 416
390 void TextureImageTransportSurface::AttachBackTextureToFBO() { 417 void TextureImageTransportSurface::AttachBackTextureToFBO() {
391 if (!parent_stub_.get()) 418 if (!parent_stub_)
392 return; 419 return;
393 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 420 DCHECK(textures_[back()].info);
394 if (!info)
395 return;
396 421
397 ScopedFrameBufferBinder fbo_binder(fbo_id_); 422 ScopedFrameBufferBinder fbo_binder(fbo_id_);
398 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, 423 glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
399 GL_COLOR_ATTACHMENT0, 424 GL_COLOR_ATTACHMENT0,
400 GL_TEXTURE_2D, 425 GL_TEXTURE_2D,
401 info->service_id(), 426 textures_[back()].info->service_id(),
402 0); 427 0);
403 glFlush(); 428 glFlush();
404 CHECK_GL_ERROR(); 429 CHECK_GL_ERROR();
405 430
406 #ifndef NDEBUG 431 #ifndef NDEBUG
407 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 432 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
408 if (status != GL_FRAMEBUFFER_COMPLETE) { 433 if (status != GL_FRAMEBUFFER_COMPLETE) {
409 DLOG(ERROR) << "Framebuffer incomplete."; 434 DLOG(ERROR) << "Framebuffer incomplete.";
410 } 435 }
411 #endif 436 #endif
412 } 437 }
413
414 TextureInfo* TextureImageTransportSurface::GetParentInfo(uint32 client_id) {
415 DCHECK(parent_stub_.get());
416 TextureManager* texture_manager =
417 parent_stub_->decoder()->GetContextGroup()->texture_manager();
418 TextureInfo* info = texture_manager->GetTextureInfo(client_id);
419 return info;
420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698