Commit 9f9a14ca authored by ccameron's avatar ccameron Committed by Commit bot

Simplify IOSurface CoreAnimation code: Part 1

This is now only used in the context of the browser compositor, so
move the code there.

Move the software layer code over to compositor as well.

Rename structures to de-empahsize 'compositing' (everything is running
through the compositor now).

BUG=314190
TBR=kbr@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#292482}
parent 18bbc2ab
......@@ -9,8 +9,8 @@
#include "base/mac/scoped_nsobject.h"
#include "content/browser/compositor/browser_compositor_view_mac.h"
#include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
#include "content/browser/renderer_host/software_layer_mac.h"
#include "content/browser/compositor/io_surface_layer_mac.h"
#include "content/browser/compositor/software_layer_mac.h"
#include "ui/base/cocoa/remote_layer_api.h"
namespace content {
......@@ -18,7 +18,7 @@ namespace content {
// BrowserCompositorViewMacInternal owns a NSView and a ui::Compositor that
// draws that view.
class BrowserCompositorViewMacInternal
: public CompositingIOSurfaceLayerClient {
: public IOSurfaceLayerClient {
public:
BrowserCompositorViewMacInternal();
virtual ~BrowserCompositorViewMacInternal();
......@@ -50,10 +50,10 @@ class BrowserCompositorViewMacInternal
cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas);
private:
// CompositingIOSurfaceLayerClient implementation:
virtual bool AcceleratedLayerShouldAckImmediately() const OVERRIDE;
virtual void AcceleratedLayerDidDrawFrame() OVERRIDE;
virtual void AcceleratedLayerHitError() OVERRIDE;
// IOSurfaceLayerClient implementation:
virtual bool IOSurfaceLayerShouldAckImmediately() const OVERRIDE;
virtual void IOSurfaceLayerDidDrawFrame() OVERRIDE;
virtual void IOSurfaceLayerHitError() OVERRIDE;
void GotAcceleratedCAContextFrame(
CAContextID ca_context_id, gfx::Size pixel_size, float scale_factor);
......@@ -68,7 +68,7 @@ private:
void DestroyCAContextLayer(
base::scoped_nsobject<CALayerHost> ca_context_layer);
void DestroyIOSurfaceLayer(
base::scoped_nsobject<CompositingIOSurfaceLayer> io_surface_layer);
base::scoped_nsobject<IOSurfaceLayer> io_surface_layer);
void DestroySoftwareLayer();
// The client of the BrowserCompositorViewMac that is using this as its
......@@ -94,7 +94,7 @@ private:
base::scoped_nsobject<CALayerHost> ca_context_layer_;
// The locally drawn accelerated CoreAnimation layer.
base::scoped_nsobject<CompositingIOSurfaceLayer> io_surface_layer_;
base::scoped_nsobject<IOSurfaceLayer> io_surface_layer_;
// The locally drawn software layer.
base::scoped_nsobject<SoftwareLayer> software_layer_;
......
......@@ -10,11 +10,10 @@
#include "base/lazy_instance.h"
#include "base/message_loop/message_loop.h"
#include "content/browser/compositor/gpu_process_transport_factory.h"
#include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
#include "content/browser/renderer_host/compositing_iosurface_mac.h"
#include "content/browser/compositor/io_surface_layer_mac.h"
#include "content/browser/compositor/software_layer_mac.h"
#include "content/browser/renderer_host/dip_util.h"
#include "content/browser/renderer_host/render_widget_resize_helper.h"
#include "content/browser/renderer_host/software_layer_mac.h"
#include "content/common/gpu/surface_handle_types_mac.h"
#include "content/public/browser/context_factory.h"
#include "ui/base/cocoa/animation_utils.h"
......@@ -113,7 +112,7 @@ bool BrowserCompositorViewMacInternal::HasFrameOfSize(
int BrowserCompositorViewMacInternal::GetRendererID() const {
if (io_surface_layer_)
return [io_surface_layer_ iosurface]->GetRendererID();
return [io_surface_layer_ rendererID];
return 0;
}
......@@ -137,7 +136,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedFrame(
// If there is no client and therefore no superview to draw into, early-out.
if (!client_) {
AcceleratedLayerDidDrawFrame();
IOSurfaceLayerDidDrawFrame();
return;
}
......@@ -183,7 +182,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedCAContextFrame(
// Acknowledge the frame to unblock the compositor immediately (the GPU
// process will do any required throttling).
AcceleratedLayerDidDrawFrame();
IOSurfaceLayerDidDrawFrame();
// If this replacing a same-type layer, remove it now that the new layer is
// in the hierarchy.
......@@ -201,7 +200,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
float scale_factor) {
// In the layer is replaced, keep the old one around until after the new one
// is installed to avoid flashes.
base::scoped_nsobject<CompositingIOSurfaceLayer> old_io_surface_layer =
base::scoped_nsobject<IOSurfaceLayer> old_io_surface_layer =
io_surface_layer_;
// Create or re-create an IOSurface layer if needed. If there already exists
......@@ -209,35 +208,26 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
// layer.
bool needs_new_layer =
!io_surface_layer_ ||
[io_surface_layer_ context]->HasBeenPoisoned() ||
[io_surface_layer_ iosurface]->scale_factor() != scale_factor;
[io_surface_layer_ hasBeenPoisoned] ||
[io_surface_layer_ scaleFactor] != scale_factor;
if (needs_new_layer) {
scoped_refptr<content::CompositingIOSurfaceMac> iosurface =
content::CompositingIOSurfaceMac::Create();
if (!iosurface) {
LOG(ERROR) << "Failed to create CompositingIOSurfaceMac";
} else {
io_surface_layer_.reset([[CompositingIOSurfaceLayer alloc]
initWithIOSurface:iosurface
withScaleFactor:scale_factor
withClient:this]);
if (io_surface_layer_)
[flipped_layer_ addSublayer:io_surface_layer_];
else
LOG(ERROR) << "Failed to create CompositingIOSurfaceLayer";
}
io_surface_layer_.reset(
[[IOSurfaceLayer alloc] initWithClient:this
withScaleFactor:scale_factor]);
if (io_surface_layer_)
[flipped_layer_ addSublayer:io_surface_layer_];
else
LOG(ERROR) << "Failed to create IOSurfaceLayer";
}
// Open the provided IOSurface.
if (io_surface_layer_) {
bool result = true;
gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
[io_surface_layer_ context]->cgl_context());
result = [io_surface_layer_ iosurface]->SetIOSurfaceWithContextCurrent(
[io_surface_layer_ context], io_surface_id, pixel_size, scale_factor);
bool result = [io_surface_layer_ gotFrameWithIOSurface:io_surface_id
withPixelSize:pixel_size
withScaleFactor:scale_factor];
if (!result) {
DestroyIOSurfaceLayer(io_surface_layer_);
LOG(ERROR) << "Failed open IOSurface in CompositingIOSurfaceLayer";
LOG(ERROR) << "Failed open IOSurface in IOSurfaceLayer";
}
}
......@@ -245,8 +235,8 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
// This frame will appear blank, the compositor will try to create another,
// and maybe that will go better.
if (!io_surface_layer_) {
LOG(ERROR) << "CompositingIOSurfaceLayer is nil, tab will be blank";
AcceleratedLayerHitError();
LOG(ERROR) << "IOSurfaceLayer is nil, tab will be blank";
IOSurfaceLayerHitError();
}
// Make the CALayer draw and set its size appropriately.
......@@ -316,7 +306,7 @@ void BrowserCompositorViewMacInternal::DestroyCAContextLayer(
}
void BrowserCompositorViewMacInternal::DestroyIOSurfaceLayer(
base::scoped_nsobject<CompositingIOSurfaceLayer> io_surface_layer) {
base::scoped_nsobject<IOSurfaceLayer> io_surface_layer) {
if (!io_surface_layer)
return;
[io_surface_layer resetClient];
......@@ -332,7 +322,7 @@ void BrowserCompositorViewMacInternal::DestroySoftwareLayer() {
software_layer_.reset();
}
bool BrowserCompositorViewMacInternal::AcceleratedLayerShouldAckImmediately()
bool BrowserCompositorViewMacInternal::IOSurfaceLayerShouldAckImmediately()
const {
// If there is no client then the accelerated layer is not in the hierarchy
// and will never draw.
......@@ -341,7 +331,7 @@ bool BrowserCompositorViewMacInternal::AcceleratedLayerShouldAckImmediately()
return client_->BrowserCompositorViewShouldAckImmediately();
}
void BrowserCompositorViewMacInternal::AcceleratedLayerDidDrawFrame() {
void BrowserCompositorViewMacInternal::IOSurfaceLayerDidDrawFrame() {
if (accelerated_output_surface_id_) {
content::ImageTransportFactory::GetInstance()->OnSurfaceDisplayed(
accelerated_output_surface_id_);
......@@ -354,14 +344,13 @@ void BrowserCompositorViewMacInternal::AcceleratedLayerDidDrawFrame() {
accelerated_latency_info_.clear();
}
void BrowserCompositorViewMacInternal::AcceleratedLayerHitError() {
void BrowserCompositorViewMacInternal::IOSurfaceLayerHitError() {
// Perform all acks that would have been done if the frame had succeeded, to
// un-block the compositor and renderer.
AcceleratedLayerDidDrawFrame();
IOSurfaceLayerDidDrawFrame();
// Poison the context being used and request a mulligan.
if (io_surface_layer_)
[io_surface_layer_ context]->PoisonContextAndSharegroup();
[io_surface_layer_ poisonContextAndSharegroup];
compositor_->ScheduleFullRedraw();
}
......
......@@ -10,53 +10,54 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/ref_counted.h"
#include "base/timer/timer.h"
#include "ui/gfx/size.h"
@class CompositingIOSurfaceLayer;
@class IOSurfaceLayer;
namespace content {
class CompositingIOSurfaceMac;
class CompositingIOSurfaceContext;
// The interface through which the CompositingIOSurfaceLayer calls back into
// The interface through which the IOSurfaceLayer calls back into
// the structrue that created it (RenderWidgetHostViewMac or
// BrowserCompositorViewMac).
class CompositingIOSurfaceLayerClient {
class IOSurfaceLayerClient {
public:
// Used to indicate that the layer should attempt to draw immediately and
// should (even if the draw is elided by the system), ack the frame
// immediately.
virtual bool AcceleratedLayerShouldAckImmediately() const = 0;
virtual bool IOSurfaceLayerShouldAckImmediately() const = 0;
// Called when a frame is drawn or when, because the layer is not visible, it
// is known that the frame will never drawn.
virtual void AcceleratedLayerDidDrawFrame() = 0;
virtual void IOSurfaceLayerDidDrawFrame() = 0;
// Called when an error prevents the frame from being drawn.
virtual void AcceleratedLayerHitError() = 0;
virtual void IOSurfaceLayerHitError() = 0;
};
// CompositingIOSurfaceLayerHelper provides C++ functionality needed for the
// CompositingIOSurfaceLayer class, and does most of the heavy lifting for the
// IOSurfaceLayerHelper provides C++ functionality needed for the
// IOSurfaceLayer class, and does most of the heavy lifting for the
// class.
// TODO(ccameron): This class should own CompositingIOSurfaceLayer, rather than
// TODO(ccameron): This class should own IOSurfaceLayer, rather than
// vice versa.
class CompositingIOSurfaceLayerHelper {
class IOSurfaceLayerHelper {
public:
CompositingIOSurfaceLayerHelper(CompositingIOSurfaceLayerClient* client,
CompositingIOSurfaceLayer* layer);
~CompositingIOSurfaceLayerHelper();
IOSurfaceLayerHelper(IOSurfaceLayerClient* client,
IOSurfaceLayer* layer);
~IOSurfaceLayerHelper();
// Called when the CompositingIOSurfaceLayer gets a new frame.
// Called when the IOSurfaceLayer gets a new frame.
void GotNewFrame();
// Called whenever -[CompositingIOSurfaceLayer setNeedsDisplay] is called.
// Called whenever -[IOSurfaceLayer setNeedsDisplay] is called.
void SetNeedsDisplay();
// Called whenever -[CompositingIOSurfaceLayer canDrawInCGLContext] is called,
// Called whenever -[IOSurfaceLayer canDrawInCGLContext] is called,
// to determine if a new frame should be drawn.
bool CanDraw();
// Called whenever -[CompositingIOSurfaceLayer drawInCGLContext] draws a
// Called whenever -[IOSurfaceLayer drawInCGLContext] draws a
// frame.
void DidDraw(bool success);
......@@ -83,10 +84,10 @@ class CompositingIOSurfaceLayerHelper {
void TimerFired();
// The client that the owning layer was created with.
content::CompositingIOSurfaceLayerClient* const client_;
content::IOSurfaceLayerClient* const client_;
// The layer that owns this helper.
CompositingIOSurfaceLayer* const layer_;
IOSurfaceLayer* const layer_;
// Used to track when canDrawInCGLContext should return YES. This can be
// in response to receiving a new compositor frame, or from any of the events
......@@ -107,27 +108,35 @@ class CompositingIOSurfaceLayerHelper {
// calls until they appear on the screen. This can lead to hangs if the
// view is moved offscreen (among other things). Prevent hangs by always
// acknowledging the frame after timeout of 1/6th of a second has passed.
base::DelayTimer<CompositingIOSurfaceLayerHelper> timer_;
base::DelayTimer<IOSurfaceLayerHelper> timer_;
};
} // namespace content
// The CoreAnimation layer for drawing accelerated content.
@interface CompositingIOSurfaceLayer : CAOpenGLLayer {
@interface IOSurfaceLayer : CAOpenGLLayer {
@private
scoped_refptr<content::CompositingIOSurfaceMac> iosurface_;
scoped_refptr<content::CompositingIOSurfaceContext> context_;
scoped_ptr<content::CompositingIOSurfaceLayerHelper> helper_;
scoped_ptr<content::IOSurfaceLayerHelper> helper_;
}
- (content::CompositingIOSurfaceMac*)iosurface;
- (content::CompositingIOSurfaceContext*)context;
- (id)initWithClient:(content::IOSurfaceLayerClient*)client
withScaleFactor:(float)scale_factor;
- (id)initWithIOSurface:(scoped_refptr<content::CompositingIOSurfaceMac>)
iosurface
withScaleFactor:(float)scale_factor
withClient:(content::CompositingIOSurfaceLayerClient*)client;
- (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id
withPixelSize:(gfx::Size)pixel_size
withScaleFactor:(float)scale_factor;
// Context poison accessors.
- (void)poisonContextAndSharegroup;
- (bool)hasBeenPoisoned;
- (float)scaleFactor;
// The CGL renderer ID.
- (int)rendererID;
// Mark that the client is no longer valid and cannot be called back into. This
// must be called before the layer is destroyed.
......
......@@ -2,7 +2,7 @@
// 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/compositing_iosurface_layer_mac.h"
#include "content/browser/compositor/io_surface_layer_mac.h"
#include <CoreFoundation/CoreFoundation.h>
#include <OpenGL/gl.h>
......@@ -18,13 +18,13 @@
#include "ui/gl/gpu_switching_manager.h"
////////////////////////////////////////////////////////////////////////////////
// CompositingIOSurfaceLayerHelper
// IOSurfaceLayerHelper
namespace content {
CompositingIOSurfaceLayerHelper::CompositingIOSurfaceLayerHelper(
CompositingIOSurfaceLayerClient* client,
CompositingIOSurfaceLayer* layer)
IOSurfaceLayerHelper::IOSurfaceLayerHelper(
IOSurfaceLayerClient* client,
IOSurfaceLayer* layer)
: client_(client),
layer_(layer),
needs_display_(false),
......@@ -35,15 +35,15 @@ CompositingIOSurfaceLayerHelper::CompositingIOSurfaceLayerHelper(
FROM_HERE,
base::TimeDelta::FromSeconds(1) / 6,
this,
&CompositingIOSurfaceLayerHelper::TimerFired) {}
&IOSurfaceLayerHelper::TimerFired) {}
CompositingIOSurfaceLayerHelper::~CompositingIOSurfaceLayerHelper() {
IOSurfaceLayerHelper::~IOSurfaceLayerHelper() {
// Any acks that were waiting on this layer to draw will not occur, so ack
// them now to prevent blocking the renderer.
AckPendingFrame(true);
}
void CompositingIOSurfaceLayerHelper::GotNewFrame() {
void IOSurfaceLayerHelper::GotNewFrame() {
// A trace value of 2 indicates that there is a pending swap ack. See
// canDrawInCGLContext for other value meanings.
TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 2);
......@@ -56,7 +56,7 @@ void CompositingIOSurfaceLayerHelper::GotNewFrame() {
// isAsynchronous property to ensure smooth animation. If this is while
// frames are being pumped then ack and display immediately to get a
// correct-sized frame displayed as soon as possible.
if (is_pumping_frames_ || client_->AcceleratedLayerShouldAckImmediately()) {
if (is_pumping_frames_ || client_->IOSurfaceLayerShouldAckImmediately()) {
SetNeedsDisplayAndDisplayAndAck();
} else {
if (![layer_ isAsynchronous])
......@@ -64,11 +64,11 @@ void CompositingIOSurfaceLayerHelper::GotNewFrame() {
}
}
void CompositingIOSurfaceLayerHelper::SetNeedsDisplay() {
void IOSurfaceLayerHelper::SetNeedsDisplay() {
needs_display_ = true;
}
bool CompositingIOSurfaceLayerHelper::CanDraw() {
bool IOSurfaceLayerHelper::CanDraw() {
// If we return NO 30 times in a row, switch to being synchronous to avoid
// burning CPU cycles on this callback.
if (needs_display_) {
......@@ -93,24 +93,24 @@ bool CompositingIOSurfaceLayerHelper::CanDraw() {
return needs_display_;
}
void CompositingIOSurfaceLayerHelper::DidDraw(bool success) {
void IOSurfaceLayerHelper::DidDraw(bool success) {
needs_display_ = false;
AckPendingFrame(success);
}
void CompositingIOSurfaceLayerHelper::AckPendingFrame(bool success) {
void IOSurfaceLayerHelper::AckPendingFrame(bool success) {
if (!has_pending_frame_)
return;
has_pending_frame_ = false;
if (success)
client_->AcceleratedLayerDidDrawFrame();
client_->IOSurfaceLayerDidDrawFrame();
else
client_->AcceleratedLayerHitError();
client_->IOSurfaceLayerHitError();
// A trace value of 0 indicates that there is no longer a pending swap ack.
TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 0);
}
void CompositingIOSurfaceLayerHelper::SetNeedsDisplayAndDisplayAndAck() {
void IOSurfaceLayerHelper::SetNeedsDisplayAndDisplayAndAck() {
// Drawing using setNeedsDisplay and displayIfNeeded will result in
// subsequent canDrawInCGLContext callbacks getting dropped, and jerky
// animation. Disable asynchronous drawing before issuing these calls as a
......@@ -123,7 +123,7 @@ void CompositingIOSurfaceLayerHelper::SetNeedsDisplayAndDisplayAndAck() {
DisplayIfNeededAndAck();
}
void CompositingIOSurfaceLayerHelper::DisplayIfNeededAndAck() {
void IOSurfaceLayerHelper::DisplayIfNeededAndAck() {
if (!needs_display_)
return;
......@@ -145,15 +145,15 @@ void CompositingIOSurfaceLayerHelper::DisplayIfNeededAndAck() {
AckPendingFrame(true);
}
void CompositingIOSurfaceLayerHelper::TimerFired() {
void IOSurfaceLayerHelper::TimerFired() {
SetNeedsDisplayAndDisplayAndAck();
}
void CompositingIOSurfaceLayerHelper::BeginPumpingFrames() {
void IOSurfaceLayerHelper::BeginPumpingFrames() {
is_pumping_frames_ = true;
}
void CompositingIOSurfaceLayerHelper::EndPumpingFrames() {
void IOSurfaceLayerHelper::EndPumpingFrames() {
is_pumping_frames_ = false;
DisplayIfNeededAndAck();
}
......@@ -161,9 +161,9 @@ void CompositingIOSurfaceLayerHelper::EndPumpingFrames() {
} // namespace content
////////////////////////////////////////////////////////////////////////////////
// CompositingIOSurfaceLayer
// IOSurfaceLayer
@implementation CompositingIOSurfaceLayer
@implementation IOSurfaceLayer
- (content::CompositingIOSurfaceMac*)iosurface {
return iosurface_.get();
......@@ -173,19 +173,16 @@ void CompositingIOSurfaceLayerHelper::EndPumpingFrames() {
return context_.get();
}
- (id)initWithIOSurface:(scoped_refptr<content::CompositingIOSurfaceMac>)
iosurface
withScaleFactor:(float)scale_factor
withClient:(content::CompositingIOSurfaceLayerClient*)client {
DCHECK(iosurface);
- (id)initWithClient:(content::IOSurfaceLayerClient*)client
withScaleFactor:(float)scale_factor {
if (self = [super init]) {
helper_.reset(new content::CompositingIOSurfaceLayerHelper(client, self));
helper_.reset(new content::IOSurfaceLayerHelper(client, self));
iosurface_ = iosurface;
iosurface_ = content::CompositingIOSurfaceMac::Create();
context_ = content::CompositingIOSurfaceContext::Get(
content::CompositingIOSurfaceContext::kCALayerContextWindowNumber);
if (!context_) {
LOG(ERROR) << "Failed create CompositingIOSurfaceContext";
if (!iosurface_ || !context_) {
LOG(ERROR) << "Failed create CompositingIOSurface or context";
[self resetClient];
[self release];
return nil;
......@@ -208,6 +205,33 @@ void CompositingIOSurfaceLayerHelper::EndPumpingFrames() {
[super dealloc];
}
- (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id
withPixelSize:(gfx::Size)pixel_size
withScaleFactor:(float)scale_factor {
bool result = true;
gfx::ScopedCGLSetCurrentContext scoped_set_current_context(
context_->cgl_context());
result = iosurface_->SetIOSurfaceWithContextCurrent(
context_, io_surface_id, pixel_size, scale_factor);
return result;
}
- (void)poisonContextAndSharegroup {
context_->PoisonContextAndSharegroup();
}
- (bool)hasBeenPoisoned {
return context_->HasBeenPoisoned();
}
- (float)scaleFactor {
return iosurface_->scale_factor();
}
- (int)rendererID {
return iosurface_->GetRendererID();
}
- (void)resetClient {
helper_.reset();
}
......@@ -265,7 +289,7 @@ void CompositingIOSurfaceLayerHelper::EndPumpingFrames() {
pixelFormat:(CGLPixelFormatObj)pixelFormat
forLayerTime:(CFTimeInterval)timeInterval
displayTime:(const CVTimeStamp*)timeStamp {
TRACE_EVENT0("browser", "CompositingIOSurfaceLayer::drawInCGLContext");
TRACE_EVENT0("browser", "IOSurfaceLayer::drawInCGLContext");
if (!iosurface_->HasIOSurface() || context_->cgl_context() != glContext) {
glClearColor(1, 1, 1, 1);
......
......@@ -2,7 +2,7 @@
// 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/software_layer_mac.h"
#include "content/browser/compositor/software_layer_mac.h"
#include "base/debug/trace_event.h"
#include "base/mac/mac_util.h"
......
......@@ -19,7 +19,7 @@
#include "base/time/time.h"
#include "content/browser/compositor/browser_compositor_view_mac.h"
#include "content/browser/compositor/delegated_frame_host.h"
#include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
#include "content/browser/compositor/io_surface_layer_mac.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"
......@@ -207,7 +207,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
public DelegatedFrameHostClient,
public BrowserCompositorViewMacClient,
public IPC::Sender,
public CompositingIOSurfaceLayerClient,
public gfx::DisplayObserver {
public:
// The view will associate itself with the given widget. The native view must
......@@ -329,11 +328,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
virtual SkColorType PreferredReadbackFormat() OVERRIDE;
// CompositingIOSurfaceLayerClient implementation.
virtual bool AcceleratedLayerShouldAckImmediately() const OVERRIDE;
virtual void AcceleratedLayerDidDrawFrame() OVERRIDE;
virtual void AcceleratedLayerHitError() OVERRIDE;
// gfx::DisplayObserver implementation.
virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
......
......@@ -30,19 +30,17 @@
#include "content/browser/accessibility/browser_accessibility_manager_mac.h"
#import "content/browser/cocoa/system_hotkey_helper_mac.h"
#import "content/browser/cocoa/system_hotkey_map.h"
#include "content/browser/compositor/io_surface_layer_mac.h"
#include "content/browser/compositor/resize_lock.h"
#include "content/browser/compositor/software_layer_mac.h"
#include "content/browser/frame_host/frame_tree.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
#include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
#include "content/browser/renderer_host/compositing_iosurface_mac.h"
#include "content/browser/renderer_host/render_widget_helper.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_helper.h"
#import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_helper.h"
#import "content/browser/renderer_host/software_layer_mac.h"
#import "content/browser/renderer_host/text_input_client_mac.h"
#include "content/common/accessibility_messages.h"
#include "content/common/edit_command.h"
......@@ -452,8 +450,44 @@ DelegatedFrameHost* RenderWidgetHostViewMac::GetDelegatedFrameHost() const {
bool RenderWidgetHostViewMac::BrowserCompositorViewShouldAckImmediately()
const {
// The logic for delegated and non-delegated rendering is the same.
return AcceleratedLayerShouldAckImmediately();
// If vsync is disabled, then always draw and ack frames immediately.
static bool is_vsync_disabled =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuVsync);
if (is_vsync_disabled)
return true;
// If the window is occluded, then this frame's display call may be severely
// throttled. This is a good thing, unless tab capture may be active, because
// the broadcast will be inappropriately throttled.
// http://crbug.com/350410
// If tab capture isn't active then only ack frames when we draw them.
if (delegated_frame_host_ && !delegated_frame_host_->HasFrameSubscriber())
return false;
NSWindow* window = [cocoa_view_ window];
// If the view isn't even in the heirarchy then frames will never be drawn,
// so ack them immediately.
if (!window)
return true;
// Check the window occlusion API.
if ([window respondsToSelector:@selector(occlusionState)]) {
if ([window occlusionState] & NSWindowOcclusionStateVisible) {
// If the window is visible then it is safe to wait until frames are
// drawn to ack them.
return false;
} else {
// If the window is occluded then frames may never be drawn, so ack them
// immediately.
return true;
}
}
// If the window occlusion API is not present then ack frames when we draw
// them.
return false;
}
void RenderWidgetHostViewMac::BrowserCompositorViewFrameSwapped(
......@@ -1593,56 +1627,6 @@ SkColorType RenderWidgetHostViewMac::PreferredReadbackFormat() {
return kN32_SkColorType;
}
////////////////////////////////////////////////////////////////////////////////
// CompositingIOSurfaceLayerClient, public:
bool RenderWidgetHostViewMac::AcceleratedLayerShouldAckImmediately() const {
// If vsync is disabled, then always draw and ack frames immediately.
static bool is_vsync_disabled =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuVsync);
if (is_vsync_disabled)
return true;
// If the window is occluded, then this frame's display call may be severely
// throttled. This is a good thing, unless tab capture may be active, because
// the broadcast will be inappropriately throttled.
// http://crbug.com/350410
// If tab capture isn't active then only ack frames when we draw them.
if (delegated_frame_host_ && !delegated_frame_host_->HasFrameSubscriber())
return false;
NSWindow* window = [cocoa_view_ window];
// If the view isn't even in the heirarchy then frames will never be drawn,
// so ack them immediately.
if (!window)
return true;
// Check the window occlusion API.
if ([window respondsToSelector:@selector(occlusionState)]) {
if ([window occlusionState] & NSWindowOcclusionStateVisible) {
// If the window is visible then it is safe to wait until frames are
// drawn to ack them.
return false;
} else {
// If the window is occluded then frames may never be drawn, so ack them
// immediately.
return true;
}
}
// If the window occlusion API is not present then ack frames when we draw
// them.
return false;
}
void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame() {
}
void RenderWidgetHostViewMac::AcceleratedLayerHitError() {
}
////////////////////////////////////////////////////////////////////////////////
// gfx::DisplayObserver, public:
......
......@@ -911,8 +911,6 @@
'browser/renderer_host/clipboard_message_filter_mac.mm',
'browser/renderer_host/compositing_iosurface_context_mac.h',
'browser/renderer_host/compositing_iosurface_context_mac.mm',
'browser/renderer_host/compositing_iosurface_layer_mac.h',
'browser/renderer_host/compositing_iosurface_layer_mac.mm',
'browser/renderer_host/compositing_iosurface_mac.h',
'browser/renderer_host/compositing_iosurface_mac.mm',
'browser/renderer_host/compositor_impl_android.cc',
......@@ -1087,8 +1085,6 @@
'browser/renderer_host/sandbox_ipc_linux.h',
'browser/renderer_host/software_frame_manager.cc',
'browser/renderer_host/software_frame_manager.h',
'browser/renderer_host/software_layer_mac.mm',
'browser/renderer_host/software_layer_mac.h',
'browser/renderer_host/socket_stream_dispatcher_host.cc',
'browser/renderer_host/socket_stream_dispatcher_host.h',
'browser/renderer_host/socket_stream_host.cc',
......@@ -1425,6 +1421,8 @@
'browser/compositor/gpu_process_transport_factory.h',
'browser/compositor/image_transport_factory.cc',
'browser/compositor/image_transport_factory.h',
'browser/compositor/io_surface_layer_mac.h',
'browser/compositor/io_surface_layer_mac.mm',
'browser/compositor/onscreen_display_client.cc',
'browser/compositor/onscreen_display_client.h',
'browser/compositor/overlay_candidate_validator_ozone.cc',
......@@ -1435,6 +1433,8 @@
'browser/compositor/reflector_impl.h',
'browser/compositor/resize_lock.cc',
'browser/compositor/resize_lock.h',
'browser/compositor/software_layer_mac.mm',
'browser/compositor/software_layer_mac.h',
'browser/compositor/gpu_browser_compositor_output_surface.cc',
'browser/compositor/gpu_browser_compositor_output_surface.h',
'browser/compositor/software_browser_compositor_output_surface.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