Commit 8af59efe authored by kbr's avatar kbr Committed by Commit bot

Revert IOSurface CoreAnimation simplifications on ccameron@'s advice.

Contains:

Revert "Workaround to prevent crashes when destroying CGL contexts"
This reverts commit 282049cc.

Revert "Log erros while presenting an IOSurface to about:gpu"
This reverts commit 090e36f0.

Revert "Simplify IOSurface CoreAnimation code: Part 2"
This reverts commit 672e23e9.
Resolved conflicts:
	content/browser/compositor/io_surface_layer_mac.mm

Fixed call ccameron@ pointed out in: https://codereview.chromium.org/490393002/diff/260001/content/browser/compositor/io_surface_layer_mac.mm#oldcode149

Build fixes for recent scoped_refptr changes.

BUG=314190,408986,411782
R=piman@chromium.org
TBR=ccameron@chromium.org,pfeldman@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#296449}
parent 978d46da
...@@ -208,6 +208,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame( ...@@ -208,6 +208,7 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
// layer. // layer.
bool needs_new_layer = bool needs_new_layer =
!io_surface_layer_ || !io_surface_layer_ ||
[io_surface_layer_ hasBeenPoisoned] ||
[io_surface_layer_ scaleFactor] != scale_factor; [io_surface_layer_ scaleFactor] != scale_factor;
if (needs_new_layer) { if (needs_new_layer) {
io_surface_layer_.reset( io_surface_layer_.reset(
...@@ -220,12 +221,28 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame( ...@@ -220,12 +221,28 @@ void BrowserCompositorViewMacInternal::GotAcceleratedIOSurfaceFrame(
} }
// Open the provided IOSurface. // Open the provided IOSurface.
[io_surface_layer_ gotFrameWithIOSurface:io_surface_id if (io_surface_layer_) {
withPixelSize:pixel_size bool result = [io_surface_layer_ gotFrameWithIOSurface:io_surface_id
withScaleFactor:scale_factor]; withPixelSize:pixel_size
withScaleFactor:scale_factor];
if (!result) {
DestroyIOSurfaceLayer(io_surface_layer_);
LOG(ERROR) << "Failed open IOSurface in IOSurfaceLayer";
}
}
// Give a final complaint if anything with the layer's creation went wrong.
// This frame will appear blank, the compositor will try to create another,
// and maybe that will go better.
if (!io_surface_layer_) {
LOG(ERROR) << "IOSurfaceLayer is nil, tab will be blank";
IOSurfaceLayerHitError();
}
// Make the CALayer draw and set its size appropriately. // Make the CALayer draw and set its size appropriately.
if (io_surface_layer_) { if (io_surface_layer_) {
[io_surface_layer_ gotNewFrame];
// Set the bounds of the accelerated layer to match the size of the frame. // Set the bounds of the accelerated layer to match the size of the frame.
// If the bounds changed, force the content to be displayed immediately. // If the bounds changed, force the content to be displayed immediately.
CGRect new_layer_bounds = CGRectMake( CGRect new_layer_bounds = CGRectMake(
...@@ -328,8 +345,12 @@ void BrowserCompositorViewMacInternal::IOSurfaceLayerDidDrawFrame() { ...@@ -328,8 +345,12 @@ void BrowserCompositorViewMacInternal::IOSurfaceLayerDidDrawFrame() {
} }
void BrowserCompositorViewMacInternal::IOSurfaceLayerHitError() { void BrowserCompositorViewMacInternal::IOSurfaceLayerHitError() {
// Perform all acks that would have been done if the frame had succeeded, to
// un-block the compositor and renderer.
IOSurfaceLayerDidDrawFrame();
// Poison the context being used and request a mulligan. // Poison the context being used and request a mulligan.
DestroyIOSurfaceLayer(io_surface_layer_); [io_surface_layer_ poisonContextAndSharegroup];
compositor_->ScheduleFullRedraw(); compositor_->ScheduleFullRedraw();
} }
......
...@@ -2,22 +2,21 @@ ...@@ -2,22 +2,21 @@
// 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.
#ifndef CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_LAYER_MAC_H_ #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_
#define CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_LAYER_MAC_H_ #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include <IOSurface/IOSurfaceAPI.h>
#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" #include "ui/gfx/size.h"
#include "ui/gl/scoped_cgl.h"
@class IOSurfaceLayer; @class IOSurfaceLayer;
namespace content { namespace content {
class IOSurfaceLayerHelper; class CompositingIOSurfaceMac;
class CompositingIOSurfaceContext;
// The interface through which the IOSurfaceLayer 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
...@@ -37,13 +36,58 @@ class IOSurfaceLayerClient { ...@@ -37,13 +36,58 @@ class IOSurfaceLayerClient {
virtual void IOSurfaceLayerHitError() = 0; virtual void IOSurfaceLayerHitError() = 0;
}; };
} // namespace content // 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 IOSurfaceLayer, rather than
// vice versa.
class IOSurfaceLayerHelper {
public:
IOSurfaceLayerHelper(IOSurfaceLayerClient* client,
IOSurfaceLayer* layer);
~IOSurfaceLayerHelper();
// The CoreAnimation layer for drawing accelerated content. // Called when the IOSurfaceLayer gets a new frame.
@interface IOSurfaceLayer : CAOpenGLLayer { void GotNewFrame();
@private
content::IOSurfaceLayerClient* client_; // Called whenever -[IOSurfaceLayer setNeedsDisplay] is called.
scoped_ptr<content::IOSurfaceLayerHelper> helper_; void SetNeedsDisplay();
// Called whenever -[IOSurfaceLayer canDrawInCGLContext] is called,
// to determine if a new frame should be drawn.
bool CanDraw();
// Called whenever -[IOSurfaceLayer drawInCGLContext] draws a
// frame.
void DidDraw(bool success);
// Immediately re-draw the layer, even if the content has not changed, and
// ensure that the frame be acked.
void SetNeedsDisplayAndDisplayAndAck();
// Immediately draw the layer, only if one is pending, and ensure that the
// frame be acked.
void DisplayIfNeededAndAck();
// Mark a bracket in which new frames are being pumped in a restricted nested
// run loop. During this time frames are acked immediately and draws are
// deferred until the bracket ends.
void BeginPumpingFrames();
void EndPumpingFrames();
private:
// Called whenever the frame provided in GotNewFrame should be acknowledged
// (this may be because it was drawn, or it may be to unblock the
// compositor).
void AckPendingFrame(bool success);
void TimerFired();
// The client that the owning layer was created with.
content::IOSurfaceLayerClient* const client_;
// The layer that owns this helper.
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
...@@ -60,32 +104,35 @@ class IOSurfaceLayerClient { ...@@ -60,32 +104,35 @@ class IOSurfaceLayerClient {
// Set when inside a BeginPumpingFrames/EndPumpingFrames block. // Set when inside a BeginPumpingFrames/EndPumpingFrames block.
bool is_pumping_frames_; bool is_pumping_frames_;
// The IOSurface being drawn by this layer. // The browser places back-pressure on the GPU by not acknowledging swap
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; // 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<IOSurfaceLayerHelper> timer_;
};
// The size of the frame in pixels. This will be less or equal than the pixel } // namespace content
// size of |io_surface_|.
gfx::Size frame_pixel_size_;
// The GL texture that was bound to |io_surface_| during the last draw call, // The CoreAnimation layer for drawing accelerated content.
// along with the context that was done in, and the value of |io_surface_| at @interface IOSurfaceLayer : CAOpenGLLayer {
// the time of the bind. @private
GLuint io_surface_texture_; scoped_refptr<content::CompositingIOSurfaceMac> iosurface_;
base::ScopedTypeRef<CGLContextObj> io_surface_texture_context_; scoped_refptr<content::CompositingIOSurfaceContext> context_;
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_texture_io_surface_;
// The CGL renderer ID, captured at draw time. scoped_ptr<content::IOSurfaceLayerHelper> helper_;
GLint cgl_renderer_id_;
} }
- (id)initWithClient:(content::IOSurfaceLayerClient*)client - (id)initWithClient:(content::IOSurfaceLayerClient*)client
withScaleFactor:(float)scale_factor; withScaleFactor:(float)scale_factor;
// Called when a new frame is received. - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id
- (void)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id
withPixelSize:(gfx::Size)pixel_size withPixelSize:(gfx::Size)pixel_size
withScaleFactor:(float)scale_factor; withScaleFactor:(float)scale_factor;
// Context poison accessors.
- (void)poisonContextAndSharegroup;
- (bool)hasBeenPoisoned;
- (float)scaleFactor; - (float)scaleFactor;
// The CGL renderer ID. // The CGL renderer ID.
...@@ -95,14 +142,20 @@ class IOSurfaceLayerClient { ...@@ -95,14 +142,20 @@ class IOSurfaceLayerClient {
// must be called before the layer is destroyed. // must be called before the layer is destroyed.
- (void)resetClient; - (void)resetClient;
// Called when a new frame is received.
- (void)gotNewFrame;
// Force a draw immediately (even if this means re-displaying a previously // Force a draw immediately (even if this means re-displaying a previously
// displayed frame). // displayed frame).
- (void)setNeedsDisplayAndDisplayAndAck; - (void)setNeedsDisplayAndDisplayAndAck;
// Force a draw immediately, but only if one was requested.
- (void)displayIfNeededAndAck;
// Mark a bracket in which new frames are being pumped in a restricted nested // Mark a bracket in which new frames are being pumped in a restricted nested
// run loop. // run loop.
- (void)beginPumpingFrames; - (void)beginPumpingFrames;
- (void)endPumpingFrames; - (void)endPumpingFrames;
@end @end
#endif // CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_LAYER_MAC_H_ #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_
...@@ -125,9 +125,9 @@ IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest, MAYBE_CaptureScreenshot) { ...@@ -125,9 +125,9 @@ IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest, MAYBE_CaptureScreenshot) {
gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(png.data()), gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(png.data()),
png.size(), &bitmap); png.size(), &bitmap);
SkColor color(bitmap.getColor(0, 0)); SkColor color(bitmap.getColor(0, 0));
EXPECT_LE(std::abs(0x12-(int)SkColorGetR(color)), 1); EXPECT_TRUE(std::abs(0x12-(int)SkColorGetR(color)) <= 1);
EXPECT_LE(std::abs(0x34-(int)SkColorGetG(color)), 1); EXPECT_TRUE(std::abs(0x34-(int)SkColorGetG(color)) <= 1);
EXPECT_LE(std::abs(0x56-(int)SkColorGetB(color)), 1); EXPECT_TRUE(std::abs(0x56-(int)SkColorGetB(color)) <= 1);
} }
} // namespace content } // namespace content
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