OLD | NEW |
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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "content/common/gpu/gl_scoped_binders.h" |
11 #include "content/common/gpu/gpu_channel.h" | 12 #include "content/common/gpu/gpu_channel.h" |
12 #include "content/common/gpu/gpu_channel_manager.h" | 13 #include "content/common/gpu/gpu_channel_manager.h" |
13 #include "content/common/gpu/gpu_messages.h" | 14 #include "content/common/gpu/gpu_messages.h" |
14 #include "content/common/gpu/sync_point_manager.h" | 15 #include "content/common/gpu/sync_point_manager.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 #include "gpu/command_buffer/service/context_group.h" | 17 #include "gpu/command_buffer/service/context_group.h" |
17 #include "gpu/command_buffer/service/gpu_scheduler.h" | 18 #include "gpu/command_buffer/service/gpu_scheduler.h" |
18 #include "gpu/command_buffer/service/texture_manager.h" | 19 #include "gpu/command_buffer/service/texture_manager.h" |
19 | 20 |
20 using gpu::gles2::ContextGroup; | 21 using gpu::gles2::ContextGroup; |
21 using gpu::gles2::TextureManager; | 22 using gpu::gles2::TextureManager; |
22 typedef TextureManager::TextureInfo TextureInfo; | 23 typedef TextureManager::TextureInfo TextureInfo; |
23 | 24 |
24 namespace { | |
25 | |
26 class ScopedFrameBufferBinder { | |
27 public: | |
28 explicit ScopedFrameBufferBinder(unsigned int fbo) { | |
29 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo_); | |
30 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo); | |
31 } | |
32 | |
33 ~ScopedFrameBufferBinder() { | |
34 glBindFramebufferEXT(GL_FRAMEBUFFER, old_fbo_); | |
35 } | |
36 | |
37 private: | |
38 int old_fbo_; | |
39 }; | |
40 | |
41 class ScopedTextureBinder { | |
42 public: | |
43 explicit ScopedTextureBinder(unsigned int id) { | |
44 glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_id_); | |
45 glBindTexture(GL_TEXTURE_2D, id); | |
46 } | |
47 | |
48 ~ScopedTextureBinder() { | |
49 glBindTexture(GL_TEXTURE_2D, old_id_); | |
50 } | |
51 | |
52 private: | |
53 int old_id_; | |
54 }; | |
55 | |
56 } // anonymous namespace | |
57 | |
58 TextureImageTransportSurface::Texture::Texture() | 25 TextureImageTransportSurface::Texture::Texture() |
59 : client_id(0), | 26 : client_id(0), |
60 sent_to_client(false) { | 27 sent_to_client(false) { |
61 } | 28 } |
62 | 29 |
63 TextureImageTransportSurface::Texture::~Texture() { | 30 TextureImageTransportSurface::Texture::~Texture() { |
64 } | 31 } |
65 | 32 |
66 TextureImageTransportSurface::TextureImageTransportSurface( | 33 TextureImageTransportSurface::TextureImageTransportSurface( |
67 GpuChannelManager* manager, | 34 GpuChannelManager* manager, |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 const gfx::Rect new_damage_rect(x, y, width, height); | 248 const gfx::Rect new_damage_rect(x, y, width, height); |
282 | 249 |
283 // An empty damage rect is a successful no-op. | 250 // An empty damage rect is a successful no-op. |
284 if (new_damage_rect.IsEmpty()) | 251 if (new_damage_rect.IsEmpty()) |
285 return true; | 252 return true; |
286 | 253 |
287 if (surfaces_same_size) { | 254 if (surfaces_same_size) { |
288 std::vector<gfx::Rect> regions_to_copy; | 255 std::vector<gfx::Rect> regions_to_copy; |
289 GetRegionsToCopy(previous_damage_rect_, new_damage_rect, ®ions_to_copy); | 256 GetRegionsToCopy(previous_damage_rect_, new_damage_rect, ®ions_to_copy); |
290 | 257 |
291 ScopedFrameBufferBinder fbo_binder(fbo_id_); | 258 content::ScopedFrameBufferBinder fbo_binder(fbo_id_); |
292 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 259 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
293 GL_COLOR_ATTACHMENT0, | 260 GL_COLOR_ATTACHMENT0, |
294 GL_TEXTURE_2D, | 261 GL_TEXTURE_2D, |
295 front_texture_service_id, | 262 front_texture_service_id, |
296 0); | 263 0); |
297 ScopedTextureBinder texture_binder(back_texture_service_id); | 264 content::ScopedTextureBinder texture_binder(back_texture_service_id); |
298 | 265 |
299 for (size_t i = 0; i < regions_to_copy.size(); ++i) { | 266 for (size_t i = 0; i < regions_to_copy.size(); ++i) { |
300 const gfx::Rect& region_to_copy = regions_to_copy[i]; | 267 const gfx::Rect& region_to_copy = regions_to_copy[i]; |
301 if (!region_to_copy.IsEmpty()) { | 268 if (!region_to_copy.IsEmpty()) { |
302 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, region_to_copy.x(), | 269 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, region_to_copy.x(), |
303 region_to_copy.y(), region_to_copy.x(), region_to_copy.y(), | 270 region_to_copy.y(), region_to_copy.x(), region_to_copy.y(), |
304 region_to_copy.width(), region_to_copy.height()); | 271 region_to_copy.width(), region_to_copy.height()); |
305 } | 272 } |
306 } | 273 } |
307 } else { | 274 } else { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return; | 352 return; |
386 TextureInfo* info = textures_[back()].info; | 353 TextureInfo* info = textures_[back()].info; |
387 DCHECK(info); | 354 DCHECK(info); |
388 | 355 |
389 GLuint service_id = info->service_id(); | 356 GLuint service_id = info->service_id(); |
390 if (!service_id) | 357 if (!service_id) |
391 return; | 358 return; |
392 info->SetServiceId(0); | 359 info->SetServiceId(0); |
393 | 360 |
394 { | 361 { |
395 ScopedFrameBufferBinder fbo_binder(fbo_id_); | 362 content::ScopedFrameBufferBinder fbo_binder(fbo_id_); |
396 glDeleteTextures(1, &service_id); | 363 glDeleteTextures(1, &service_id); |
397 } | 364 } |
398 glFlush(); | 365 glFlush(); |
399 CHECK_GL_ERROR(); | 366 CHECK_GL_ERROR(); |
400 } | 367 } |
401 | 368 |
402 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { | 369 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { |
403 if (!parent_stub_) | 370 if (!parent_stub_) |
404 return; | 371 return; |
405 Texture& texture = textures_[back()]; | 372 Texture& texture = textures_[back()]; |
(...skipping 22 matching lines...) Expand all Loading... |
428 size.width(), | 395 size.width(), |
429 size.height(), | 396 size.height(), |
430 1, | 397 1, |
431 0, | 398 0, |
432 GL_RGBA, | 399 GL_RGBA, |
433 GL_UNSIGNED_BYTE, | 400 GL_UNSIGNED_BYTE, |
434 true); | 401 true); |
435 } | 402 } |
436 | 403 |
437 { | 404 { |
438 ScopedTextureBinder texture_binder(service_id); | 405 content::ScopedTextureBinder texture_binder(service_id); |
439 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 406 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
440 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 407 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 408 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
443 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | 410 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, |
444 size.width(), size.height(), 0, | 411 size.width(), size.height(), 0, |
445 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 412 GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
446 CHECK_GL_ERROR(); | 413 CHECK_GL_ERROR(); |
447 } | 414 } |
448 | 415 |
449 AttachBackTextureToFBO(); | 416 AttachBackTextureToFBO(); |
450 | 417 |
451 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 418 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
452 params.width = size.width(); | 419 params.width = size.width(); |
453 params.height = size.height(); | 420 params.height = size.height(); |
454 params.surface_handle = texture.client_id; | 421 params.surface_handle = texture.client_id; |
455 helper_->SendAcceleratedSurfaceNew(params); | 422 helper_->SendAcceleratedSurfaceNew(params); |
456 texture.sent_to_client = true; | 423 texture.sent_to_client = true; |
457 } | 424 } |
458 | 425 |
459 void TextureImageTransportSurface::AttachBackTextureToFBO() { | 426 void TextureImageTransportSurface::AttachBackTextureToFBO() { |
460 if (!parent_stub_) | 427 if (!parent_stub_) |
461 return; | 428 return; |
462 DCHECK(textures_[back()].info); | 429 DCHECK(textures_[back()].info); |
463 | 430 |
464 ScopedFrameBufferBinder fbo_binder(fbo_id_); | 431 content::ScopedFrameBufferBinder fbo_binder(fbo_id_); |
465 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 432 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
466 GL_COLOR_ATTACHMENT0, | 433 GL_COLOR_ATTACHMENT0, |
467 GL_TEXTURE_2D, | 434 GL_TEXTURE_2D, |
468 textures_[back()].info->service_id(), | 435 textures_[back()].info->service_id(), |
469 0); | 436 0); |
470 glFlush(); | 437 glFlush(); |
471 CHECK_GL_ERROR(); | 438 CHECK_GL_ERROR(); |
472 | 439 |
473 #ifndef NDEBUG | 440 #ifndef NDEBUG |
474 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | 441 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
(...skipping 10 matching lines...) Expand all Loading... |
485 Texture& texture = textures_[i]; | 452 Texture& texture = textures_[i]; |
486 texture.info = NULL; | 453 texture.info = NULL; |
487 if (!texture.sent_to_client) | 454 if (!texture.sent_to_client) |
488 continue; | 455 continue; |
489 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 456 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
490 params.identifier = texture.client_id; | 457 params.identifier = texture.client_id; |
491 helper_->SendAcceleratedSurfaceRelease(params); | 458 helper_->SendAcceleratedSurfaceRelease(params); |
492 } | 459 } |
493 parent_stub_ = NULL; | 460 parent_stub_ = NULL; |
494 } | 461 } |
OLD | NEW |