Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Side by Side Diff: content/browser/renderer_host/compositing_iosurface_mac.mm

Issue 15689003: Part 3/3 (RWH/IOSurface) of adding with device scale factor to transport surfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // Having two NSOpenGLContexts bound to an NSView concurrently will cause 328 // Having two NSOpenGLContexts bound to an NSView concurrently will cause
329 // artifacts and crashes. If |context_| is bound to |view|, then unbind 329 // artifacts and crashes. If |context_| is bound to |view|, then unbind
330 // |context_| before |new_context| gets bound to |view|. 330 // |context_| before |new_context| gets bound to |view|.
331 // http://crbug.com/230883 331 // http://crbug.com/230883
332 if ([context_->nsgl_context() view] == view) 332 if ([context_->nsgl_context() view] == view)
333 [context_->nsgl_context() clearDrawable]; 333 [context_->nsgl_context() clearDrawable];
334 334
335 context_ = new_context; 335 context_ = new_context;
336 } 336 }
337 337
338 void CompositingIOSurfaceMac::SetDeviceScaleFactor(float scale_factor) {
339 // TODO: After a resolution change, the DPI-ness of the view and the
340 // IOSurface might not be in sync.
341 io_surface_size_ = gfx::ToFlooredSize(
342 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor));
343 }
344
345 bool CompositingIOSurfaceMac::is_vsync_disabled() const { 338 bool CompositingIOSurfaceMac::is_vsync_disabled() const {
346 return context_->is_vsync_disabled(); 339 return context_->is_vsync_disabled();
347 } 340 }
348 341
349 void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase, 342 void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase,
350 uint32* interval_numerator, 343 uint32* interval_numerator,
351 uint32* interval_denominator) { 344 uint32* interval_denominator) {
352 base::AutoLock lock(lock_); 345 base::AutoLock lock(lock_);
353 *timebase = vsync_timebase_; 346 *timebase = vsync_timebase_;
354 *interval_numerator = vsync_interval_numerator_; 347 *interval_numerator = vsync_interval_numerator_;
355 *interval_denominator = vsync_interval_denominator_; 348 *interval_denominator = vsync_interval_denominator_;
356 } 349 }
357 350
358 CompositingIOSurfaceMac::~CompositingIOSurfaceMac() { 351 CompositingIOSurfaceMac::~CompositingIOSurfaceMac() {
359 FailAllCopies(); 352 FailAllCopies();
360 CVDisplayLinkRelease(display_link_); 353 CVDisplayLinkRelease(display_link_);
361 CGLSetCurrentContext(context_->cgl_context()); 354 CGLSetCurrentContext(context_->cgl_context());
362 DestroyAllCopyContextsWithinContext(); 355 DestroyAllCopyContextsWithinContext();
363 UnrefIOSurfaceWithContextCurrent(); 356 UnrefIOSurfaceWithContextCurrent();
364 CGLSetCurrentContext(0); 357 CGLSetCurrentContext(0);
365 context_ = nil; 358 context_ = nil;
366 } 359 }
367 360
368 void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle, 361 void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle,
369 const gfx::Size& size) { 362 const gfx::Size& size,
363 float scale_factor) {
370 pixel_io_surface_size_ = size; 364 pixel_io_surface_size_ = size;
365 io_surface_size_ = gfx::ToFlooredSize(
366 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor));
Nico 2013/05/22 15:33:22 Does this still have to be a member variable, or c
ccameron 2013/05/22 20:50:12 It's also used when checking HasAcceleratedSurface
371 CGLSetCurrentContext(context_->cgl_context()); 367 CGLSetCurrentContext(context_->cgl_context());
372 MapIOSurfaceToTexture(io_surface_handle); 368 MapIOSurfaceToTexture(io_surface_handle);
373 CGLSetCurrentContext(0); 369 CGLSetCurrentContext(0);
374 } 370 }
375 371
376 int CompositingIOSurfaceMac::GetRendererID() { 372 int CompositingIOSurfaceMac::GetRendererID() {
377 GLint current_renderer_id = -1; 373 GLint current_renderer_id = -1;
378 if (CGLGetParameter(context_->cgl_context(), 374 if (CGLGetParameter(context_->cgl_context(),
379 kCGLCPCurrentRendererID, 375 kCGLCPCurrentRendererID,
380 &current_renderer_id) == kCGLNoError) 376 &current_renderer_id) == kCGLNoError)
(...skipping 19 matching lines...) Expand all
400 396
401 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface", 397 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface",
402 "has_io_surface", has_io_surface); 398 "has_io_surface", has_io_surface);
403 399
404 [context_->nsgl_context() setView:view]; 400 [context_->nsgl_context() setView:view];
405 gfx::Size window_size(NSSizeToCGSize([view frame].size)); 401 gfx::Size window_size(NSSizeToCGSize([view frame].size));
406 gfx::Size pixel_window_size = gfx::ToFlooredSize( 402 gfx::Size pixel_window_size = gfx::ToFlooredSize(
407 gfx::ScaleSize(window_size, scale_factor)); 403 gfx::ScaleSize(window_size, scale_factor));
408 glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height()); 404 glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height());
409 405
410 SetDeviceScaleFactor(scale_factor);
411
412 SurfaceQuad quad; 406 SurfaceQuad quad;
413 quad.set_size(io_surface_size_, pixel_io_surface_size_); 407 quad.set_size(io_surface_size_, pixel_io_surface_size_);
414 408
415 glMatrixMode(GL_PROJECTION); 409 glMatrixMode(GL_PROJECTION);
416 glLoadIdentity(); 410 glLoadIdentity();
417 411
418 // Note that the projection keeps things in view units, so the use of 412 // Note that the projection keeps things in view units, so the use of
419 // window_size / io_surface_size_ (as opposed to the pixel_ variants) below is 413 // window_size / io_surface_size_ (as opposed to the pixel_ variants) below is
420 // correct. 414 // correct.
421 glOrtho(0, window_size.width(), window_size.height(), 0, -1, 1); 415 glOrtho(0, window_size.width(), window_size.height(), 0, -1, 1);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 } 604 }
611 605
612 io_surface_handle_ = io_surface_handle; 606 io_surface_handle_ = io_surface_handle;
613 607
614 // Actual IOSurface size is rounded up to reduce reallocations during window 608 // Actual IOSurface size is rounded up to reduce reallocations during window
615 // resize. Get the actual size to properly map the texture. 609 // resize. Get the actual size to properly map the texture.
616 gfx::Size rounded_size( 610 gfx::Size rounded_size(
617 io_surface_support_->IOSurfaceGetWidth(io_surface_), 611 io_surface_support_->IOSurfaceGetWidth(io_surface_),
618 io_surface_support_->IOSurfaceGetHeight(io_surface_)); 612 io_surface_support_->IOSurfaceGetHeight(io_surface_));
619 613
620 // TODO(thakis): Keep track of the view size over IPC. At the moment,
621 // the correct view units are computed on first paint.
622 io_surface_size_ = pixel_io_surface_size_;
Nico 2013/05/22 15:33:22 \o/
623
624 GLenum target = GL_TEXTURE_RECTANGLE_ARB; 614 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
625 glGenTextures(1, &texture_); 615 glGenTextures(1, &texture_);
626 glBindTexture(target, texture_); 616 glBindTexture(target, texture_);
627 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 617 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
628 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR(); 618 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR();
629 GLuint plane = 0; 619 GLuint plane = 0;
630 CGLError cglerror = io_surface_support_->CGLTexImageIOSurface2D( 620 CGLError cglerror = io_surface_support_->CGLTexImageIOSurface2D(
631 context_->cgl_context(), 621 context_->cgl_context(),
632 target, 622 target,
633 GL_RGBA, 623 GL_RGBA,
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 } 1064 }
1075 1065
1076 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface( 1066 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface(
1077 const gfx::Rect& rect, float scale_factor) const { 1067 const gfx::Rect& rect, float scale_factor) const {
1078 return gfx::IntersectRects(rect, 1068 return gfx::IntersectRects(rect,
1079 gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(io_surface_size_), 1069 gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(io_surface_size_),
1080 scale_factor))); 1070 scale_factor)));
1081 } 1071 }
1082 1072
1083 } // namespace content 1073 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/compositing_iosurface_mac.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698