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

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

Issue 10214014: Backport to R19 of r132638 r133017 r133579 r133732 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1084/src
Patch Set: 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() {
101 for (int i = 0; i < 2; ++i) { 113 if (parent_stub_) {
102 Texture& texture = textures_[i]; 114 parent_stub_->decoder()->MakeCurrent();
103 if (!texture.sent_to_client) 115 ReleaseParentStub();
104 continue;
105 GpuHostMsg_AcceleratedSurfaceRelease_Params params;
106 params.identifier = texture.client_id;
107 helper_->SendAcceleratedSurfaceRelease(params);
108 } 116 }
109 117
110 helper_->Destroy(); 118 helper_->Destroy();
111 } 119 }
112 120
113 bool TextureImageTransportSurface::Resize(const gfx::Size&) { 121 bool TextureImageTransportSurface::Resize(const gfx::Size&) {
114 return true; 122 return true;
115 } 123 }
116 124
117 bool TextureImageTransportSurface::IsOffscreen() { 125 bool TextureImageTransportSurface::IsOffscreen() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ReleaseBackTexture(); 168 ReleaseBackTexture();
161 break; 169 break;
162 }; 170 };
163 } 171 }
164 172
165 void* TextureImageTransportSurface::GetShareHandle() { 173 void* TextureImageTransportSurface::GetShareHandle() {
166 return GetHandle(); 174 return GetHandle();
167 } 175 }
168 176
169 void* TextureImageTransportSurface::GetDisplay() { 177 void* TextureImageTransportSurface::GetDisplay() {
170 return parent_stub_.get() ? parent_stub_->surface()->GetDisplay() : NULL; 178 return parent_stub_ ? parent_stub_->surface()->GetDisplay() : NULL;
171 } 179 }
172 180
173 void* TextureImageTransportSurface::GetConfig() { 181 void* TextureImageTransportSurface::GetConfig() {
174 return parent_stub_.get() ? parent_stub_->surface()->GetConfig() : NULL; 182 return parent_stub_ ? parent_stub_->surface()->GetConfig() : NULL;
175 } 183 }
176 184
177 void TextureImageTransportSurface::OnResize(gfx::Size size) { 185 void TextureImageTransportSurface::OnResize(gfx::Size size) {
178 CreateBackTexture(size); 186 CreateBackTexture(size);
179 } 187 }
180 188
181 void TextureImageTransportSurface::OnWillDestroyStub( 189 void TextureImageTransportSurface::OnWillDestroyStub(
182 GpuCommandBufferStub* stub) { 190 GpuCommandBufferStub* stub) {
183 glDeleteFramebuffersEXT(1, &fbo_id_); 191 if (stub == parent_stub_) {
184 CHECK_GL_ERROR(); 192 ReleaseParentStub();
185 fbo_id_ = 0; 193 } else {
194 stub->RemoveDestructionObserver(this);
195 // We are losing the stub owning us, this is our last chance to clean up the
196 // resources we allocated in the stub's context.
197 glDeleteFramebuffersEXT(1, &fbo_id_);
198 CHECK_GL_ERROR();
199 fbo_id_ = 0;
186 200
187 stub->RemoveDestructionObserver(this); 201 stub_destroyed_ = true;
188 stub_destroyed_ = true; 202 }
189 } 203 }
190 204
191 bool TextureImageTransportSurface::SwapBuffers() { 205 bool TextureImageTransportSurface::SwapBuffers() {
206 if (!parent_stub_) {
207 LOG(ERROR) << "SwapBuffers failed because no parent stub.";
208 return false;
209 }
210
192 glFlush(); 211 glFlush();
193 front_ = back(); 212 front_ = back();
194 previous_damage_rect_ = gfx::Rect(textures_[front_].size); 213 previous_damage_rect_ = gfx::Rect(textures_[front_].size);
195 214
196 DCHECK(textures_[front_].client_id != 0); 215 DCHECK(textures_[front_].client_id != 0);
197 216
198 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; 217 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
199 params.surface_handle = textures_[front_].client_id; 218 params.surface_handle = textures_[front_].client_id;
200 helper_->SendAcceleratedSurfaceBuffersSwapped(params); 219 helper_->SendAcceleratedSurfaceBuffersSwapped(params);
201 helper_->SetScheduled(false); 220 helper_->SetScheduled(false);
202 return true; 221 return true;
203 } 222 }
204 223
205 bool TextureImageTransportSurface::PostSubBuffer( 224 bool TextureImageTransportSurface::PostSubBuffer(
206 int x, int y, int width, int height) { 225 int x, int y, int width, int height) {
207 if (!parent_stub_.get()) 226 if (!parent_stub_) {
227 LOG(ERROR) << "PostSubBuffer failed because no parent stub.";
208 return false; 228 return false;
229 }
209 230
210 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 231 DCHECK(textures_[back()].info);
211 if (!info) 232 int back_texture_service_id = textures_[back()].info->service_id();
212 return false;
213 int back_texture_service_id = info->service_id();
214 233
215 info = GetParentInfo(textures_[front_].client_id); 234 DCHECK(textures_[front_].info);
216 if (!info) 235 int front_texture_service_id = textures_[front_].info->service_id();
217 return false;
218 int front_texture_service_id = info->service_id();
219 236
220 gfx::Size expected_size = textures_[back()].size; 237 gfx::Size expected_size = textures_[back()].size;
221 bool surfaces_same_size = textures_[front_].size == expected_size; 238 bool surfaces_same_size = textures_[front_].size == expected_size;
222 239
223 const gfx::Rect new_damage_rect(x, y, width, height); 240 const gfx::Rect new_damage_rect(x, y, width, height);
224 241
225 // An empty damage rect is a successful no-op. 242 // An empty damage rect is a successful no-op.
226 if (new_damage_rect.IsEmpty()) 243 if (new_damage_rect.IsEmpty())
227 return true; 244 return true;
228 245
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 extensions += "GL_CHROMIUM_front_buffer_cached "; 289 extensions += "GL_CHROMIUM_front_buffer_cached ";
273 extensions += "GL_CHROMIUM_post_sub_buffer"; 290 extensions += "GL_CHROMIUM_post_sub_buffer";
274 return extensions; 291 return extensions;
275 } 292 }
276 293
277 gfx::Size TextureImageTransportSurface::GetSize() { 294 gfx::Size TextureImageTransportSurface::GetSize() {
278 return textures_[back()].size; 295 return textures_[back()].size;
279 } 296 }
280 297
281 void* TextureImageTransportSurface::GetHandle() { 298 void* TextureImageTransportSurface::GetHandle() {
282 return parent_stub_.get() ? parent_stub_->surface()->GetHandle() : NULL; 299 return parent_stub_ ? parent_stub_->surface()->GetHandle() : NULL;
283 } 300 }
284 301
285 302
286 void TextureImageTransportSurface::OnNewSurfaceACK( 303 void TextureImageTransportSurface::OnNewSurfaceACK(
287 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { 304 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) {
288 } 305 }
289 306
290 void TextureImageTransportSurface::OnBuffersSwappedACK() { 307 void TextureImageTransportSurface::OnBuffersSwappedACK() {
291 if (helper_->MakeCurrent()) { 308 if (helper_->MakeCurrent()) {
292 if (textures_[front_].size != textures_[back()].size) { 309 if (textures_[front_].size != textures_[back()].size) {
(...skipping 10 matching lines...) Expand all
303 320
304 void TextureImageTransportSurface::OnPostSubBufferACK() { 321 void TextureImageTransportSurface::OnPostSubBufferACK() {
305 OnBuffersSwappedACK(); 322 OnBuffersSwappedACK();
306 } 323 }
307 324
308 void TextureImageTransportSurface::OnResizeViewACK() { 325 void TextureImageTransportSurface::OnResizeViewACK() {
309 NOTREACHED(); 326 NOTREACHED();
310 } 327 }
311 328
312 void TextureImageTransportSurface::ReleaseBackTexture() { 329 void TextureImageTransportSurface::ReleaseBackTexture() {
313 if (!parent_stub_.get()) 330 if (!parent_stub_)
314 return; 331 return;
315 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 332 TextureInfo* info = textures_[back()].info;
316 if (!info) 333 DCHECK(info);
317 return;
318 334
319 GLuint service_id = info->service_id(); 335 GLuint service_id = info->service_id();
320 if (!service_id) 336 if (!service_id)
321 return; 337 return;
322 info->SetServiceId(0); 338 info->SetServiceId(0);
323 339
324 { 340 {
325 ScopedFrameBufferBinder fbo_binder(fbo_id_); 341 ScopedFrameBufferBinder fbo_binder(fbo_id_);
326 glDeleteTextures(1, &service_id); 342 glDeleteTextures(1, &service_id);
327 } 343 }
328 glFlush(); 344 glFlush();
329 CHECK_GL_ERROR(); 345 CHECK_GL_ERROR();
330 } 346 }
331 347
332 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { 348 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) {
333 if (!parent_stub_.get()) 349 if (!parent_stub_)
334 return; 350 return;
335 Texture& texture = textures_[back()]; 351 Texture& texture = textures_[back()];
336 TextureInfo* info = GetParentInfo(texture.client_id); 352 TextureInfo* info = texture.info;
337 if (!info) 353 DCHECK(info);
338 return;
339 354
340 GLuint service_id = info->service_id(); 355 GLuint service_id = info->service_id();
341 356
342 if (service_id && texture.size == size) 357 if (service_id && texture.size == size)
343 return; 358 return;
344 359
345 if (!service_id) { 360 if (!service_id) {
346 glGenTextures(1, &service_id); 361 glGenTextures(1, &service_id);
347 info->SetServiceId(service_id); 362 info->SetServiceId(service_id);
348 } 363 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 396
382 GpuHostMsg_AcceleratedSurfaceNew_Params params; 397 GpuHostMsg_AcceleratedSurfaceNew_Params params;
383 params.width = size.width(); 398 params.width = size.width();
384 params.height = size.height(); 399 params.height = size.height();
385 params.surface_handle = texture.client_id; 400 params.surface_handle = texture.client_id;
386 helper_->SendAcceleratedSurfaceNew(params); 401 helper_->SendAcceleratedSurfaceNew(params);
387 texture.sent_to_client = true; 402 texture.sent_to_client = true;
388 } 403 }
389 404
390 void TextureImageTransportSurface::AttachBackTextureToFBO() { 405 void TextureImageTransportSurface::AttachBackTextureToFBO() {
391 if (!parent_stub_.get()) 406 if (!parent_stub_)
392 return; 407 return;
393 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 408 DCHECK(textures_[back()].info);
394 if (!info)
395 return;
396 409
397 ScopedFrameBufferBinder fbo_binder(fbo_id_); 410 ScopedFrameBufferBinder fbo_binder(fbo_id_);
398 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, 411 glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
399 GL_COLOR_ATTACHMENT0, 412 GL_COLOR_ATTACHMENT0,
400 GL_TEXTURE_2D, 413 GL_TEXTURE_2D,
401 info->service_id(), 414 textures_[back()].info->service_id(),
402 0); 415 0);
403 glFlush(); 416 glFlush();
404 CHECK_GL_ERROR(); 417 CHECK_GL_ERROR();
405 418
406 #ifndef NDEBUG 419 #ifndef NDEBUG
407 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 420 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
408 if (status != GL_FRAMEBUFFER_COMPLETE) { 421 if (status != GL_FRAMEBUFFER_COMPLETE) {
409 DLOG(ERROR) << "Framebuffer incomplete."; 422 DLOG(ERROR) << "Framebuffer incomplete.";
410 } 423 }
411 #endif 424 #endif
412 } 425 }
413 426
414 TextureInfo* TextureImageTransportSurface::GetParentInfo(uint32 client_id) { 427 void TextureImageTransportSurface::ReleaseParentStub() {
415 DCHECK(parent_stub_.get()); 428 DCHECK(parent_stub_);
416 TextureManager* texture_manager = 429 parent_stub_->RemoveDestructionObserver(this);
417 parent_stub_->decoder()->GetContextGroup()->texture_manager(); 430 for (int i = 0; i < 2; ++i) {
418 TextureInfo* info = texture_manager->GetTextureInfo(client_id); 431 Texture& texture = textures_[i];
419 return info; 432 texture.info = NULL;
433 if (!texture.sent_to_client)
434 continue;
435 GpuHostMsg_AcceleratedSurfaceRelease_Params params;
436 params.identifier = texture.client_id;
437 helper_->SendAcceleratedSurfaceRelease(params);
438 }
439 parent_stub_ = NULL;
420 } 440 }
OLDNEW
« no previous file with comments | « content/common/gpu/texture_image_transport_surface.h ('k') | gpu/command_buffer/client/gles2_implementation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698