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/browser/renderer_host/compositing_iosurface_mac.h" | 5 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
6 | 6 |
7 #include <OpenGL/OpenGL.h> | 7 #include <OpenGL/OpenGL.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 DrawQuad(filler_quad); | 379 DrawQuad(filler_quad); |
380 } | 380 } |
381 if (window_size.height() > io_surface_size_.height()) { | 381 if (window_size.height() > io_surface_size_.height()) { |
382 // Draw bottom gutter to the width of the IOSurface. | 382 // Draw bottom gutter to the width of the IOSurface. |
383 filler_quad.set_rect(0.0f, io_surface_size_.height(), | 383 filler_quad.set_rect(0.0f, io_surface_size_.height(), |
384 io_surface_size_.width(), window_size.height()); | 384 io_surface_size_.width(), window_size.height()); |
385 DrawQuad(filler_quad); | 385 DrawQuad(filler_quad); |
386 } | 386 } |
387 } | 387 } |
388 | 388 |
| 389 // Workaround for issue 158469. Issue a dummy draw call with texture_ not |
| 390 // bound to blit_rgb_sampler_location_, in order to shake all references |
| 391 // to the IOSurface out of the driver. |
| 392 glBegin(GL_TRIANGLES); |
| 393 glEnd(); |
| 394 |
389 glUseProgram(0); CHECK_GL_ERROR(); | 395 glUseProgram(0); CHECK_GL_ERROR(); |
390 | |
391 // Issue a dummy draw call to flush references to the IOSurface out of | |
392 // the GL driver. | |
393 DoWorkaroundForIOSurfaceLeak(); | |
394 } else { | 396 } else { |
395 // Should match the clear color of RenderWidgetHostViewMac. | 397 // Should match the clear color of RenderWidgetHostViewMac. |
396 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); | 398 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
397 glClear(GL_COLOR_BUFFER_BIT); | 399 glClear(GL_COLOR_BUFFER_BIT); |
398 } | 400 } |
399 | 401 |
400 static bool initialized_workaround = false; | 402 static bool initialized_workaround = false; |
401 static bool use_glfinish_workaround = false; | 403 static bool use_glfinish_workaround = false; |
402 | 404 |
403 if (!initialized_workaround) { | 405 if (!initialized_workaround) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 glEnableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL_ERROR(); | 525 glEnableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL_ERROR(); |
524 | 526 |
525 glVertexPointer(2, GL_FLOAT, sizeof(SurfaceVertex), &quad.verts_[0].x_); | 527 glVertexPointer(2, GL_FLOAT, sizeof(SurfaceVertex), &quad.verts_[0].x_); |
526 glTexCoordPointer(2, GL_FLOAT, sizeof(SurfaceVertex), &quad.verts_[0].tx_); | 528 glTexCoordPointer(2, GL_FLOAT, sizeof(SurfaceVertex), &quad.verts_[0].tx_); |
527 glDrawArrays(GL_QUADS, 0, 4); CHECK_GL_ERROR(); | 529 glDrawArrays(GL_QUADS, 0, 4); CHECK_GL_ERROR(); |
528 | 530 |
529 glDisableClientState(GL_VERTEX_ARRAY); | 531 glDisableClientState(GL_VERTEX_ARRAY); |
530 glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 532 glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
531 } | 533 } |
532 | 534 |
533 void CompositingIOSurfaceMac::DoWorkaroundForIOSurfaceLeak() { | |
534 if (!shader_program_blit_rgb_) | |
535 return; | |
536 | |
537 glMatrixMode(GL_PROJECTION); | |
538 glLoadIdentity(); | |
539 glOrtho(0, 1, 0, 1, -1, 1); | |
540 glMatrixMode(GL_MODELVIEW); | |
541 glLoadIdentity(); | |
542 | |
543 // Workaround for issue 158469. Issue a dummy draw call with texture_ not | |
544 // bound to blit_rgb_sampler_location_, in order to shake all references | |
545 // to the IOSurface out of the driver. | |
546 glUseProgram(shader_program_blit_rgb_); | |
547 glUniform1i(blit_rgb_sampler_location_, 0); | |
548 glActiveTexture(GL_TEXTURE0 + 0); | |
549 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); | |
550 | |
551 // Let invisible_quad be a quad that is outside of the viewport. | |
552 SurfaceQuad invisible_quad; | |
553 invisible_quad.set_rect(-2.0f, -2.0f, -1.9f, -1.9f); | |
554 invisible_quad.set_texcoord_rect(0.0f, 0.0f, 1.0f, 1.0f); | |
555 DrawQuad(invisible_quad); | |
556 glUseProgram(0); | |
557 | |
558 CHECK_GL_ERROR(); | |
559 } | |
560 | |
561 void CompositingIOSurfaceMac::UnrefIOSurfaceWithContextCurrent() { | 535 void CompositingIOSurfaceMac::UnrefIOSurfaceWithContextCurrent() { |
562 if (texture_) { | 536 if (texture_) { |
563 glDeleteTextures(1, &texture_); | 537 glDeleteTextures(1, &texture_); |
564 texture_ = 0; | 538 texture_ = 0; |
565 } | 539 } |
566 | 540 |
567 io_surface_.reset(); | 541 io_surface_.reset(); |
568 | 542 |
569 // Forget the ID, because even if it is still around when we want to use it | 543 // Forget the ID, because even if it is still around when we want to use it |
570 // again, OSX may have reused the same ID for a new tab and we don't want to | 544 // again, OSX may have reused the same ID for a new tab and we don't want to |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 glDeleteFramebuffersEXT(1, ©_context_.frame_buffer); CHECK_GL_ERROR(); | 848 glDeleteFramebuffersEXT(1, ©_context_.frame_buffer); CHECK_GL_ERROR(); |
875 glDeleteTextures(1, ©_context_.frame_buffer_texture); CHECK_GL_ERROR(); | 849 glDeleteTextures(1, ©_context_.frame_buffer_texture); CHECK_GL_ERROR(); |
876 glDeleteBuffers(1, ©_context_.pixel_buffer); CHECK_GL_ERROR(); | 850 glDeleteBuffers(1, ©_context_.pixel_buffer); CHECK_GL_ERROR(); |
877 if (copy_context_.use_fence) { | 851 if (copy_context_.use_fence) { |
878 glDeleteFencesAPPLE(1, ©_context_.fence); CHECK_GL_ERROR(); | 852 glDeleteFencesAPPLE(1, ©_context_.fence); CHECK_GL_ERROR(); |
879 } | 853 } |
880 copy_context_.Reset(); | 854 copy_context_.Reset(); |
881 } | 855 } |
882 | 856 |
883 } // namespace content | 857 } // namespace content |
OLD | NEW |