OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_ns_gl_surface.h" | 5 #include "ui/accelerated_widget_mac/io_surface_ns_gl_surface.h" |
6 | 6 |
7 #include <OpenGL/GL.h> | 7 #include <OpenGL/GL.h> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/mac/bind_objc_block.h" | 10 #include "base/mac/bind_objc_block.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 IOSurfaceNSGLSurface::~IOSurfaceNSGLSurface() { | 59 IOSurfaceNSGLSurface::~IOSurfaceNSGLSurface() { |
60 [ns_gl_context_ makeCurrentContext]; | 60 [ns_gl_context_ makeCurrentContext]; |
61 iosurface_ = NULL; | 61 iosurface_ = NULL; |
62 [NSOpenGLContext clearCurrentContext]; | 62 [NSOpenGLContext clearCurrentContext]; |
63 [ns_gl_context_ clearDrawable]; | 63 [ns_gl_context_ clearDrawable]; |
64 } | 64 } |
65 | 65 |
66 bool IOSurfaceNSGLSurface::GotFrame(IOSurfaceID io_surface_id, | 66 bool IOSurfaceNSGLSurface::GotFrame(IOSurfaceID io_surface_id, |
67 gfx::Size frame_pixel_size, | 67 gfx::Size frame_pixel_size, |
68 float frame_scale_factor) { | 68 float frame_scale_factor, |
| 69 gfx::Rect pixel_damage_rect) { |
69 // The OpenGL framebuffer's scale factor and pixel size are updated to match | 70 // The OpenGL framebuffer's scale factor and pixel size are updated to match |
70 // the CALayer's contentsScale and bounds at setView. The pixel size is the | 71 // the CALayer's contentsScale and bounds at setView. The pixel size is the |
71 // stored in the GL_VIEWPORT state of the context. | 72 // stored in the GL_VIEWPORT state of the context. |
72 gfx::Size contents_pixel_size; | 73 gfx::Size contents_pixel_size; |
73 float contents_scale_factor = [[view_ layer] contentsScale]; | 74 float contents_scale_factor = [[view_ layer] contentsScale]; |
74 { | 75 { |
75 [ns_gl_context_ makeCurrentContext]; | 76 [ns_gl_context_ makeCurrentContext]; |
76 GLint viewport[4]; | 77 GLint viewport[4]; |
77 glGetIntegerv(GL_VIEWPORT, viewport); | 78 glGetIntegerv(GL_VIEWPORT, viewport); |
78 [NSOpenGLContext clearCurrentContext]; | 79 [NSOpenGLContext clearCurrentContext]; |
79 contents_pixel_size = gfx::Size(viewport[2], viewport[3]); | 80 contents_pixel_size = gfx::Size(viewport[2], viewport[3]); |
80 } | 81 } |
81 | 82 |
82 // If the OpenGL framebuffer does not match the frame in scale factor or | 83 // If the OpenGL framebuffer does not match the frame in scale factor or |
83 // pixel size, then re-latch them. Note that they will latch to the layer's | 84 // pixel size, then re-latch them. Note that they will latch to the layer's |
84 // bounds, which will not necessarily match the frame's pixel size. | 85 // bounds, which will not necessarily match the frame's pixel size. |
| 86 bool full_damage = false; |
85 if (frame_pixel_size != contents_pixel_size || | 87 if (frame_pixel_size != contents_pixel_size || |
86 frame_scale_factor != contents_scale_factor) { | 88 frame_scale_factor != contents_scale_factor) { |
87 ScopedCAActionDisabler disabler; | 89 ScopedCAActionDisabler disabler; |
88 [ns_gl_context_ clearDrawable]; | 90 [ns_gl_context_ clearDrawable]; |
89 [[view_ layer] setContentsScale:frame_scale_factor]; | 91 [[view_ layer] setContentsScale:frame_scale_factor]; |
90 [ns_gl_context_ setView:view_]; | 92 [ns_gl_context_ setView:view_]; |
| 93 |
| 94 // The front buffer may have been destroyed at re-creation, so re-draw |
| 95 // everything. |
| 96 full_damage = true; |
91 } | 97 } |
92 | 98 |
93 bool result = true; | 99 bool result = true; |
94 [ns_gl_context_ makeCurrentContext]; | 100 [ns_gl_context_ makeCurrentContext]; |
95 result &= iosurface_->SetIOSurface(io_surface_id, frame_pixel_size); | 101 result &= iosurface_->SetIOSurface(io_surface_id, frame_pixel_size); |
96 result &= iosurface_->DrawIOSurface(); | 102 if (full_damage) |
| 103 result &= iosurface_->DrawIOSurface(); |
| 104 else |
| 105 result &= iosurface_->DrawIOSurfaceWithDamageRect(pixel_damage_rect); |
97 glFlush(); | 106 glFlush(); |
98 [NSOpenGLContext clearCurrentContext]; | 107 [NSOpenGLContext clearCurrentContext]; |
99 return result; | 108 return result; |
100 } | 109 } |
101 | 110 |
102 }; | 111 }; |
OLD | NEW |