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