OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/compositor/io_surface_layer_mac.h" | 5 #include "content/browser/compositor/io_surface_layer_mac.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <OpenGL/CGLIOSurface.h> | 8 #include <OpenGL/CGLIOSurface.h> |
9 #include <OpenGL/CGLRenderers.h> | 9 #include <OpenGL/CGLRenderers.h> |
10 #include <OpenGL/gl.h> | 10 #include <OpenGL/gl.h> |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 204 } |
205 | 205 |
206 - (void)dealloc { | 206 - (void)dealloc { |
207 DCHECK(!helper_); | 207 DCHECK(!helper_); |
208 [super dealloc]; | 208 [super dealloc]; |
209 } | 209 } |
210 | 210 |
211 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id | 211 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id |
212 withPixelSize:(gfx::Size)pixel_size | 212 withPixelSize:(gfx::Size)pixel_size |
213 withScaleFactor:(float)scale_factor { | 213 withScaleFactor:(float)scale_factor { |
214 bool result = true; | 214 return iosurface_->SetIOSurface(context_, io_surface_id, pixel_size); |
215 gfx::ScopedCGLSetCurrentContext scoped_set_current_context( | |
216 context_->cgl_context()); | |
217 result = iosurface_->SetIOSurfaceWithContextCurrent( | |
218 context_, io_surface_id, pixel_size, scale_factor); | |
219 return result; | |
220 } | 215 } |
221 | 216 |
222 - (void)poisonContextAndSharegroup { | 217 - (void)poisonContextAndSharegroup { |
223 context_->PoisonContextAndSharegroup(); | 218 context_->PoisonContextAndSharegroup(); |
224 } | 219 } |
225 | 220 |
226 - (bool)hasBeenPoisoned { | 221 - (bool)hasBeenPoisoned { |
227 return context_->HasBeenPoisoned(); | 222 return context_->HasBeenPoisoned(); |
228 } | 223 } |
229 | 224 |
230 - (float)scaleFactor { | 225 - (float)scaleFactor { |
231 return iosurface_->scale_factor(); | 226 if ([self respondsToSelector:(@selector(contentsScale))]) |
| 227 return [self contentsScale]; |
| 228 return 1; |
232 } | 229 } |
233 | 230 |
234 - (int)rendererID { | 231 - (int)rendererID { |
235 return iosurface_->GetRendererID(); | 232 return iosurface_->GetRendererID(); |
236 } | 233 } |
237 | 234 |
238 - (void)resetClient { | 235 - (void)resetClient { |
239 helper_.reset(); | 236 helper_.reset(); |
240 } | 237 } |
241 | 238 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 forLayerTime:(CFTimeInterval)timeInterval | 290 forLayerTime:(CFTimeInterval)timeInterval |
294 displayTime:(const CVTimeStamp*)timeStamp { | 291 displayTime:(const CVTimeStamp*)timeStamp { |
295 TRACE_EVENT0("browser", "IOSurfaceLayer::drawInCGLContext"); | 292 TRACE_EVENT0("browser", "IOSurfaceLayer::drawInCGLContext"); |
296 | 293 |
297 if (!iosurface_->HasIOSurface() || context_->cgl_context() != glContext) { | 294 if (!iosurface_->HasIOSurface() || context_->cgl_context() != glContext) { |
298 glClearColor(1, 1, 1, 1); | 295 glClearColor(1, 1, 1, 1); |
299 glClear(GL_COLOR_BUFFER_BIT); | 296 glClear(GL_COLOR_BUFFER_BIT); |
300 return; | 297 return; |
301 } | 298 } |
302 | 299 |
303 // The correct viewport to cover the layer will be set up by the caller. | 300 bool draw_succeeded = iosurface_->DrawIOSurface(); |
304 // Transform this into a window size for DrawIOSurface, where it will be | |
305 // transformed back into this viewport. | |
306 GLint viewport[4]; | |
307 glGetIntegerv(GL_VIEWPORT, viewport); | |
308 gfx::Rect window_rect(viewport[0], viewport[1], viewport[2], viewport[3]); | |
309 float window_scale_factor = 1.f; | |
310 if ([self respondsToSelector:(@selector(contentsScale))]) | |
311 window_scale_factor = [self contentsScale]; | |
312 window_rect = ToNearestRect( | |
313 gfx::ScaleRect(window_rect, 1.f/window_scale_factor)); | |
314 | |
315 bool draw_succeeded = iosurface_->DrawIOSurface( | |
316 context_, window_rect, window_scale_factor); | |
317 | |
318 if (helper_) | 301 if (helper_) |
319 helper_->DidDraw(draw_succeeded); | 302 helper_->DidDraw(draw_succeeded); |
320 | 303 |
321 [super drawInCGLContext:glContext | 304 [super drawInCGLContext:glContext |
322 pixelFormat:pixelFormat | 305 pixelFormat:pixelFormat |
323 forLayerTime:timeInterval | 306 forLayerTime:timeInterval |
324 displayTime:timeStamp]; | 307 displayTime:timeStamp]; |
325 } | 308 } |
326 | 309 |
327 @end | 310 @end |
OLD | NEW |