summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkbr <kbr@chromium.org>2015-08-09 11:54:45 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-09 18:55:24 +0000
commit9f6cac12a46fb8960d4dc25ae5901906697a45f8 (patch)
tree9a8fd50c6d252c7b8ed9706c25e18351044eb697
parentd8f5fd8d5d5cb7b8da7a338eff3da10167e2ae04 (diff)
downloadchromium_src-9f6cac12a46fb8960d4dc25ae5901906697a45f8.zip
chromium_src-9f6cac12a46fb8960d4dc25ae5901906697a45f8.tar.gz
chromium_src-9f6cac12a46fb8960d4dc25ae5901906697a45f8.tar.bz2
Revert of Mac Overlays: Add GPU back-pressure (patchset #8 id:140001 of https://codereview.chromium.org/1273563002/ )
Reason for revert: This broke the WebGL 2.0 prototype on Mac OS -- please see https://code.google.com/p/chromium/issues/detail?id=515696#c16 for details. Original issue's description: > Mac Overlays: Add GPU back-pressure > > Issue a GL fence after every SwapBuffers. Do not call -[CALayer > setContents:] with the content being rendered by that SwapBuffers until > the fence has passed. > > Query the previous's frame's GL fence at the beginning of each > SwapBuffers. Also issue a callback to query the GL fence at the > mid-point of the VSync period (if there is no subsequent SwapBuffers, > or if the frame takes more than one VSync to render). > > Note that waiting for the GL fence to complete before calling -[CALayer > setContents] is not required for correctness -- only the expected content > (everything before the glFlush) will appear in the layer. Rather, the > reason for waiting for the GL fence is to make the time at which the > content will appear on-screen more reliable. > > Because there may be multiple calls to SwapBuffers in flight, store the > data necessary to call -[CALayer setContents] in a PendingSwap > structure. Maintain a queue of these structures. > > Because the ImageTransportSurface does not know anything about the > VSync period, send the CGDirectDisplayID for the attached display to the > ImageTransportSurface in the AcceleratedSurfaceMsg_BufferPresented IPC > (which is where the CGL renderer ID is already communicated). Send this > information instead of the raw VSync parameters so that the updates to > all windows on a single display may be coalesced into a single callback > in the future. > > Note that this display is the display that is used for vsync by the > RenderWidgetHostViewMac, so if vsync is disabled, it will be 0. > > Separate gfx::ScopedSetGLToRealGLApi into its own header file to > simplify header orders. > > Access the IOSurface of the GLImageIOSurface directly, rather than > using its ScheduleOverlayPlane method. This simplifies things > immediately, in that we can reason about the underlying IOSurface's > lifetime better than weak pointers to images. It will also simplify > the implementation of partial swap and multiple overlays. > > BUG=515696 > > Committed: https://crrev.com/5c207cac73c835b5f362670d6b46333dfae1f4c4 > Cr-Commit-Position: refs/heads/master@{#342548} TBR=dcheng@chromium.org,jbauman@chromium.org,tapted@chromium.org,ccameron@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=515696 Review URL: https://codereview.chromium.org/1280033004 Cr-Commit-Position: refs/heads/master@{#342566}
-rw-r--r--content/browser/compositor/gpu_surfaceless_browser_compositor_output_surface.cc4
-rw-r--r--content/browser/gpu/gpu_process_host_ui_shim.cc3
-rw-r--r--content/browser/renderer_host/render_widget_host_view_mac.h1
-rw-r--r--content/browser/renderer_host/render_widget_host_view_mac.mm7
-rw-r--r--content/common/gpu/gpu_messages.h3
-rw-r--r--content/common/gpu/image_transport_surface_calayer_mac.mm2
-rw-r--r--content/common/gpu/image_transport_surface_overlay_mac.h44
-rw-r--r--content/common/gpu/image_transport_surface_overlay_mac.mm293
-rw-r--r--gpu/command_buffer/service/gl_context_virtual.cc2
-rw-r--r--ui/accelerated_widget_mac/accelerated_widget_mac.h6
-rw-r--r--ui/accelerated_widget_mac/accelerated_widget_mac.mm10
-rw-r--r--ui/accelerated_widget_mac/display_link_mac.cc22
-rw-r--r--ui/accelerated_widget_mac/display_link_mac.h11
-rw-r--r--ui/gl/BUILD.gn2
-rw-r--r--ui/gl/gl.gyp2
-rw-r--r--ui/gl/gl_gl_api_implementation.cc9
-rw-r--r--ui/gl/gl_gl_api_implementation.h10
-rw-r--r--ui/gl/gl_image_io_surface.h2
-rw-r--r--ui/gl/gl_image_io_surface.mm20
-rw-r--r--ui/gl/scoped_api.cc20
-rw-r--r--ui/gl/scoped_api.h28
-rw-r--r--ui/views/cocoa/bridged_native_widget.h1
-rw-r--r--ui/views/cocoa/bridged_native_widget.mm4
23 files changed, 69 insertions, 437 deletions
diff --git a/content/browser/compositor/gpu_surfaceless_browser_compositor_output_surface.cc b/content/browser/compositor/gpu_surfaceless_browser_compositor_output_surface.cc
index 62b1aae..9507cc3 100644
--- a/content/browser/compositor/gpu_surfaceless_browser_compositor_output_surface.cc
+++ b/content/browser/compositor/gpu_surfaceless_browser_compositor_output_surface.cc
@@ -98,9 +98,6 @@ void GpuSurfacelessBrowserCompositorOutputSurface::Reshape(
void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersCompleted(
const std::vector<ui::LatencyInfo>& latency_info,
gfx::SwapResult result) {
-#if defined(OS_MACOSX)
- NOTREACHED();
-#else
if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) {
// Even through the swap failed, this is a fixable error so we can pretend
// it succeeded to the rest of the system.
@@ -109,7 +106,6 @@ void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersCompleted(
}
GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted(latency_info,
result);
-#endif
}
#if defined(OS_MACOSX)
diff --git a/content/browser/gpu/gpu_process_host_ui_shim.cc b/content/browser/gpu/gpu_process_host_ui_shim.cc
index 040daa3..637f4bc 100644
--- a/content/browser/gpu/gpu_process_host_ui_shim.cc
+++ b/content/browser/gpu/gpu_process_host_ui_shim.cc
@@ -308,8 +308,7 @@ void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped(
params.scale_factor,
params.damage_rect,
base::Bind(&OnSurfaceDisplayedCallback, params.surface_id),
- &ack_params.disable_throttling, &ack_params.renderer_id,
- &ack_params.display_id_for_vsync);
+ &ack_params.disable_throttling, &ack_params.renderer_id);
}
Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, ack_params));
}
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
index 71cb1d6..0f6a826 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.h
+++ b/content/browser/renderer_host/render_widget_host_view_mac.h
@@ -496,7 +496,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
// AcceleratedWidgetMacNSView implementation.
NSView* AcceleratedWidgetGetNSView() const override;
bool AcceleratedWidgetShouldIgnoreBackpressure() const override;
- uint32_t AcceleratedWidgetGetDisplayIDForVSync() const override;
void AcceleratedWidgetSwapCompleted(
const std::vector<ui::LatencyInfo>& latency_info) override;
void AcceleratedWidgetHitError() override;
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
index 4033cc6..e0aef15 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -515,13 +515,6 @@ bool RenderWidgetHostViewMac::AcceleratedWidgetShouldIgnoreBackpressure()
return false;
}
-uint32_t RenderWidgetHostViewMac::AcceleratedWidgetGetDisplayIDForVSync()
- const {
- if (display_link_)
- return display_link_->display_id();
- return 0;
-}
-
void RenderWidgetHostViewMac::AcceleratedWidgetSwapCompleted(
const std::vector<ui::LatencyInfo>& all_latency_info) {
if (!render_widget_host_)
diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h
index 16ca262..2b3a732 100644
--- a/content/common/gpu/gpu_messages.h
+++ b/content/common/gpu/gpu_messages.h
@@ -110,9 +110,6 @@ IPC_STRUCT_BEGIN(AcceleratedSurfaceMsg_BufferPresented_Params)
// If the browser is drawing to the screen, this is the CGL renderer ID of
// the GL context that the brower is using.
IPC_STRUCT_MEMBER(int32, renderer_id)
- // The CGDirectDisplayID on which the content was displayed, to be used for
- // computing vsync. If vsync is not enabled, this is zero.
- IPC_STRUCT_MEMBER(uint32, display_id_for_vsync)
IPC_STRUCT_END()
#endif
diff --git a/content/common/gpu/image_transport_surface_calayer_mac.mm b/content/common/gpu/image_transport_surface_calayer_mac.mm
index a9e5a97..d64ef03 100644
--- a/content/common/gpu/image_transport_surface_calayer_mac.mm
+++ b/content/common/gpu/image_transport_surface_calayer_mac.mm
@@ -16,9 +16,9 @@
#include "ui/base/cocoa/animation_utils.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/gfx/geometry/size_conversions.h"
+#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_switches.h"
#include "ui/gl/gpu_switching_manager.h"
-#include "ui/gl/scoped_api.h"
namespace {
const size_t kFramesToKeepCAContextAfterDiscard = 2;
diff --git a/content/common/gpu/image_transport_surface_overlay_mac.h b/content/common/gpu/image_transport_surface_overlay_mac.h
index 022fbb4..66c0591f 100644
--- a/content/common/gpu/image_transport_surface_overlay_mac.h
+++ b/content/common/gpu/image_transport_surface_overlay_mac.h
@@ -5,13 +5,9 @@
#ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
#define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
-#include <deque>
-
-#include "base/memory/linked_ptr.h"
#import "base/mac/scoped_nsobject.h"
#include "content/common/gpu/gpu_command_buffer_stub.h"
#include "content/common/gpu/image_transport_surface.h"
-#include "ui/accelerated_widget_mac/display_link_mac.h"
#include "ui/gl/gl_surface.h"
@class CAContext;
@@ -51,35 +47,14 @@ class ImageTransportSurfaceOverlayMac : public gfx::GLSurface,
void WakeUpGpu() override;
private:
- class PendingSwap;
-
~ImageTransportSurfaceOverlayMac() override;
-
- gfx::SwapResult SwapBuffersInternal(const gfx::Rect& pixel_damage_rect);
-
- // Returns true if the front of |pending_swaps_| has completed, or has timed
- // out by |now|.
- bool IsFirstPendingSwapReadyToDisplay(
- const base::TimeTicks& now);
- // Sets the CALayer contents to the IOSurface for the front of
- // |pending_swaps_|, and removes it from the queue.
- void DisplayFirstPendingSwapImmediately();
- // Force that all of |pending_swaps_| displayed immediately, and the list be
- // cleared.
- void FinishAllPendingSwaps();
- // Callback issued during the next vsync period ofter a SwapBuffers call,
- // to check if the swap is completed, and display the frame. Note that if
- // another SwapBuffers happens before this callback, the pending swap will
- // be tested at that time, too.
- void CheckPendingSwapsCallback();
- // Function to post the above callback. The argument |now| is passed as an
- // argument to avoid redundant calls to base::TimeTicks::Now.
- void PostCheckPendingSwapsCallbackIfNeeded(const base::TimeTicks& now);
-
scoped_ptr<ImageTransportHelper> helper_;
base::scoped_nsobject<CAContext> ca_context_;
base::scoped_nsobject<CALayer> layer_;
+ // A phony NSView handle used to identify this.
+ gfx::AcceleratedWidget widget_;
+
gfx::Size pixel_size_;
float scale_factor_;
std::vector<ui::LatencyInfo> latency_info_;
@@ -88,19 +63,6 @@ class ImageTransportSurfaceOverlayMac : public gfx::GLSurface,
// consumed and reset when SwapBuffers is called. For now, only one overlay
// plane is supported.
gfx::GLImage* pending_overlay_image_;
-
- // A queue of all frames that have been created by SwapBuffersInternal but
- // have not yet been displayed. This queue is checked at the beginning of
- // every swap and also by a callback.
- std::deque<linked_ptr<PendingSwap>> pending_swaps_;
-
- // The display link used to compute the time for callbacks.
- scoped_refptr<ui::DisplayLinkMac> display_link_mac_;
-
- // True if there is a pending call to CheckPendingSwapsCallback posted.
- bool has_pending_callback_;
-
- base::WeakPtrFactory<ImageTransportSurfaceOverlayMac> weak_factory_;
};
} // namespace content
diff --git a/content/common/gpu/image_transport_surface_overlay_mac.mm b/content/common/gpu/image_transport_surface_overlay_mac.mm
index 213f045..1a52833 100644
--- a/content/common/gpu/image_transport_surface_overlay_mac.mm
+++ b/content/common/gpu/image_transport_surface_overlay_mac.mm
@@ -4,92 +4,27 @@
#include "content/common/gpu/image_transport_surface_overlay_mac.h"
-#include <IOSurface/IOSurface.h>
-#include <OpenGL/GL.h>
+#include <OpenGL/gl.h>
-// This type consistently causes problem on Mac, and needs to be dealt with
-// in a systemic way.
-// http://crbug.com/517208
-#ifndef GL_OES_EGL_image
-typedef void* GLeglImageOES;
-#endif
-
-#include "base/mac/scoped_cftyperef.h"
#include "content/common/gpu/gpu_messages.h"
#include "ui/accelerated_widget_mac/surface_handle_types.h"
#include "ui/base/cocoa/animation_utils.h"
#include "ui/base/cocoa/remote_layer_api.h"
#include "ui/gfx/geometry/dip_util.h"
-#include "ui/gl/gl_fence_apple.h"
#include "ui/gl/gl_image_io_surface.h"
-#include "ui/gl/scoped_api.h"
-#include "ui/gl/scoped_cgl.h"
-
-namespace {
-
-// Don't let a frame draw until 5% of the way through the next vsync interval
-// after the call to SwapBuffers. This slight offset is to ensure that skew
-// doesn't result in the frame being presented to the previous vsync interval.
-
-const double kVSyncIntervalFractionForEarliestDisplay = 0.05;
-// Target 50% of the way through the next vsync interval. Empirically, it has
-// been determined to be a good target for smooth animation.
-const double kVSyncIntervalFractionForDisplayCallback = 0.5;
-
-// If a frame takes more than 1/4th of a second for its fence to finish, just
-// pretend that the frame is ready to draw.
-const double kMaximumDelayWaitingForFenceInSeconds = 0.25;
-
-void CheckGLErrors(const char* msg) {
- GLenum gl_error;
- while ((gl_error = glGetError()) != GL_NO_ERROR) {
- LOG(ERROR) << "OpenGL error hit " << msg << ": " << gl_error;
- }
-}
-
-} // namespace
-
-@interface CALayer(Private)
--(void)setContentsChanged;
-@end
namespace content {
-class ImageTransportSurfaceOverlayMac::PendingSwap {
- public:
- PendingSwap() : scale_factor(1) {}
- ~PendingSwap() { DCHECK(!fence); }
-
- gfx::Size pixel_size;
- float scale_factor;
- std::vector<ui::LatencyInfo> latency_info;
-
- // The IOSurface with new content for this swap.
- base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
-
- // A fence object, and the CGL context it was issued in.
- base::ScopedTypeRef<CGLContextObj> cgl_context;
- scoped_ptr<gfx::GLFenceAPPLE> fence;
-
- // The earliest time that this frame may be drawn. A frame is not allowed
- // to draw until a fraction of the way through the vsync interval after its
- // This extra latency is to allow wiggle-room for smoothness.
- base::TimeTicks earliest_allowed_draw_time;
- // After this time, always draw the frame, no matter what its fence says. This
- // is to prevent GL bugs from locking the compositor forever.
- base::TimeTicks latest_allowed_draw_time;
-};
-
ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac(
GpuChannelManager* manager,
GpuCommandBufferStub* stub,
gfx::PluginWindowHandle handle)
- : scale_factor_(1), pending_overlay_image_(nullptr),
- has_pending_callback_(false), weak_factory_(this) {
+ : scale_factor_(1), pending_overlay_image_(nullptr) {
helper_.reset(new ImageTransportHelper(this, manager, stub, handle));
}
ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() {
+ gfx::GLImageIOSurface::SetLayerForWidget(widget_, nil);
}
bool ImageTransportSurfaceOverlayMac::Initialize() {
@@ -102,225 +37,61 @@ bool ImageTransportSurfaceOverlayMac::Initialize() {
ca_context_.reset(
[[CAContext contextWithCGSConnection:connection_id options:@{}] retain]);
layer_.reset([[CALayer alloc] init]);
- [layer_ setGeometryFlipped:YES];
- [layer_ setOpaque:YES];
[ca_context_ setLayer:layer_];
+
+ // Register the CALayer so that it can be picked up in GLImageIOSurface.
+ static intptr_t previous_widget = 0;
+ previous_widget += 1;
+ widget_ = reinterpret_cast<gfx::AcceleratedWidget>(previous_widget);
+ gfx::GLImageIOSurface::SetLayerForWidget(widget_, layer_);
+
return true;
}
-void ImageTransportSurfaceOverlayMac::Destroy() {
- FinishAllPendingSwaps();
-}
+void ImageTransportSurfaceOverlayMac::Destroy() {}
bool ImageTransportSurfaceOverlayMac::IsOffscreen() {
return false;
}
-gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffersInternal(
- const gfx::Rect& pixel_damage_rect) {
- TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffersInternal");
-
- // Use the same concept of 'now' for the entire function. The duration of
- // this function only affect the result if this function lasts across a vsync
- // boundary, in which case smooth animation is out the window anyway.
- const base::TimeTicks now = base::TimeTicks::Now();
+gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() {
+ TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffers");
- // If the previous swap is ready to display, do it before flushing the
- // new swap. It is desirable to always be hitting this path when trying to
- // animate smoothly with vsync.
- if (!pending_swaps_.empty()) {
- if (IsFirstPendingSwapReadyToDisplay(now))
- DisplayFirstPendingSwapImmediately();
+ // A flush is required to ensure that all content appears in the layer.
+ {
+ TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFlush");
+ glFlush();
}
- // The remainder of the function will populate the PendingSwap structure and
- // then enqueue it.
- linked_ptr<PendingSwap> new_swap(new PendingSwap);
- new_swap->pixel_size = pixel_size_;
- new_swap->scale_factor = scale_factor_;
- new_swap->latency_info.swap(latency_info_);
-
// There should exist only one overlay image, and it should cover the whole
// surface.
DCHECK(pending_overlay_image_);
if (pending_overlay_image_) {
- gfx::GLImageIOSurface* pending_overlay_image_io_surface =
- static_cast<gfx::GLImageIOSurface*>(pending_overlay_image_);
- new_swap->io_surface = pending_overlay_image_io_surface->io_surface();
- pending_overlay_image_ = nullptr;
- }
-
- // A flush is required to ensure that all content appears in the layer.
- {
- gfx::ScopedSetGLToRealGLApi scoped_set_gl_api;
- TRACE_EVENT1("gpu", "ImageTransportSurfaceOverlayMac::glFlush", "surface",
- new_swap->io_surface.get());
- CheckGLErrors("before flushing frame");
- new_swap->cgl_context.reset(CGLGetCurrentContext(),
- base::scoped_policy::RETAIN);
- new_swap->fence.reset(new gfx::GLFenceAPPLE);
- CheckGLErrors("while flushing frame");
- }
-
- // Compute the deadlines for drawing this frame.
- if (display_link_mac_) {
- new_swap->earliest_allowed_draw_time =
- display_link_mac_->GetNextVSyncTimeAfter(
- now, kVSyncIntervalFractionForEarliestDisplay);
- new_swap->latest_allowed_draw_time = now +
- base::TimeDelta::FromSecondsD(kMaximumDelayWaitingForFenceInSeconds);
- } else {
- // If we have no display link (because vsync is disabled or because we have
- // not received display parameters yet), immediately attempt to display the
- // surface.
- new_swap->earliest_allowed_draw_time = now;
- new_swap->latest_allowed_draw_time = now;
- }
-
- pending_swaps_.push_back(new_swap);
- PostCheckPendingSwapsCallbackIfNeeded(now);
- return gfx::SwapResult::SWAP_ACK;
-}
-
-bool ImageTransportSurfaceOverlayMac::IsFirstPendingSwapReadyToDisplay(
- const base::TimeTicks& now) {
- DCHECK(!pending_swaps_.empty());
- linked_ptr<PendingSwap> swap = pending_swaps_.front();
-
- // If more that a certain amount of time has passed since the swap,
- // unconditionally continue.
- if (now > swap->latest_allowed_draw_time)
- return true;
-
- // Frames are disallowed from drawing until the vsync interval after their
- // swap is issued.
- if (now < swap->earliest_allowed_draw_time)
- return false;
-
- // If there is no fence then this is either for immediate display, or the
- // fence was aready successfully checked and deleted.
- if (!swap->fence)
- return true;
-
- // Check if the pending work has finished (and early-out if it is not, and
- // this is not forced).
- bool has_completed = false;
- {
- gfx::ScopedSetGLToRealGLApi scoped_set_gl_api;
- gfx::ScopedCGLSetCurrentContext scoped_set_current(swap->cgl_context);
-
- CheckGLErrors("before testing fence");
- has_completed= swap->fence->HasCompleted();
- CheckGLErrors("after testing fence");
- if (has_completed) {
- swap->fence.reset();
- CheckGLErrors("while deleting fence");
- }
- }
- return has_completed;
-}
-
-void ImageTransportSurfaceOverlayMac::DisplayFirstPendingSwapImmediately() {
- TRACE_EVENT0("gpu",
- "ImageTransportSurfaceOverlayMac::DisplayFirstPendingSwapImmediately");
- DCHECK(!pending_swaps_.empty());
- linked_ptr<PendingSwap> swap = pending_swaps_.front();
-
- // If there is a fence for this object, delete it.
- if (swap->fence) {
- gfx::ScopedSetGLToRealGLApi scoped_set_gl_api;
- gfx::ScopedCGLSetCurrentContext scoped_set_current(swap->cgl_context);
-
- CheckGLErrors("before deleting active fence");
- swap->fence.reset();
- CheckGLErrors("while deleting active fence");
- }
-
- // Update the CALayer hierarchy.
- {
- TRACE_EVENT1("gpu", "ImageTransportSurfaceOverlayMac::setContents",
- "surface", swap->io_surface.get());
+ TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::setContents");
ScopedCAActionDisabler disabler;
-
- id new_contents = static_cast<id>(swap->io_surface.get());
- [layer_ setContents:new_contents];
-
- CGRect new_frame = gfx::ConvertRectToDIP(
- swap->scale_factor, gfx::Rect(swap->pixel_size)).ToCGRect();
- if (!CGRectEqualToRect([layer_ frame], new_frame))
- [layer_ setFrame:new_frame];
+ gfx::Rect dip_bounds = gfx::ConvertRectToDIP(
+ scale_factor_, gfx::Rect(pixel_size_));
+ gfx::RectF crop_rect(0, 0, 1, 1);
+ pending_overlay_image_->ScheduleOverlayPlane(
+ widget_, 0, gfx::OVERLAY_TRANSFORM_NONE, dip_bounds, crop_rect);
+ pending_overlay_image_ = nullptr;
}
- // Send acknowledgement to the browser.
GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
params.surface_handle =
ui::SurfaceHandleFromCAContextID([ca_context_ contextId]);
params.size = pixel_size_;
params.scale_factor = scale_factor_;
- params.latency_info.swap(swap->latency_info);
+ params.latency_info.swap(latency_info_);
helper_->SendAcceleratedSurfaceBuffersSwapped(params);
-
- // Remove this from the queue, and reset any callback timers.
- pending_swaps_.pop_front();
-}
-
-void ImageTransportSurfaceOverlayMac::FinishAllPendingSwaps() {
- TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::FinishAllPendingSwaps");
- while (!pending_swaps_.empty())
- DisplayFirstPendingSwapImmediately();
-}
-
-void ImageTransportSurfaceOverlayMac::CheckPendingSwapsCallback() {
- TRACE_EVENT0("gpu",
- "ImageTransportSurfaceOverlayMac::CheckPendingSwapsCallback");
-
- DCHECK(has_pending_callback_);
- has_pending_callback_ = false;
-
- if (pending_swaps_.empty())
- return;
-
- const base::TimeTicks now = base::TimeTicks::Now();
- if (IsFirstPendingSwapReadyToDisplay(now))
- DisplayFirstPendingSwapImmediately();
- PostCheckPendingSwapsCallbackIfNeeded(now);
-}
-
-void ImageTransportSurfaceOverlayMac::PostCheckPendingSwapsCallbackIfNeeded(
- const base::TimeTicks& now) {
- TRACE_EVENT0("gpu",
- "ImageTransportSurfaceOverlayMac::PostCheckPendingSwapsCallbackIfNeeded");
-
- if (has_pending_callback_)
- return;
- if (pending_swaps_.empty())
- return;
-
- base::TimeTicks target;
- if (display_link_mac_) {
- target = display_link_mac_->GetNextVSyncTimeAfter(
- now, kVSyncIntervalFractionForDisplayCallback);
- } else {
- target = now;
- }
- base::TimeDelta delay = target - now;
-
- base::MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&ImageTransportSurfaceOverlayMac::CheckPendingSwapsCallback,
- weak_factory_.GetWeakPtr()), delay);
- has_pending_callback_ = true;
-}
-
-gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() {
- return SwapBuffersInternal(gfx::Rect(pixel_size_));
+ return gfx::SwapResult::SWAP_ACK;
}
gfx::SwapResult ImageTransportSurfaceOverlayMac::PostSubBuffer(int x,
int y,
int width,
int height) {
- return SwapBuffersInternal(gfx::Rect(x, y, width, height));
+ return SwapBuffers();
}
bool ImageTransportSurfaceOverlayMac::SupportsPostSubBuffer() {
@@ -358,18 +129,10 @@ bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const {
}
void ImageTransportSurfaceOverlayMac::OnBufferPresented(
- const AcceleratedSurfaceMsg_BufferPresented_Params& params) {
- if (display_link_mac_ &&
- display_link_mac_->display_id() == params.display_id_for_vsync)
- return;
- display_link_mac_ = ui::DisplayLinkMac::GetForDisplay(
- params.display_id_for_vsync);
-}
+ const AcceleratedSurfaceMsg_BufferPresented_Params& params) {}
void ImageTransportSurfaceOverlayMac::OnResize(gfx::Size pixel_size,
float scale_factor) {
- // Flush through any pending frames.
- FinishAllPendingSwaps();
pixel_size_ = pixel_size;
scale_factor_ = scale_factor;
}
diff --git a/gpu/command_buffer/service/gl_context_virtual.cc b/gpu/command_buffer/service/gl_context_virtual.cc
index 563e601..f965ace 100644
--- a/gpu/command_buffer/service/gl_context_virtual.cc
+++ b/gpu/command_buffer/service/gl_context_virtual.cc
@@ -6,12 +6,10 @@
#include "base/callback.h"
#include "gpu/command_buffer/service/gl_state_restorer_impl.h"
-#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/gpu_preference.h"
#include "ui/gl/gpu_timing.h"
-#include "ui/gl/scoped_api.h"
namespace gpu {
diff --git a/ui/accelerated_widget_mac/accelerated_widget_mac.h b/ui/accelerated_widget_mac/accelerated_widget_mac.h
index f24e8b8..087a9a6 100644
--- a/ui/accelerated_widget_mac/accelerated_widget_mac.h
+++ b/ui/accelerated_widget_mac/accelerated_widget_mac.h
@@ -39,7 +39,6 @@ class AcceleratedWidgetMacNSView {
public:
virtual NSView* AcceleratedWidgetGetNSView() const = 0;
virtual bool AcceleratedWidgetShouldIgnoreBackpressure() const = 0;
- virtual uint32_t AcceleratedWidgetGetDisplayIDForVSync() const = 0;
virtual void AcceleratedWidgetSwapCompleted(
const std::vector<ui::LatencyInfo>& latency_info) = 0;
virtual void AcceleratedWidgetHitError() = 0;
@@ -68,9 +67,6 @@ class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac
// Return the CGL renderer ID for the surface, if one is available.
int GetRendererID() const;
- // Return the CG display ID for the surface, if known.
- uint32_t GetDisplayIDForVSync() const;
-
// Return true if the renderer should not be throttled by GPU back-pressure.
bool IsRendererThrottlingDisabled() const;
@@ -165,7 +161,7 @@ void AcceleratedWidgetMacGotAcceleratedFrame(
float scale_factor,
const gfx::Rect& pixel_damage_rect,
const base::Closure& drawn_callback,
- bool* disable_throttling, int* renderer_id, uint32_t* display_id);
+ bool* disable_throttling, int* renderer_id);
ACCELERATED_WIDGET_MAC_EXPORT
void AcceleratedWidgetMacGotSoftwareFrame(
diff --git a/ui/accelerated_widget_mac/accelerated_widget_mac.mm b/ui/accelerated_widget_mac/accelerated_widget_mac.mm
index c490c4e..82390e5 100644
--- a/ui/accelerated_widget_mac/accelerated_widget_mac.mm
+++ b/ui/accelerated_widget_mac/accelerated_widget_mac.mm
@@ -110,12 +110,6 @@ int AcceleratedWidgetMac::GetRendererID() const {
return 0;
}
-uint32_t AcceleratedWidgetMac::GetDisplayIDForVSync() const {
- if (view_)
- return view_->AcceleratedWidgetGetDisplayIDForVSync();
- return 0;
-}
-
bool AcceleratedWidgetMac::IsRendererThrottlingDisabled() const {
if (view_)
return view_->AcceleratedWidgetShouldIgnoreBackpressure();
@@ -371,7 +365,7 @@ void AcceleratedWidgetMacGotAcceleratedFrame(
float scale_factor,
const gfx::Rect& pixel_damage_rect,
const base::Closure& drawn_callback,
- bool* disable_throttling, int* renderer_id, uint32_t* display_id) {
+ bool* disable_throttling, int* renderer_id) {
AcceleratedWidgetMac* accelerated_widget_mac =
GetHelperFromAcceleratedWidget(widget);
if (accelerated_widget_mac) {
@@ -381,11 +375,9 @@ void AcceleratedWidgetMacGotAcceleratedFrame(
*disable_throttling =
accelerated_widget_mac->IsRendererThrottlingDisabled();
*renderer_id = accelerated_widget_mac->GetRendererID();
- *display_id = accelerated_widget_mac->GetDisplayIDForVSync();
} else {
*disable_throttling = false;
*renderer_id = 0;
- *display_id = 0;
}
}
diff --git a/ui/accelerated_widget_mac/display_link_mac.cc b/ui/accelerated_widget_mac/display_link_mac.cc
index 3013efb..c9a3069 100644
--- a/ui/accelerated_widget_mac/display_link_mac.cc
+++ b/ui/accelerated_widget_mac/display_link_mac.cc
@@ -27,9 +27,6 @@ namespace ui {
// static
scoped_refptr<DisplayLinkMac> DisplayLinkMac::GetForDisplay(
CGDirectDisplayID display_id) {
- if (!display_id)
- return nullptr;
-
// Return the existing display link for this display, if it exists.
DisplayMap::iterator found = display_map_.Get().find(display_id);
if (found != display_map_.Get().end()) {
@@ -108,22 +105,6 @@ bool DisplayLinkMac::GetVSyncParameters(
return true;
}
-base::TimeTicks DisplayLinkMac::GetNextVSyncTimeAfter(
- const base::TimeTicks& from, double interval_fraction) {
- if (!timebase_and_interval_valid_) {
- StartOrContinueDisplayLink();
- return from;
- }
-
- // Compute the previous vsync time.
- base::TimeTicks previous_vsync =
- interval_ * ((from - timebase_remainder_) / interval_) +
- timebase_remainder_;
-
- // Return |interval_fraction| through the next vsync.
- return previous_vsync + (1 + interval_fraction) * interval_;
-}
-
void DisplayLinkMac::Tick(const CVTimeStamp& cv_time) {
TRACE_EVENT0("ui", "DisplayLinkMac::Tick");
@@ -142,9 +123,6 @@ void DisplayLinkMac::Tick(const CVTimeStamp& cv_time) {
cv_time.hostTime / 1000);
interval_ = base::TimeDelta::FromMicroseconds(
1000000 * static_cast<int64>(numerator) / denominator);
- // Compute |timebase_remainder_| to be the first vsync after time zero.
- timebase_remainder_ =
- timebase_ - interval_ * ((timebase_ - base::TimeTicks()) / interval_);
timebase_and_interval_valid_ = true;
StopDisplayLink();
diff --git a/ui/accelerated_widget_mac/display_link_mac.h b/ui/accelerated_widget_mac/display_link_mac.h
index e462e28..1ec7a72 100644
--- a/ui/accelerated_widget_mac/display_link_mac.h
+++ b/ui/accelerated_widget_mac/display_link_mac.h
@@ -5,8 +5,8 @@
#ifndef UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_
#define UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_
-#include <map>
#include <QuartzCore/CVDisplayLink.h>
+#include <map>
#include "base/lazy_instance.h"
#include "base/mac/scoped_typeref.h"
@@ -24,19 +24,11 @@ class ACCELERATED_WIDGET_MAC_EXPORT DisplayLinkMac :
static scoped_refptr<DisplayLinkMac> GetForDisplay(
CGDirectDisplayID display_id);
- CGDirectDisplayID display_id() const { return display_id_; }
-
// Get vsync scheduling parameters.
bool GetVSyncParameters(
base::TimeTicks* timebase,
base::TimeDelta* interval);
- // Return the time of |interval_fraction| of the way through the next
- // vsync period that starts after |from|. If the vsync parameters have
- // not yet been computed, return |from|.
- base::TimeTicks GetNextVSyncTimeAfter(
- const base::TimeTicks& from, double interval_fraction);
-
private:
friend class base::RefCounted<DisplayLinkMac>;
@@ -78,7 +70,6 @@ class ACCELERATED_WIDGET_MAC_EXPORT DisplayLinkMac :
// VSync parameters computed during Tick.
bool timebase_and_interval_valid_;
base::TimeTicks timebase_;
- base::TimeTicks timebase_remainder_;
base::TimeDelta interval_;
// Each display link instance consumes a non-negligible number of cycles, so
diff --git a/ui/gl/BUILD.gn b/ui/gl/BUILD.gn
index 721f351..8234fc7 100644
--- a/ui/gl/BUILD.gn
+++ b/ui/gl/BUILD.gn
@@ -96,8 +96,6 @@ component("gl") {
"gpu_switching_manager.h",
"gpu_timing.cc",
"gpu_timing.h",
- "scoped_api.cc",
- "scoped_api.h",
"scoped_binders.cc",
"scoped_binders.h",
"scoped_make_current.cc",
diff --git a/ui/gl/gl.gyp b/ui/gl/gl.gyp
index f0f026a..b730d96 100644
--- a/ui/gl/gl.gyp
+++ b/ui/gl/gl.gyp
@@ -115,8 +115,6 @@
'gpu_switching_observer.h',
'gpu_timing.cc',
'gpu_timing.h',
- 'scoped_api.cc',
- 'scoped_api.h',
'scoped_binders.cc',
'scoped_binders.h',
'scoped_make_current.cc',
diff --git a/ui/gl/gl_gl_api_implementation.cc b/ui/gl/gl_gl_api_implementation.cc
index b7dc44b..a59a2c0 100644
--- a/ui/gl/gl_gl_api_implementation.cc
+++ b/ui/gl/gl_gl_api_implementation.cc
@@ -614,4 +614,13 @@ void VirtualGLApi::glFinishFn() {
GLApiBase::glFinishFn();
}
+ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi()
+ : old_gl_api_(GetCurrentGLApi()) {
+ SetGLToRealGLApi();
+}
+
+ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() {
+ SetGLApi(old_gl_api_);
+}
+
} // namespace gfx
diff --git a/ui/gl/gl_gl_api_implementation.h b/ui/gl/gl_gl_api_implementation.h
index cfefb13..a5197fe 100644
--- a/ui/gl/gl_gl_api_implementation.h
+++ b/ui/gl/gl_gl_api_implementation.h
@@ -36,7 +36,6 @@ void ClearGLBindingsGL();
void SetGLToRealGLApi();
void SetGLApi(GLApi* api);
void SetGLApiToNoContext();
-GLApi* GetCurrentGLApi();
const GLVersionInfo* GetGLVersionInfo();
class GL_EXPORT GLApiBase : public GLApi {
@@ -140,6 +139,15 @@ private:
std::string extensions_;
};
+class GL_EXPORT ScopedSetGLToRealGLApi {
+ public:
+ ScopedSetGLToRealGLApi();
+ ~ScopedSetGLToRealGLApi();
+
+ private:
+ GLApi* old_gl_api_;
+};
+
} // namespace gfx
#endif // UI_GL_GL_GL_API_IMPLEMENTATION_H_
diff --git a/ui/gl/gl_image_io_surface.h b/ui/gl/gl_image_io_surface.h
index e513b93..12fd7b57 100644
--- a/ui/gl/gl_image_io_surface.h
+++ b/ui/gl/gl_image_io_surface.h
@@ -45,8 +45,6 @@ class GL_EXPORT GLImageIOSurface : public GLImage {
const Rect& bounds_rect,
const RectF& crop_rect) override;
- base::ScopedCFTypeRef<IOSurfaceRef> io_surface();
-
static void SetLayerForWidget(gfx::AcceleratedWidget widget,
CALayer* layer);
diff --git a/ui/gl/gl_image_io_surface.mm b/ui/gl/gl_image_io_surface.mm
index b488c53..2044f37 100644
--- a/ui/gl/gl_image_io_surface.mm
+++ b/ui/gl/gl_image_io_surface.mm
@@ -199,12 +199,22 @@ bool GLImageIOSurface::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
OverlayTransform transform,
const Rect& bounds_rect,
const RectF& crop_rect) {
- NOTREACHED();
- return false;
-}
+ // Only simple overlay planes are currently supported.
+ DCHECK_EQ(0, z_order);
+ DCHECK_EQ(gfx::RectF(0, 0, 1, 1).ToString(), crop_rect.ToString());
+ DCHECK_EQ(gfx::OVERLAY_TRANSFORM_NONE, transform);
+
+ // Convert the phony widget to the appropriate CALayer.
+ auto found = g_widget_to_layer_map.Pointer()->find(widget);
+ if (found == g_widget_to_layer_map.Pointer()->end())
+ return false;
+ CALayer* layer = found->second;
-base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() {
- return io_surface_;
+ // Also note that transactions are not disabled. The caller must ensure that
+ // all changes to the CALayer tree happen atomically.
+ [layer setContents:static_cast<id>(io_surface_.get())];
+ [layer setFrame:bounds_rect.ToCGRect()];
+ return true;
}
// static
diff --git a/ui/gl/scoped_api.cc b/ui/gl/scoped_api.cc
deleted file mode 100644
index f43f692..0000000
--- a/ui/gl/scoped_api.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2015 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 "ui/gl/scoped_api.h"
-
-#include "ui/gl/gl_gl_api_implementation.h"
-
-namespace gfx {
-
-ScopedSetGLToRealGLApi::ScopedSetGLToRealGLApi()
- : old_gl_api_(GetCurrentGLApi()) {
- SetGLToRealGLApi();
-}
-
-ScopedSetGLToRealGLApi::~ScopedSetGLToRealGLApi() {
- SetGLApi(old_gl_api_);
-}
-
-} // namespace gfx
diff --git a/ui/gl/scoped_api.h b/ui/gl/scoped_api.h
deleted file mode 100644
index dd9af50..0000000
--- a/ui/gl/scoped_api.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2015 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.
-
-#ifndef UI_GL_SCOPED_API_H_
-#define UI_GL_SCOPED_API_H_
-
-#include "base/basictypes.h"
-#include "ui/gl/gl_export.h"
-
-namespace gfx {
-
-class GLApi;
-
-class GL_EXPORT ScopedSetGLToRealGLApi {
- public:
- ScopedSetGLToRealGLApi();
- ~ScopedSetGLToRealGLApi();
-
- private:
- GLApi* old_gl_api_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedSetGLToRealGLApi);
-};
-
-} // namespace gfx
-
-#endif // UI_GL_SCOPED_API_H_
diff --git a/ui/views/cocoa/bridged_native_widget.h b/ui/views/cocoa/bridged_native_widget.h
index 0180f81..2f7d30a 100644
--- a/ui/views/cocoa/bridged_native_widget.h
+++ b/ui/views/cocoa/bridged_native_widget.h
@@ -228,7 +228,6 @@ class VIEWS_EXPORT BridgedNativeWidget
// Overridden from ui::AcceleratedWidgetMac:
NSView* AcceleratedWidgetGetNSView() const override;
bool AcceleratedWidgetShouldIgnoreBackpressure() const override;
- uint32_t AcceleratedWidgetGetDisplayIDForVSync() const override;
void AcceleratedWidgetSwapCompleted(
const std::vector<ui::LatencyInfo>& latency_info) override;
void AcceleratedWidgetHitError() override;
diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm
index d2934ba..1bd03ff 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -862,10 +862,6 @@ bool BridgedNativeWidget::AcceleratedWidgetShouldIgnoreBackpressure() const {
return true;
}
-uint32_t BridgedNativeWidget::AcceleratedWidgetGetDisplayIDForVSync() const {
- return 0;
-}
-
void BridgedNativeWidget::AcceleratedWidgetSwapCompleted(
const std::vector<ui::LatencyInfo>& latency_info) {
// Ignore frames arriving "late" for an old size. A frame at the new size