| 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 "ui/accelerated_widget_mac/io_surface_texture.h" | 5 #include "ui/accelerated_widget_mac/io_surface_texture.h" |
| 6 | 6 |
| 7 #include <OpenGL/CGLIOSurface.h> | 7 #include <OpenGL/CGLIOSurface.h> |
| 8 #include <OpenGL/CGLRenderers.h> | 8 #include <OpenGL/CGLRenderers.h> |
| 9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
| 10 #include <OpenGL/OpenGL.h> | 10 #include <OpenGL/OpenGL.h> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 needs_gl_finish_workaround_(needs_gl_finish_workaround) { | 56 needs_gl_finish_workaround_(needs_gl_finish_workaround) { |
| 57 } | 57 } |
| 58 | 58 |
| 59 IOSurfaceTexture::~IOSurfaceTexture() { | 59 IOSurfaceTexture::~IOSurfaceTexture() { |
| 60 ReleaseIOSurfaceAndTexture(); | 60 ReleaseIOSurfaceAndTexture(); |
| 61 offscreen_context_ = NULL; | 61 offscreen_context_ = NULL; |
| 62 DCHECK(eviction_queue_iterator_ == eviction_queue_.Get().end()); | 62 DCHECK(eviction_queue_iterator_ == eviction_queue_.Get().end()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool IOSurfaceTexture::DrawIOSurface() { | 65 bool IOSurfaceTexture::DrawIOSurface() { |
| 66 TRACE_EVENT0("browser", "IOSurfaceTexture::DrawIOSurface"); | 66 return DrawIOSurfaceInternal(gfx::Rect(pixel_size_), true); |
| 67 } |
| 68 |
| 69 bool IOSurfaceTexture::DrawIOSurfaceWithDamageRect(gfx::Rect damage_rect) { |
| 70 return DrawIOSurfaceInternal(damage_rect, false); |
| 71 } |
| 72 |
| 73 bool IOSurfaceTexture::DrawIOSurfaceInternal( |
| 74 gfx::Rect damage_rect, bool draw_boundary) { |
| 75 TRACE_EVENT0("browser", "IOSurfaceTexture::DrawIOSurfaceInternal"); |
| 67 DCHECK(CGLGetCurrentContext()); | 76 DCHECK(CGLGetCurrentContext()); |
| 68 | 77 |
| 69 // If we have release the IOSurface, clear the screen to light grey and | 78 // If we have release the IOSurface, clear the screen to light grey and |
| 70 // early-out. | 79 // early-out. |
| 71 if (!io_surface_) { | 80 if (!io_surface_) { |
| 72 glClearColor(0.9, 0.9, 0.9, 1); | 81 glClearColor(0.9, 0.9, 0.9, 1); |
| 73 glClear(GL_COLOR_BUFFER_BIT); | 82 glClear(GL_COLOR_BUFFER_BIT); |
| 74 return false; | 83 return false; |
| 75 } | 84 } |
| 76 | 85 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 pixel_size_.height() - viewport_rect.height(), pixel_size_.height(), | 96 pixel_size_.height() - viewport_rect.height(), pixel_size_.height(), |
| 88 -1, 1); | 97 -1, 1); |
| 89 glMatrixMode(GL_MODELVIEW); | 98 glMatrixMode(GL_MODELVIEW); |
| 90 glLoadIdentity(); | 99 glLoadIdentity(); |
| 91 | 100 |
| 92 // Draw a quad the size of the IOSurface. This should cover the full viewport. | 101 // Draw a quad the size of the IOSurface. This should cover the full viewport. |
| 93 glColor4f(1, 1, 1, 1); | 102 glColor4f(1, 1, 1, 1); |
| 94 glEnable(GL_TEXTURE_RECTANGLE_ARB); | 103 glEnable(GL_TEXTURE_RECTANGLE_ARB); |
| 95 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); | 104 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); |
| 96 glBegin(GL_QUADS); | 105 glBegin(GL_QUADS); |
| 97 glTexCoord2f(0, 0); | 106 glTexCoord2f(damage_rect.x(), damage_rect.y()); |
| 98 glVertex2f(0, 0); | 107 glVertex2f(damage_rect.x(), damage_rect.y()); |
| 99 glTexCoord2f(pixel_size_.width(), 0); | 108 glTexCoord2f(damage_rect.right(), damage_rect.y()); |
| 100 glVertex2f(pixel_size_.width(), 0); | 109 glVertex2f(damage_rect.right(), damage_rect.y()); |
| 101 glTexCoord2f(pixel_size_.width(), pixel_size_.height()); | 110 glTexCoord2f(damage_rect.right(), damage_rect.bottom()); |
| 102 glVertex2f(pixel_size_.width(), pixel_size_.height()); | 111 glVertex2f(damage_rect.right(), damage_rect.bottom()); |
| 103 glTexCoord2f(0, pixel_size_.height()); | 112 glTexCoord2f(damage_rect.x(), damage_rect.bottom()); |
| 104 glVertex2f(0, pixel_size_.height()); | 113 glVertex2f(damage_rect.x(), damage_rect.bottom()); |
| 105 glEnd(); | 114 glEnd(); |
| 106 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); | 115 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); |
| 107 glDisable(GL_TEXTURE_RECTANGLE_ARB); | 116 glDisable(GL_TEXTURE_RECTANGLE_ARB); |
| 108 | 117 |
| 109 // Workaround for issue 158469. Issue a dummy draw call with texture_ not | 118 // Workaround for issue 158469. Issue a dummy draw call with texture_ not |
| 110 // bound to a texture, in order to shake all references to the IOSurface out | 119 // bound to a texture, in order to shake all references to the IOSurface out |
| 111 // of the driver. | 120 // of the driver. |
| 112 glBegin(GL_TRIANGLES); | 121 glBegin(GL_TRIANGLES); |
| 113 glEnd(); | 122 glEnd(); |
| 114 | 123 |
| 124 // If the viewport is larger than the texture, clear out the overflow to |
| 125 // white. |
| 126 if (draw_boundary) { |
| 127 if (pixel_size_.width() < viewport_rect.width()) { |
| 128 glBegin(GL_QUADS); |
| 129 glVertex2f(pixel_size_.width(), 0); |
| 130 glVertex2f(pixel_size_.width(), viewport_rect.height()); |
| 131 glVertex2f(viewport_rect.width(), viewport_rect.height()); |
| 132 glVertex2f(viewport_rect.width(), 0); |
| 133 glEnd(); |
| 134 } |
| 135 if (pixel_size_.height() < viewport_rect.height()) { |
| 136 int non_surface_height = viewport_rect.height() - pixel_size_.height(); |
| 137 glBegin(GL_QUADS); |
| 138 glVertex2f(0, 0); |
| 139 glVertex2f(0, non_surface_height); |
| 140 glVertex2f(pixel_size_.width(), non_surface_height); |
| 141 glVertex2f(pixel_size_.width(), 0); |
| 142 glEnd(); |
| 143 } |
| 144 } |
| 145 |
| 115 if (needs_gl_finish_workaround_) { | 146 if (needs_gl_finish_workaround_) { |
| 116 TRACE_EVENT0("gpu", "glFinish"); | 147 TRACE_EVENT0("gpu", "glFinish"); |
| 117 glFinish(); | 148 glFinish(); |
| 118 } | 149 } |
| 119 | 150 |
| 120 // Check if any of the drawing calls result in an error. | 151 // Check if any of the drawing calls result in an error. |
| 121 GetAndSaveGLError(); | 152 GetAndSaveGLError(); |
| 122 bool result = true; | 153 bool result = true; |
| 123 if (gl_error_ != GL_NO_ERROR) { | 154 if (gl_error_ != GL_NO_ERROR) { |
| 124 LOG(ERROR) << "GL error in DrawIOSurface: " << gl_error_; | 155 LOG(ERROR) << "GL error in DrawIOSurface: " << gl_error_; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 336 } |
| 306 | 337 |
| 307 // static | 338 // static |
| 308 base::LazyInstance<IOSurfaceTexture::EvictionQueue> | 339 base::LazyInstance<IOSurfaceTexture::EvictionQueue> |
| 309 IOSurfaceTexture::eviction_queue_; | 340 IOSurfaceTexture::eviction_queue_; |
| 310 | 341 |
| 311 // static | 342 // static |
| 312 bool IOSurfaceTexture::eviction_scheduled_ = false; | 343 bool IOSurfaceTexture::eviction_scheduled_ = false; |
| 313 | 344 |
| 314 } // namespace ui | 345 } // namespace ui |
| OLD | NEW |