| 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/CGLRenderers.h> | 7 #include <OpenGL/CGLRenderers.h> |
| 8 #include <OpenGL/OpenGL.h> | 8 #include <OpenGL/OpenGL.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // Having two NSOpenGLContexts bound to an NSView concurrently will cause | 317 // Having two NSOpenGLContexts bound to an NSView concurrently will cause |
| 318 // artifacts and crashes. If |context_| is bound to |view|, then unbind | 318 // artifacts and crashes. If |context_| is bound to |view|, then unbind |
| 319 // |context_| before |new_context| gets bound to |view|. | 319 // |context_| before |new_context| gets bound to |view|. |
| 320 // http://crbug.com/230883 | 320 // http://crbug.com/230883 |
| 321 if ([context_->nsgl_context() view] == view) | 321 if ([context_->nsgl_context() view] == view) |
| 322 [context_->nsgl_context() clearDrawable]; | 322 [context_->nsgl_context() clearDrawable]; |
| 323 | 323 |
| 324 context_ = new_context; | 324 context_ = new_context; |
| 325 } | 325 } |
| 326 | 326 |
| 327 void CompositingIOSurfaceMac::SetDeviceScaleFactor(float scale_factor) { |
| 328 // TODO: After a resolution change, the DPI-ness of the view and the |
| 329 // IOSurface might not be in sync. |
| 330 io_surface_size_ = gfx::ToFlooredSize( |
| 331 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor)); |
| 332 } |
| 333 |
| 327 bool CompositingIOSurfaceMac::is_vsync_disabled() const { | 334 bool CompositingIOSurfaceMac::is_vsync_disabled() const { |
| 328 return context_->is_vsync_disabled(); | 335 return context_->is_vsync_disabled(); |
| 329 } | 336 } |
| 330 | 337 |
| 331 void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase, | 338 void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase, |
| 332 uint32* interval_numerator, | 339 uint32* interval_numerator, |
| 333 uint32* interval_denominator) { | 340 uint32* interval_denominator) { |
| 334 base::AutoLock lock(lock_); | 341 base::AutoLock lock(lock_); |
| 335 *timebase = vsync_timebase_; | 342 *timebase = vsync_timebase_; |
| 336 *interval_numerator = vsync_interval_numerator_; | 343 *interval_numerator = vsync_interval_numerator_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 384 |
| 378 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface", | 385 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface", |
| 379 "has_io_surface", has_io_surface); | 386 "has_io_surface", has_io_surface); |
| 380 | 387 |
| 381 [context_->nsgl_context() setView:view]; | 388 [context_->nsgl_context() setView:view]; |
| 382 gfx::Size window_size(NSSizeToCGSize([view frame].size)); | 389 gfx::Size window_size(NSSizeToCGSize([view frame].size)); |
| 383 gfx::Size pixel_window_size = gfx::ToFlooredSize( | 390 gfx::Size pixel_window_size = gfx::ToFlooredSize( |
| 384 gfx::ScaleSize(window_size, scale_factor)); | 391 gfx::ScaleSize(window_size, scale_factor)); |
| 385 glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height()); | 392 glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height()); |
| 386 | 393 |
| 387 // TODO: After a resolution change, the DPI-ness of the view and the | 394 SetDeviceScaleFactor(scale_factor); |
| 388 // IOSurface might not be in sync. | 395 |
| 389 io_surface_size_ = gfx::ToFlooredSize( | 396 SurfaceQuad quad; |
| 390 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor)); | 397 quad.set_size(io_surface_size_, pixel_io_surface_size_); |
| 391 quad_.set_size(io_surface_size_, pixel_io_surface_size_); | |
| 392 | 398 |
| 393 glMatrixMode(GL_PROJECTION); | 399 glMatrixMode(GL_PROJECTION); |
| 394 glLoadIdentity(); | 400 glLoadIdentity(); |
| 395 | 401 |
| 396 // Note that the projection keeps things in view units, so the use of | 402 // Note that the projection keeps things in view units, so the use of |
| 397 // window_size / io_surface_size_ (as opposed to the pixel_ variants) below is | 403 // window_size / io_surface_size_ (as opposed to the pixel_ variants) below is |
| 398 // correct. | 404 // correct. |
| 399 glOrtho(0, window_size.width(), window_size.height(), 0, -1, 1); | 405 glOrtho(0, window_size.width(), window_size.height(), 0, -1, 1); |
| 400 glMatrixMode(GL_MODELVIEW); | 406 glMatrixMode(GL_MODELVIEW); |
| 401 glLoadIdentity(); | 407 glLoadIdentity(); |
| 402 | 408 |
| 403 glDisable(GL_DEPTH_TEST); | 409 glDisable(GL_DEPTH_TEST); |
| 404 glDisable(GL_BLEND); | 410 glDisable(GL_BLEND); |
| 405 | 411 |
| 406 if (has_io_surface) { | 412 if (has_io_surface) { |
| 407 context_->shader_program_cache()->UseBlitProgram(); | 413 context_->shader_program_cache()->UseBlitProgram(); |
| 408 glActiveTexture(GL_TEXTURE0); | 414 glActiveTexture(GL_TEXTURE0); |
| 409 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); | 415 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); |
| 410 | 416 |
| 411 DrawQuad(quad_); | 417 DrawQuad(quad); |
| 412 | 418 |
| 413 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); CHECK_GL_ERROR(); | 419 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); CHECK_GL_ERROR(); |
| 414 | 420 |
| 415 // Fill the resize gutters with white. | 421 // Fill the resize gutters with white. |
| 416 if (window_size.width() > io_surface_size_.width() || | 422 if (window_size.width() > io_surface_size_.width() || |
| 417 window_size.height() > io_surface_size_.height()) { | 423 window_size.height() > io_surface_size_.height()) { |
| 418 context_->shader_program_cache()->UseSolidWhiteProgram(); | 424 context_->shader_program_cache()->UseSolidWhiteProgram(); |
| 419 SurfaceQuad filler_quad; | 425 SurfaceQuad filler_quad; |
| 420 if (window_size.width() > io_surface_size_.width()) { | 426 if (window_size.width() > io_surface_size_.width()) { |
| 421 // Draw right-side gutter down to the bottom of the window. | 427 // Draw right-side gutter down to the bottom of the window. |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 } | 1052 } |
| 1047 | 1053 |
| 1048 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface( | 1054 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface( |
| 1049 const gfx::Rect& rect, float scale_factor) const { | 1055 const gfx::Rect& rect, float scale_factor) const { |
| 1050 return gfx::IntersectRects(rect, | 1056 return gfx::IntersectRects(rect, |
| 1051 gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(io_surface_size_), | 1057 gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(io_surface_size_), |
| 1052 scale_factor))); | 1058 scale_factor))); |
| 1053 } | 1059 } |
| 1054 | 1060 |
| 1055 } // namespace content | 1061 } // namespace content |
| OLD | NEW |