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

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: address review comments 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;
206 parent_stub_ = NULL;
207 } else {
208 // We are losing the stub owning us, this is our last chance to clean up the
209 // resources we allocated in the stub's context.
210 glDeleteFramebuffersEXT(1, &fbo_id_);
211 CHECK_GL_ERROR();
212 fbo_id_ = 0;
186 213
187 stub->RemoveDestructionObserver(this); 214 stub_destroyed_ = true;
188 stub_destroyed_ = true; 215 }
189 } 216 }
190 217
191 bool TextureImageTransportSurface::SwapBuffers() { 218 bool TextureImageTransportSurface::SwapBuffers() {
219 if (!parent_stub_) {
220 LOG(ERROR) << "SwapBuffers failed because no parent stub.";
221 return false;
222 }
223
192 glFlush(); 224 glFlush();
193 front_ = back(); 225 front_ = back();
194 previous_damage_rect_ = gfx::Rect(textures_[front_].size); 226 previous_damage_rect_ = gfx::Rect(textures_[front_].size);
195 227
196 DCHECK(textures_[front_].client_id != 0); 228 DCHECK(textures_[front_].client_id != 0);
197 229
198 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; 230 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
199 params.surface_handle = textures_[front_].client_id; 231 params.surface_handle = textures_[front_].client_id;
200 helper_->SendAcceleratedSurfaceBuffersSwapped(params); 232 helper_->SendAcceleratedSurfaceBuffersSwapped(params);
201 helper_->SetScheduled(false); 233 helper_->SetScheduled(false);
202 return true; 234 return true;
203 } 235 }
204 236
205 bool TextureImageTransportSurface::PostSubBuffer( 237 bool TextureImageTransportSurface::PostSubBuffer(
206 int x, int y, int width, int height) { 238 int x, int y, int width, int height) {
207 if (!parent_stub_.get()) 239 if (!parent_stub_) {
240 LOG(ERROR) << "PostSubBuffer failed because no parent stub.";
208 return false; 241 return false;
242 }
209 243
210 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 244 DCHECK(textures_[back()].info);
211 if (!info) 245 int back_texture_service_id = textures_[back()].info->service_id();
212 return false;
213 int back_texture_service_id = info->service_id();
214 246
215 info = GetParentInfo(textures_[front_].client_id); 247 DCHECK(textures_[front_].info);
216 if (!info) 248 int front_texture_service_id = textures_[front_].info->service_id();
217 return false;
218 int front_texture_service_id = info->service_id();
219 249
220 gfx::Size expected_size = textures_[back()].size; 250 gfx::Size expected_size = textures_[back()].size;
221 bool surfaces_same_size = textures_[front_].size == expected_size; 251 bool surfaces_same_size = textures_[front_].size == expected_size;
222 252
223 const gfx::Rect new_damage_rect(x, y, width, height); 253 const gfx::Rect new_damage_rect(x, y, width, height);
224 254
225 // An empty damage rect is a successful no-op. 255 // An empty damage rect is a successful no-op.
226 if (new_damage_rect.IsEmpty()) 256 if (new_damage_rect.IsEmpty())
227 return true; 257 return true;
228 258
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 extensions += "GL_CHROMIUM_front_buffer_cached "; 302 extensions += "GL_CHROMIUM_front_buffer_cached ";
273 extensions += "GL_CHROMIUM_post_sub_buffer"; 303 extensions += "GL_CHROMIUM_post_sub_buffer";
274 return extensions; 304 return extensions;
275 } 305 }
276 306
277 gfx::Size TextureImageTransportSurface::GetSize() { 307 gfx::Size TextureImageTransportSurface::GetSize() {
278 return textures_[back()].size; 308 return textures_[back()].size;
279 } 309 }
280 310
281 void* TextureImageTransportSurface::GetHandle() { 311 void* TextureImageTransportSurface::GetHandle() {
282 return parent_stub_.get() ? parent_stub_->surface()->GetHandle() : NULL; 312 return parent_stub_ ? parent_stub_->surface()->GetHandle() : NULL;
283 } 313 }
284 314
285 315
286 void TextureImageTransportSurface::OnNewSurfaceACK( 316 void TextureImageTransportSurface::OnNewSurfaceACK(
287 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { 317 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) {
288 } 318 }
289 319
290 void TextureImageTransportSurface::OnBuffersSwappedACK() { 320 void TextureImageTransportSurface::OnBuffersSwappedACK() {
291 if (helper_->MakeCurrent()) { 321 if (helper_->MakeCurrent()) {
292 if (textures_[front_].size != textures_[back()].size) { 322 if (textures_[front_].size != textures_[back()].size) {
(...skipping 10 matching lines...) Expand all
303 333
304 void TextureImageTransportSurface::OnPostSubBufferACK() { 334 void TextureImageTransportSurface::OnPostSubBufferACK() {
305 OnBuffersSwappedACK(); 335 OnBuffersSwappedACK();
306 } 336 }
307 337
308 void TextureImageTransportSurface::OnResizeViewACK() { 338 void TextureImageTransportSurface::OnResizeViewACK() {
309 NOTREACHED(); 339 NOTREACHED();
310 } 340 }
311 341
312 void TextureImageTransportSurface::ReleaseBackTexture() { 342 void TextureImageTransportSurface::ReleaseBackTexture() {
313 if (!parent_stub_.get()) 343 if (!parent_stub_)
314 return; 344 return;
315 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 345 TextureInfo* info = textures_[back()].info;
316 if (!info) 346 DCHECK(info);
317 return;
318 347
319 GLuint service_id = info->service_id(); 348 GLuint service_id = info->service_id();
320 if (!service_id) 349 if (!service_id)
321 return; 350 return;
322 info->SetServiceId(0); 351 info->SetServiceId(0);
323 352
324 { 353 {
325 ScopedFrameBufferBinder fbo_binder(fbo_id_); 354 ScopedFrameBufferBinder fbo_binder(fbo_id_);
326 glDeleteTextures(1, &service_id); 355 glDeleteTextures(1, &service_id);
327 } 356 }
328 glFlush(); 357 glFlush();
329 CHECK_GL_ERROR(); 358 CHECK_GL_ERROR();
330 } 359 }
331 360
332 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { 361 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) {
333 if (!parent_stub_.get()) 362 if (!parent_stub_)
334 return; 363 return;
335 Texture& texture = textures_[back()]; 364 Texture& texture = textures_[back()];
336 TextureInfo* info = GetParentInfo(texture.client_id); 365 TextureInfo* info = texture.info;
337 if (!info) 366 DCHECK(info);
338 return;
339 367
340 GLuint service_id = info->service_id(); 368 GLuint service_id = info->service_id();
341 369
342 if (service_id && texture.size == size) 370 if (service_id && texture.size == size)
343 return; 371 return;
344 372
345 if (!service_id) { 373 if (!service_id) {
346 glGenTextures(1, &service_id); 374 glGenTextures(1, &service_id);
347 info->SetServiceId(service_id); 375 info->SetServiceId(service_id);
348 } 376 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 409
382 GpuHostMsg_AcceleratedSurfaceNew_Params params; 410 GpuHostMsg_AcceleratedSurfaceNew_Params params;
383 params.width = size.width(); 411 params.width = size.width();
384 params.height = size.height(); 412 params.height = size.height();
385 params.surface_handle = texture.client_id; 413 params.surface_handle = texture.client_id;
386 helper_->SendAcceleratedSurfaceNew(params); 414 helper_->SendAcceleratedSurfaceNew(params);
387 texture.sent_to_client = true; 415 texture.sent_to_client = true;
388 } 416 }
389 417
390 void TextureImageTransportSurface::AttachBackTextureToFBO() { 418 void TextureImageTransportSurface::AttachBackTextureToFBO() {
391 if (!parent_stub_.get()) 419 if (!parent_stub_)
392 return; 420 return;
393 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 421 DCHECK(textures_[back()].info);
394 if (!info)
395 return;
396 422
397 ScopedFrameBufferBinder fbo_binder(fbo_id_); 423 ScopedFrameBufferBinder fbo_binder(fbo_id_);
398 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, 424 glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
399 GL_COLOR_ATTACHMENT0, 425 GL_COLOR_ATTACHMENT0,
400 GL_TEXTURE_2D, 426 GL_TEXTURE_2D,
401 info->service_id(), 427 textures_[back()].info->service_id(),
402 0); 428 0);
403 glFlush(); 429 glFlush();
404 CHECK_GL_ERROR(); 430 CHECK_GL_ERROR();
405 431
406 #ifndef NDEBUG 432 #ifndef NDEBUG
407 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 433 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
408 if (status != GL_FRAMEBUFFER_COMPLETE) { 434 if (status != GL_FRAMEBUFFER_COMPLETE) {
409 DLOG(ERROR) << "Framebuffer incomplete."; 435 DLOG(ERROR) << "Framebuffer incomplete.";
410 } 436 }
411 #endif 437 #endif
412 } 438 }
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
« no previous file with comments | « content/common/gpu/texture_image_transport_surface.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698