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 glBegin(GL_QUADS); | |
137 glVertex2f(0, 0); | |
138 glVertex2f(pixel_size_.width(), viewport_rect.height() - | |
139 pixel_size_.height()); | |
Ken Russell (switch to Gerrit)
2015/06/05 21:43:27
This looks wrong -- should this be (0, ...)?
ccameron
2015/06/05 22:46:22
Yes, this is wrong. Fixed.
| |
140 glVertex2f(viewport_rect.width(), viewport_rect.height() - | |
141 pixel_size_.height()); | |
142 glVertex2f(viewport_rect.width(), 0); | |
143 glEnd(); | |
144 } | |
145 } | |
146 | |
115 if (needs_gl_finish_workaround_) { | 147 if (needs_gl_finish_workaround_) { |
116 TRACE_EVENT0("gpu", "glFinish"); | 148 TRACE_EVENT0("gpu", "glFinish"); |
117 glFinish(); | 149 glFinish(); |
118 } | 150 } |
119 | 151 |
120 // Check if any of the drawing calls result in an error. | 152 // Check if any of the drawing calls result in an error. |
121 GetAndSaveGLError(); | 153 GetAndSaveGLError(); |
122 bool result = true; | 154 bool result = true; |
123 if (gl_error_ != GL_NO_ERROR) { | 155 if (gl_error_ != GL_NO_ERROR) { |
124 LOG(ERROR) << "GL error in DrawIOSurface: " << gl_error_; | 156 LOG(ERROR) << "GL error in DrawIOSurface: " << gl_error_; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 } | 337 } |
306 | 338 |
307 // static | 339 // static |
308 base::LazyInstance<IOSurfaceTexture::EvictionQueue> | 340 base::LazyInstance<IOSurfaceTexture::EvictionQueue> |
309 IOSurfaceTexture::eviction_queue_; | 341 IOSurfaceTexture::eviction_queue_; |
310 | 342 |
311 // static | 343 // static |
312 bool IOSurfaceTexture::eviction_scheduled_ = false; | 344 bool IOSurfaceTexture::eviction_scheduled_ = false; |
313 | 345 |
314 } // namespace ui | 346 } // namespace ui |
OLD | NEW |