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

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

Issue 16189012: Add a path to use CALayers to display content (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate review feedback Created 7 years, 6 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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/mac/mac_util.h" 15 #include "base/mac/mac_util.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/threading/platform_thread.h" 17 #include "base/threading/platform_thread.h"
18 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" 18 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
19 #include "content/browser/renderer_host/compositing_iosurface_shader_programs_ma c.h" 19 #include "content/browser/renderer_host/compositing_iosurface_shader_programs_ma c.h"
20 #include "content/browser/renderer_host/compositing_iosurface_transformer_mac.h" 20 #include "content/browser/renderer_host/compositing_iosurface_transformer_mac.h"
21 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
21 #include "content/common/content_constants_internal.h" 22 #include "content/common/content_constants_internal.h"
22 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" 23 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
23 #include "gpu/command_buffer/service/gpu_switches.h" 24 #include "gpu/command_buffer/service/gpu_switches.h"
24 #include "media/base/video_util.h" 25 #include "media/base/video_util.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
27 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 28 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
28 #include "ui/gl/gl_context.h" 29 #include "ui/gl/gl_context.h"
29 #include "ui/gfx/size_conversions.h" 30 #include "ui/gfx/size_conversions.h"
30 #include "ui/surface/io_surface_support_mac.h" 31 #include "ui/surface/io_surface_support_mac.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 220 }
220 } 221 }
221 } 222 }
222 223
223 224
224 // static 225 // static
225 CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create( 226 CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create(
226 int window_number, 227 int window_number,
227 SurfaceOrder surface_order) { 228 SurfaceOrder surface_order) {
228 TRACE_EVENT0("browser", "CompositingIOSurfaceMac::Create"); 229 TRACE_EVENT0("browser", "CompositingIOSurfaceMac::Create");
230
231 scoped_refptr<CompositingIOSurfaceContext> context =
232 CompositingIOSurfaceContext::Get(window_number, surface_order);
233 if (!context) {
234 LOG(WARNING) << "Failed to create context for IOSurface";
235 return NULL;
236 }
237
238 return Create(context);
239 }
240
241 CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create(
242 const scoped_refptr<CompositingIOSurfaceContext>& context) {
229 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); 243 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize();
230 if (!io_surface_support) { 244 if (!io_surface_support) {
231 LOG(WARNING) << "No IOSurface support"; 245 LOG(WARNING) << "No IOSurface support";
232 return NULL; 246 return NULL;
233 } 247 }
234 248
235 scoped_refptr<CompositingIOSurfaceContext> context =
236 CompositingIOSurfaceContext::Get(window_number, surface_order);
237
238 return new CompositingIOSurfaceMac(io_surface_support, 249 return new CompositingIOSurfaceMac(io_surface_support,
239 context); 250 context);
240 } 251 }
241 252
242 CompositingIOSurfaceMac::CompositingIOSurfaceMac( 253 CompositingIOSurfaceMac::CompositingIOSurfaceMac(
243 IOSurfaceSupport* io_surface_support, 254 IOSurfaceSupport* io_surface_support,
244 scoped_refptr<CompositingIOSurfaceContext> context) 255 const scoped_refptr<CompositingIOSurfaceContext>& context)
245 : io_surface_support_(io_surface_support), 256 : io_surface_support_(io_surface_support),
246 context_(context), 257 context_(context),
247 io_surface_handle_(0), 258 io_surface_handle_(0),
259 scale_factor_(1.f),
248 texture_(0), 260 texture_(0),
249 finish_copy_timer_( 261 finish_copy_timer_(
250 FROM_HERE, 262 FROM_HERE,
251 base::TimeDelta::FromMilliseconds(kFinishCopyPollingPeriodMs), 263 base::TimeDelta::FromMilliseconds(kFinishCopyPollingPeriodMs),
252 base::Bind(&CompositingIOSurfaceMac::FinishAllCopies, 264 base::Bind(&CompositingIOSurfaceMac::FinishAllCopies,
253 base::Unretained(this)), 265 base::Unretained(this)),
254 true), 266 true),
255 display_link_(0), 267 display_link_(0),
256 display_link_stop_timer_(FROM_HERE, base::TimeDelta::FromSeconds(1), 268 display_link_stop_timer_(FROM_HERE, base::TimeDelta::FromSeconds(1),
257 this, &CompositingIOSurfaceMac::StopDisplayLink), 269 this, &CompositingIOSurfaceMac::StopDisplayLink),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 DestroyAllCopyContextsWithinContext(); 367 DestroyAllCopyContextsWithinContext();
356 UnrefIOSurfaceWithContextCurrent(); 368 UnrefIOSurfaceWithContextCurrent();
357 CGLSetCurrentContext(0); 369 CGLSetCurrentContext(0);
358 context_ = nil; 370 context_ = nil;
359 } 371 }
360 372
361 void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle, 373 void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle,
362 const gfx::Size& size, 374 const gfx::Size& size,
363 float scale_factor) { 375 float scale_factor) {
364 pixel_io_surface_size_ = size; 376 pixel_io_surface_size_ = size;
377 scale_factor_ = scale_factor;
365 dip_io_surface_size_ = gfx::ToFlooredSize( 378 dip_io_surface_size_ = gfx::ToFlooredSize(
366 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor)); 379 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor_));
367 CGLSetCurrentContext(context_->cgl_context()); 380 CGLSetCurrentContext(context_->cgl_context());
368 MapIOSurfaceToTexture(io_surface_handle); 381 MapIOSurfaceToTexture(io_surface_handle);
369 CGLSetCurrentContext(0); 382 CGLSetCurrentContext(0);
370 } 383 }
371 384
372 int CompositingIOSurfaceMac::GetRendererID() { 385 int CompositingIOSurfaceMac::GetRendererID() {
373 GLint current_renderer_id = -1; 386 GLint current_renderer_id = -1;
374 if (CGLGetParameter(context_->cgl_context(), 387 if (CGLGetParameter(context_->cgl_context(),
375 kCGLCPCurrentRendererID, 388 kCGLCPCurrentRendererID,
376 &current_renderer_id) == kCGLNoError) 389 &current_renderer_id) == kCGLNoError)
377 return current_renderer_id & kCGLRendererIDMatchingMask; 390 return current_renderer_id & kCGLRendererIDMatchingMask;
378 return -1; 391 return -1;
379 } 392 }
380 393
381 void CompositingIOSurfaceMac::DrawIOSurface( 394 void CompositingIOSurfaceMac::DrawIOSurface(
382 NSView* view, 395 RenderWidgetHostViewMac* render_widget_host_view) {
383 float scale_factor, 396 DCHECK(!render_widget_host_view->use_core_animation_);
384 int window_number, 397
385 SurfaceOrder surface_order, 398 NSView* view = render_widget_host_view->cocoa_view();
399
400 content::CompositingIOSurfaceMac::SurfaceOrder surface_order =
401 render_widget_host_view->allow_overlapping_views_
402 ? content::CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW
403 : content::CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW;
404 SwitchToContextOnNewWindow(
405 view,
406 render_widget_host_view->window_number(),
407 surface_order);
408
409 CGLSetCurrentContext(context_->cgl_context());
410 [context_->nsgl_context() setView:view];
411
412 gfx::Size window_size(NSSizeToCGSize([view frame].size));
413
414 DrawIOSurface(
415 window_size,
416 render_widget_host_view->scale_factor(),
417 render_widget_host_view->frame_subscriber());
418
419 CGLSetCurrentContext(context_->cgl_context());
420 CGLFlushDrawable(context_->cgl_context());
421 CGLSetCurrentContext(0);
422 }
423
424 void CompositingIOSurfaceMac::DrawIOSurface(
425 const gfx::Size& window_size,
426 float window_scale_factor,
386 RenderWidgetHostViewFrameSubscriber* frame_subscriber) { 427 RenderWidgetHostViewFrameSubscriber* frame_subscriber) {
387
388 if (display_link_ == NULL) 428 if (display_link_ == NULL)
389 SetupCVDisplayLink(); 429 SetupCVDisplayLink();
390 430
391 SwitchToContextOnNewWindow(view, window_number, surface_order);
392
393 CGLSetCurrentContext(context_->cgl_context());
394
395 bool has_io_surface = MapIOSurfaceToTexture(io_surface_handle_); 431 bool has_io_surface = MapIOSurfaceToTexture(io_surface_handle_);
396
397 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface", 432 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface",
398 "has_io_surface", has_io_surface); 433 "has_io_surface", has_io_surface);
399 434
400 [context_->nsgl_context() setView:view];
401 gfx::Size window_size(NSSizeToCGSize([view frame].size));
402 gfx::Size pixel_window_size = gfx::ToFlooredSize( 435 gfx::Size pixel_window_size = gfx::ToFlooredSize(
403 gfx::ScaleSize(window_size, scale_factor)); 436 gfx::ScaleSize(window_size, window_scale_factor));
404 glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height()); 437 glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height());
405 438
406 SurfaceQuad quad; 439 SurfaceQuad quad;
407 quad.set_size(dip_io_surface_size_, pixel_io_surface_size_); 440 quad.set_size(dip_io_surface_size_, pixel_io_surface_size_);
408 441
409 glMatrixMode(GL_PROJECTION); 442 glMatrixMode(GL_PROJECTION);
410 glLoadIdentity(); 443 glLoadIdentity();
411 444
412 // Note that the projection keeps things in view units, so the use of 445 // Note that the projection keeps things in view units, so the use of
413 // window_size / dip_io_surface_size_ (as opposed to the pixel_ variants) 446 // window_size / dip_io_surface_size_ (as opposed to the pixel_ variants)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 const base::Time present_time = base::Time::Now(); 526 const base::Time present_time = base::Time::Now();
494 scoped_refptr<media::VideoFrame> frame; 527 scoped_refptr<media::VideoFrame> frame;
495 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 528 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
496 if (frame_subscriber->ShouldCaptureFrame(present_time, &frame, &callback)) { 529 if (frame_subscriber->ShouldCaptureFrame(present_time, &frame, &callback)) {
497 copy_done_callback = CopyToVideoFrameWithinContext( 530 copy_done_callback = CopyToVideoFrameWithinContext(
498 gfx::Rect(pixel_io_surface_size_), true, frame, 531 gfx::Rect(pixel_io_surface_size_), true, frame,
499 base::Bind(callback, present_time)); 532 base::Bind(callback, present_time));
500 } 533 }
501 } 534 }
502 535
503 CGLFlushDrawable(context_->cgl_context());
504
505 // For latency_tests.cc: 536 // For latency_tests.cc:
506 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete", 537 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete",
507 TRACE_EVENT_SCOPE_THREAD); 538 TRACE_EVENT_SCOPE_THREAD);
508 539
509 // Try to finish previous copy requests after flush to get better pipelining. 540 // Try to finish previous copy requests after flush to get better pipelining.
510 std::vector<base::Closure> copy_done_callbacks; 541 std::vector<base::Closure> copy_done_callbacks;
511 FinishAllCopiesWithinContext(&copy_done_callbacks); 542 FinishAllCopiesWithinContext(&copy_done_callbacks);
512 543
513 CGLSetCurrentContext(0);
514
515 if (!copy_done_callback.is_null()) 544 if (!copy_done_callback.is_null())
516 copy_done_callbacks.push_back(copy_done_callback); 545 copy_done_callbacks.push_back(copy_done_callback);
517 for (size_t i = 0; i < copy_done_callbacks.size(); ++i) 546 for (size_t i = 0; i < copy_done_callbacks.size(); ++i)
518 copy_done_callbacks[i].Run(); 547 copy_done_callbacks[i].Run();
519 548
520 StartOrContinueDisplayLink(); 549 StartOrContinueDisplayLink();
521 550
522 if (!is_vsync_disabled()) 551 if (!is_vsync_disabled())
523 RateLimitDraws(); 552 RateLimitDraws();
524 } 553 }
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 } 1088 }
1060 } 1089 }
1061 1090
1062 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface( 1091 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface(
1063 const gfx::Rect& rect) const { 1092 const gfx::Rect& rect) const {
1064 return gfx::IntersectRects(rect, 1093 return gfx::IntersectRects(rect,
1065 gfx::ToEnclosingRect(gfx::Rect(pixel_io_surface_size_))); 1094 gfx::ToEnclosingRect(gfx::Rect(pixel_io_surface_size_)));
1066 } 1095 }
1067 1096
1068 } // namespace content 1097 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698