Commit 4232b250 authored by ccameron@chromium.org's avatar ccameron@chromium.org

Make --enable-delegated-renderer show stuff on Mac

With this patch, pixels appear on screen and tab capture works.

Add a OnNativeSurfaceBuffersSwapped mechanism to display
an IOSurface to an NSView. This is wired up to the existing
CompositingIOSurfaceMac. In a future refactoring, something
much more light-weight than CompositingIOSurfaceMac will
be used (CompositingIOSurfaceMac has capture code, etc, in
it).

Add a DelegatedFrameHost to RenderWidgetHostViewMac, and
hookup the DelegatedFrameHostClient implementation. Create
the DelegatedFrameHost when a delegated frame is received, and
use its existence to determine which mode is active.

BUG=314190

Review URL: https://codereview.chromium.org/267073003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269946 0039d316-1c4b-4281-b951-d872f2087c98
parent 2c68be07
......@@ -1606,7 +1606,6 @@ void ResourceProvider::TransferResource(GLES2Interface* gl,
DCHECK(!source->lock_for_read_count);
DCHECK(source->origin != Resource::External || source->mailbox.IsValid());
DCHECK(source->allocated);
DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE);
resource->id = id;
resource->format = source->format;
resource->mailbox_holder.texture_target = source->target;
......
......@@ -754,8 +754,8 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
resource_dispatcher_host_.get()->Shutdown();
}
#if defined(USE_AURA)
{
#if defined(USE_AURA) || defined(OS_MACOSX)
if (ShouldInitializeBrowserGpuChannelAndTransportSurface()) {
TRACE_EVENT0("shutdown",
"BrowserMainLoop::Subsystem:ImageTransportFactory");
ImageTransportFactory::Terminate();
......
......@@ -12,6 +12,7 @@
#include "cc/resources/single_release_callback.h"
#include "cc/resources/texture_mailbox.h"
#include "content/browser/compositor/resize_lock.h"
#include "content/common/gpu/client/gl_helper.h"
#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
#include "content/public/common/content_switches.h"
#include "media/base/video_frame.h"
......@@ -40,7 +41,7 @@ DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client)
last_output_surface_id_(0),
pending_delegated_ack_count_(0),
skipped_frames_(false),
can_lock_compositor_(YES),
can_lock_compositor_(YES_CAN_LOCK),
delegated_frame_evictor_(new DelegatedFrameEvictor(this)) {
ImageTransportFactory::GetInstance()->AddObserver(this);
}
......@@ -76,15 +77,13 @@ void DelegatedFrameHost::MaybeCreateResizeLock() {
can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
can_lock_compositor_ == NO_PENDING_COMMIT;
if (can_lock_compositor_ == YES)
if (can_lock_compositor_ == YES_CAN_LOCK)
can_lock_compositor_ = YES_DID_LOCK;
resize_lock_ = client_->CreateResizeLock(defer_compositor_lock);
}
bool DelegatedFrameHost::ShouldCreateResizeLock() {
RenderWidgetHostImpl* host = client_->GetHost();
// On Windows while resizing, the the resize locks makes us mis-paint a white
// vertical strip (including the non-client area) if the content composition
// is lagging the UI composition. So here we disable the throttling so that
......@@ -92,9 +91,12 @@ bool DelegatedFrameHost::ShouldCreateResizeLock() {
// whiteout. Because this causes the content to be drawn at wrong sizes while
// resizing we compensate by blocking the UI thread in Compositor::Draw() by
// issuing a FinishAllRendering() if we are resizing.
#if defined(OS_WIN)
// TODO(ccameron): Mac browser window resizing is incompletely implemented.
#if defined(OS_WIN) || defined(OS_MACOSX)
return false;
#else
RenderWidgetHostImpl* host = client_->GetHost();
if (resize_lock_)
return false;
......@@ -724,7 +726,7 @@ void DelegatedFrameHost::OnCompositingDidCommit(
ui::Compositor* compositor) {
RenderWidgetHostImpl* host = client_->GetHost();
if (can_lock_compositor_ == NO_PENDING_COMMIT) {
can_lock_compositor_ = YES;
can_lock_compositor_ = YES_CAN_LOCK;
if (resize_lock_.get() && resize_lock_->GrabDeferredLock())
can_lock_compositor_ = YES_DID_LOCK;
}
......
......@@ -13,7 +13,6 @@
#include "content/browser/renderer_host/delegated_frame_evictor.h"
#include "content/browser/renderer_host/dip_util.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/gpu/client/gl_helper.h"
#include "content/public/browser/render_process_host.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_observer.h"
......@@ -29,6 +28,7 @@ class VideoFrame;
namespace content {
class DelegatedFrameHost;
class ReadbackYUVInterface;
class RenderWidgetHostViewFrameSubscriber;
class RenderWidgetHostImpl;
class ResizeLock;
......@@ -258,7 +258,7 @@ class CONTENT_EXPORT DelegatedFrameHost
scoped_refptr<ui::CompositorLock> released_front_lock_;
enum CanLockCompositorState {
YES,
YES_CAN_LOCK,
// We locked, so at some point we'll need to kick a frame.
YES_DID_LOCK,
// No. A lock timed out, we need to kick a new frame before locking again.
......
......@@ -800,6 +800,13 @@ void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped(
"GpuHostMsg_AcceleratedSurfaceBuffersSwapped"))
return;
gfx::AcceleratedWidget native_widget =
GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id);
if (native_widget) {
RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnIOThread(this, params);
return;
}
gfx::GLSurfaceHandle surface_handle =
GpuSurfaceTracker::Get()->GetSurfaceHandle(params.surface_id);
// Compositor window is always gfx::kNullPluginWindow.
......
......@@ -30,10 +30,12 @@ namespace base {
class TimeDelta;
}
struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
struct ViewHostMsg_CreateWindow_Params;
struct ViewMsg_SwapOut_Params;
namespace content {
class GpuProcessHost;
class ResourceDispatcherHostImpl;
class SessionStorageNamespace;
......@@ -167,6 +169,12 @@ class RenderWidgetHelper
void FreeTransportDIB(TransportDIB::Id dib_id);
#endif
#if defined(OS_MACOSX)
static void OnNativeSurfaceBuffersSwappedOnIOThread(
GpuProcessHost* gpu_process_host,
const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params);
#endif
private:
// A class used to proxy a paint message. PaintMsgProxy objects are created
// on the IO thread and destroyed on the UI thread.
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/renderer_host/render_widget_helper.h"
#import <Cocoa/Cocoa.h>
#include "base/bind.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/gpu/gpu_surface_tracker.h"
#include "content/common/gpu/gpu_messages.h"
// Declare methods used to present swaps to this view.
@interface NSView (ContentCompositingView)
- (void)onNativeSurfaceBuffersSwappedWithParams:
(GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params;
@end
@implementation NSView (ContentCompositingView)
- (void)onNativeSurfaceBuffersSwappedWithParams:
(GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params {
}
@end
namespace {
void OnNativeSurfaceBuffersSwappedOnUIThread(
const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
gfx::AcceleratedWidget native_widget =
content::GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id);
[native_widget onNativeSurfaceBuffersSwappedWithParams:params];
}
} // namespace
namespace content {
void RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnIOThread(
GpuProcessHost* gpu_process_host,
const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// Immediately acknowledge this frame on the IO thread instead of the UI
// thread. The UI thread will wait on the GPU process. If the UI thread
// were to be responsible for acking swaps, then there would be a cycle
// and a potential deadlock.
// TODO(ccameron): This immediate ack circumvents GPU back-pressure that
// is necessary to throttle renderers. Fix that.
// TODO(ccameron): It is possible that the IOSurface will be deleted or
// reused soon as it is acked. Take out a reference to the IOSurface here,
// to ensure the IOSurface does not disappear before routing to the UI
// thread.
AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
ack_params.sync_point = 0;
ack_params.renderer_id = 0;
gpu_process_host->Send(new AcceleratedSurfaceMsg_BufferPresented(
params.route_id, ack_params));
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&OnNativeSurfaceBuffersSwappedOnUIThread, params));
}
} // namespace content
......@@ -17,6 +17,7 @@
#include "content/browser/compositor/resize_lock.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/gpu/client/gl_helper.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/host_shared_bitmap_manager.h"
#include "content/common/input_messages.h"
......
......@@ -16,6 +16,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "content/browser/compositor/delegated_frame_host.h"
#include "content/browser/renderer_host/display_link_mac.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/renderer_host/software_frame_manager.h"
......@@ -35,6 +36,11 @@ class RenderWidgetHostViewMacEditCommandHelper;
class WebContents;
}
namespace ui {
class Compositor;
class Layer;
}
@class CompositingIOSurfaceLayer;
@class FullscreenWindowManager;
@protocol RenderWidgetHostViewMacDelegate;
......@@ -214,6 +220,7 @@ class RenderWidgetHostImpl;
// RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
class CONTENT_EXPORT RenderWidgetHostViewMac
: public RenderWidgetHostViewBase,
public DelegatedFrameHostClient,
public IPC::Sender,
public SoftwareFrameManagerClient {
public:
......@@ -448,6 +455,11 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
base::DelayTimer<RenderWidgetHostViewMac>
compositing_iosurface_layer_async_timer_;
// Delegated frame management and compositior.
scoped_ptr<DelegatedFrameHost> delegated_frame_host_;
scoped_ptr<ui::Compositor> compositor_;
scoped_ptr<ui::Layer> root_layer_;
// This holds the current software compositing framebuffer, if any.
scoped_ptr<SoftwareFrameManager> software_frame_manager_;
......@@ -514,6 +526,20 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
bool HasPendingSwapAck() const { return pending_swap_ack_; }
// DelegatedFrameHostClient implementation.
virtual ui::Compositor* GetCompositor() const OVERRIDE;
virtual ui::Layer* GetLayer() OVERRIDE;
virtual RenderWidgetHostImpl* GetHost() OVERRIDE;
virtual void SchedulePaintInRect(
const gfx::Rect& damage_rect_in_dip) OVERRIDE;
virtual bool IsVisible() OVERRIDE;
virtual scoped_ptr<ResizeLock> CreateResizeLock(
bool defer_compositor_lock) OVERRIDE;
virtual gfx::Size DesiredFrameSize() OVERRIDE;
virtual float CurrentDeviceScaleFactor() OVERRIDE;
virtual gfx::Size ConvertViewSizeToPixel(const gfx::Size& size) OVERRIDE;
virtual DelegatedFrameHost* GetDelegatedFrameHost() const OVERRIDE;
private:
friend class RenderWidgetHostViewMacTest;
......
......@@ -515,7 +515,8 @@ scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateNativeSurface(
GpuChannelManager* manager,
GpuCommandBufferStub* stub,
const gfx::GLSurfaceHandle& surface_handle) {
DCHECK(surface_handle.transport_type == gfx::NATIVE_TRANSPORT);
DCHECK(surface_handle.transport_type == gfx::NATIVE_DIRECT ||
surface_handle.transport_type == gfx::NATIVE_TRANSPORT);
IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize();
switch (gfx::GetGLImplementation()) {
......
......@@ -1090,6 +1090,7 @@
'browser/renderer_host/render_view_host_impl.h',
'browser/renderer_host/render_widget_helper.cc',
'browser/renderer_host/render_widget_helper.h',
'browser/renderer_host/render_widget_helper_mac.mm',
'browser/renderer_host/render_widget_host_delegate.cc',
'browser/renderer_host/render_widget_host_delegate.h',
'browser/renderer_host/render_widget_host_impl.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment