diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-25 11:39:07 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-01-25 15:20:42 +0000 |
commit | 6c91641271e536ffaa88a1dff5127e42ee99a91e (patch) | |
tree | 703d9dd49602377ddc90cbf886aad37913f2496b /chromium/ui/accelerated_widget_mac | |
parent | b145b7fafd36f0c260d6a768c81fc14e32578099 (diff) | |
download | qtwebengine-chromium-6c91641271e536ffaa88a1dff5127e42ee99a91e.tar.gz |
BASELINE: Update Chromium to 49.0.2623.23
Also adds missing printing sources.
Change-Id: I3726b8f0c7d6751c9fc846096c571fadca7108cd
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'chromium/ui/accelerated_widget_mac')
15 files changed, 112 insertions, 1431 deletions
diff --git a/chromium/ui/accelerated_widget_mac/BUILD.gn b/chromium/ui/accelerated_widget_mac/BUILD.gn index 429ddd414d3..69d2213e63a 100644 --- a/chromium/ui/accelerated_widget_mac/BUILD.gn +++ b/chromium/ui/accelerated_widget_mac/BUILD.gn @@ -12,14 +12,6 @@ component("accelerated_widget_mac") { "display_link_mac.h", "io_surface_context.h", "io_surface_context.mm", - "io_surface_layer.h", - "io_surface_layer.mm", - "io_surface_texture.h", - "io_surface_texture.mm", - "software_layer.h", - "software_layer.mm", - "surface_handle_types.cc", - "surface_handle_types.h", "window_resize_helper_mac.cc", "window_resize_helper_mac.h", ] @@ -36,10 +28,5 @@ component("accelerated_widget_mac") { "//ui/gl", ] - libs = [ - # Required by io_surface_texture.mm. - "IOSurface.framework", - "OpenGL.framework", - "QuartzCore.framework", - ] + libs = [ "QuartzCore.framework" ] } diff --git a/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.gyp b/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.gyp index 69d429faebf..a062ef796c3 100644 --- a/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.gyp +++ b/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.gyp @@ -19,14 +19,6 @@ 'display_link_mac.h', 'io_surface_context.h', 'io_surface_context.mm', - 'io_surface_layer.h', - 'io_surface_layer.mm', - 'io_surface_texture.h', - 'io_surface_texture.mm', - 'software_layer.h', - 'software_layer.mm', - 'surface_handle_types.cc', - 'surface_handle_types.h', 'window_resize_helper_mac.cc', 'window_resize_helper_mac.h', ], @@ -43,9 +35,6 @@ ], 'link_settings': { 'libraries': [ - # Required by io_surface_texture.mm. - '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', - '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', '$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework', ], }, diff --git a/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.h b/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.h index 39142965f0f..696dc188347 100644 --- a/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.h +++ b/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.h @@ -8,8 +8,11 @@ #include <IOSurface/IOSurface.h> #include <vector> +#include "base/mac/scoped_cftyperef.h" +#include "base/macros.h" +#include "base/time/time.h" #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" -#include "ui/events/latency_info.h" +#include "ui/base/cocoa/remote_layer_api.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/native_widget_types.h" @@ -17,9 +20,6 @@ #if defined(__OBJC__) #import <Cocoa/Cocoa.h> #import "base/mac/scoped_nsobject.h" -#import "ui/accelerated_widget_mac/io_surface_layer.h" -#import "ui/accelerated_widget_mac/software_layer.h" -#include "ui/base/cocoa/remote_layer_api.h" #endif // __OBJC__ class SkCanvas; @@ -38,12 +38,9 @@ class AcceleratedWidgetMac; class AcceleratedWidgetMacNSView { public: virtual NSView* AcceleratedWidgetGetNSView() const = 0; - virtual bool AcceleratedWidgetShouldIgnoreBackpressure() const = 0; virtual void AcceleratedWidgetGetVSyncParameters( base::TimeTicks* timebase, base::TimeDelta* interval) const = 0; - virtual void AcceleratedWidgetSwapCompleted( - const std::vector<ui::LatencyInfo>& latency_info) = 0; - virtual void AcceleratedWidgetHitError() = 0; + virtual void AcceleratedWidgetSwapCompleted() = 0; }; #if defined(__OBJC__) @@ -52,8 +49,7 @@ class AcceleratedWidgetMacNSView { // to a ui::Compositor, which will cause, through its output surface, calls to // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed // in an NSView by setting the AcceleratedWidgetMacNSView for the helper. -class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac - : public IOSurfaceLayerClient { +class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac { public: explicit AcceleratedWidgetMac(bool needs_gl_finish_workaround); virtual ~AcceleratedWidgetMac(); @@ -66,46 +62,23 @@ class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac // Return true if the last frame swapped has a size in DIP of |dip_size|. bool HasFrameOfSize(const gfx::Size& dip_size) const; - // Return the CGL renderer ID for the surface, if one is available. - int GetRendererID() const; - // Populate the vsync parameters for the surface's display. void GetVSyncParameters( base::TimeTicks* timebase, base::TimeDelta* interval) const; - // Return true if the renderer should not be throttled by GPU back-pressure. - bool IsRendererThrottlingDisabled() const; - - // Mark a bracket in which new frames are being pumped in a restricted nested - // run loop. - void BeginPumpingFrames(); - void EndPumpingFrames(); - - void GotAcceleratedFrame( - uint64 surface_handle, - const std::vector<ui::LatencyInfo>& latency_info, - const gfx::Size& pixel_size, - float scale_factor, - const gfx::Rect& pixel_damage_rect, - const base::Closure& drawn_callback); - - void GotSoftwareFrame(float scale_factor, SkCanvas* canvas); + void GotFrame(CAContextID ca_context_id, + base::ScopedCFTypeRef<IOSurfaceRef> io_surface, + const gfx::Size& pixel_size, + float scale_factor); private: - // IOSurfaceLayerClient implementation: - bool IOSurfaceLayerShouldAckImmediately() const override; - void IOSurfaceLayerDidDrawFrame() override; - void IOSurfaceLayerHitError() override; + void GotCAContextFrame(CAContextID ca_context_id, + const gfx::Size& pixel_size, + float scale_factor); - void GotAcceleratedCAContextFrame(CAContextID ca_context_id, - const gfx::Size& pixel_size, - float scale_factor); - - void GotAcceleratedIOSurfaceFrame(IOSurfaceID io_surface_id, - const gfx::Size& pixel_size, - float scale_factor); - - void AcknowledgeAcceleratedFrame(); + void GotIOSurfaceFrame(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, + const gfx::Size& pixel_size, + float scale_factor); // Remove a layer from the heirarchy and destroy it. Because the accelerated // layer types may be replaced by a layer of the same type, the layer to @@ -113,9 +86,8 @@ class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac // layer is reset. void DestroyCAContextLayer( base::scoped_nsobject<CALayerHost> ca_context_layer); - void DestroyIOSurfaceLayer( - base::scoped_nsobject<IOSurfaceLayer> io_surface_layer); - void DestroySoftwareLayer(); + void DestroyLocalLayer(); + void EnsureLocalLayer(); // The AcceleratedWidgetMacNSView that is using this as its internals. AcceleratedWidgetMacNSView* view_; @@ -135,17 +107,8 @@ class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac // The accelerated CoreAnimation layer hosted by the GPU process. base::scoped_nsobject<CALayerHost> ca_context_layer_; - // The locally drawn accelerated CoreAnimation layer. - base::scoped_nsobject<IOSurfaceLayer> io_surface_layer_; - - // The locally drawn software layer. - base::scoped_nsobject<SoftwareLayer> software_layer_; - - // If an accelerated frame has come in which has not yet been drawn and acked - // then this is the latency info and the callback to make when the frame is - // drawn. If there is no such frame then the callback is null. - std::vector<ui::LatencyInfo> accelerated_latency_info_; - base::Closure accelerated_frame_drawn_callback_; + // The locally drawn layer, which has its contents set to an IOSurface. + base::scoped_nsobject<CALayer> local_layer_; // The size in DIP of the last swap received from |compositor_|. gfx::Size last_swap_size_dip_; @@ -160,19 +123,14 @@ class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac #endif // __OBJC__ ACCELERATED_WIDGET_MAC_EXPORT -void AcceleratedWidgetMacGotAcceleratedFrame( - gfx::AcceleratedWidget widget, uint64 surface_handle, - const std::vector<ui::LatencyInfo>& latency_info, +void AcceleratedWidgetMacGotFrame( + gfx::AcceleratedWidget widget, + CAContextID ca_context_id, + base::ScopedCFTypeRef<IOSurfaceRef> io_surface, const gfx::Size& pixel_size, float scale_factor, - const gfx::Rect& pixel_damage_rect, - const base::Closure& drawn_callback, - bool* disable_throttling, int* renderer_id, - base::TimeTicks* vsync_timebase, base::TimeDelta* vsync_interval); - -ACCELERATED_WIDGET_MAC_EXPORT -void AcceleratedWidgetMacGotSoftwareFrame( - gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas); + base::TimeTicks* vsync_timebase, + base::TimeDelta* vsync_interval); } // namespace ui diff --git a/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.mm b/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.mm index 2d31cdac759..4ce927493c2 100644 --- a/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.mm +++ b/chromium/ui/accelerated_widget_mac/accelerated_widget_mac.mm @@ -7,15 +7,20 @@ #include <map> #include "base/lazy_instance.h" +#include "base/mac/mac_util.h" +#include "base/mac/scoped_cftyperef.h" +#include "base/mac/sdk_forward_declarations.h" #include "base/message_loop/message_loop.h" #include "base/trace_event/trace_event.h" #include "third_party/skia/include/core/SkCanvas.h" -#include "ui/accelerated_widget_mac/io_surface_layer.h" -#include "ui/accelerated_widget_mac/surface_handle_types.h" #include "ui/base/cocoa/animation_utils.h" #include "ui/gfx/geometry/dip_util.h" #include "ui/gl/scoped_cgl.h" +@interface CALayer (PrivateAPI) +- (void)setContentsChanged; +@end + namespace ui { namespace { @@ -91,9 +96,8 @@ void AcceleratedWidgetMac::ResetNSView() { ScopedCAActionDisabler disabler; [flipped_layer_ removeFromSuperlayer]; - DestroyIOSurfaceLayer(io_surface_layer_); DestroyCAContextLayer(ca_context_layer_); - DestroySoftwareLayer(); + DestroyLocalLayer(); last_swap_size_dip_ = gfx::Size(); view_ = NULL; @@ -104,12 +108,6 @@ bool AcceleratedWidgetMac::HasFrameOfSize( return last_swap_size_dip_ == dip_size; } -int AcceleratedWidgetMac::GetRendererID() const { - if (io_surface_layer_) - return [io_surface_layer_ rendererID]; - return 0; -} - void AcceleratedWidgetMac::GetVSyncParameters( base::TimeTicks* timebase, base::TimeDelta* interval) const { if (view_) { @@ -120,64 +118,31 @@ void AcceleratedWidgetMac::GetVSyncParameters( } } -bool AcceleratedWidgetMac::IsRendererThrottlingDisabled() const { - if (view_) - return view_->AcceleratedWidgetShouldIgnoreBackpressure(); - return false; -} - -void AcceleratedWidgetMac::BeginPumpingFrames() { - [io_surface_layer_ beginPumpingFrames]; -} - -void AcceleratedWidgetMac::EndPumpingFrames() { - [io_surface_layer_ endPumpingFrames]; -} - -void AcceleratedWidgetMac::GotAcceleratedFrame( - uint64 surface_handle, - const std::vector<ui::LatencyInfo>& latency_info, +void AcceleratedWidgetMac::GotFrame( + CAContextID ca_context_id, + base::ScopedCFTypeRef<IOSurfaceRef> io_surface, const gfx::Size& pixel_size, - float scale_factor, - const gfx::Rect& pixel_damage_rect, - const base::Closure& drawn_callback) { - // Record the surface and latency info to use when acknowledging this frame. - DCHECK(accelerated_frame_drawn_callback_.is_null()); - accelerated_frame_drawn_callback_ = drawn_callback; - accelerated_latency_info_.insert(accelerated_latency_info_.end(), - latency_info.begin(), latency_info.end()); - + float scale_factor) { // If there is no view and therefore no superview to draw into, early-out. - if (!view_) { - AcknowledgeAcceleratedFrame(); + if (!view_) return; - } // Disable the fade-in or fade-out effect if we create or remove layers. ScopedCAActionDisabler disabler; last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); - switch (GetSurfaceHandleType(surface_handle)) { - case kSurfaceHandleTypeIOSurface: { - IOSurfaceID io_surface_id = IOSurfaceIDFromSurfaceHandle(surface_handle); - GotAcceleratedIOSurfaceFrame(io_surface_id, pixel_size, scale_factor); - break; - } - case kSurfaceHandleTypeCAContext: { - CAContextID ca_context_id = CAContextIDFromSurfaceHandle(surface_handle); - GotAcceleratedCAContextFrame(ca_context_id, pixel_size, scale_factor); - break; - } - default: - LOG(ERROR) << "Unrecognized accelerated frame type."; - return; - } + + if (ca_context_id) + GotCAContextFrame(ca_context_id, pixel_size, scale_factor); + else + GotIOSurfaceFrame(io_surface, pixel_size, scale_factor); + + view_->AcceleratedWidgetSwapCompleted(); } -void AcceleratedWidgetMac::GotAcceleratedCAContextFrame( - CAContextID ca_context_id, - const gfx::Size& pixel_size, - float scale_factor) { +void AcceleratedWidgetMac::GotCAContextFrame(CAContextID ca_context_id, + const gfx::Size& pixel_size, + 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<CALayerHost> old_ca_context_layer = @@ -193,119 +158,53 @@ void AcceleratedWidgetMac::GotAcceleratedCAContextFrame( [flipped_layer_ addSublayer:ca_context_layer_]; } - // Acknowledge the frame to unblock the compositor immediately (the GPU - // process will do any required throttling). - AcknowledgeAcceleratedFrame(); - // If this replacing a same-type layer, remove it now that the new layer is // in the hierarchy. if (old_ca_context_layer != ca_context_layer_) DestroyCAContextLayer(old_ca_context_layer); // Remove any different-type layers that this is replacing. - DestroyIOSurfaceLayer(io_surface_layer_); - DestroySoftwareLayer(); + DestroyLocalLayer(); } -void AcceleratedWidgetMac::GotAcceleratedIOSurfaceFrame( - IOSurfaceID io_surface_id, - const gfx::Size& pixel_size, - 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<IOSurfaceLayer> old_io_surface_layer = - io_surface_layer_; - - // Create or re-create an IOSurface layer if needed. If there already exists - // a layer but it has the wrong scale factor or it was poisoned, re-create the - // layer. - bool needs_new_layer = - !io_surface_layer_ || - [io_surface_layer_ hasBeenPoisoned] || - [io_surface_layer_ scaleFactor] != scale_factor; - if (needs_new_layer) { - io_surface_layer_.reset( - [[IOSurfaceLayer alloc] initWithClient:this - withScaleFactor:scale_factor - needsGLFinishWorkaround:needs_gl_finish_workaround_]); - if (io_surface_layer_) - [flipped_layer_ addSublayer:io_surface_layer_]; - else - LOG(ERROR) << "Failed to create IOSurfaceLayer"; +void AcceleratedWidgetMac::EnsureLocalLayer() { + if (!local_layer_) { + local_layer_.reset([[CALayer alloc] init]); + // Setting contents gravity is necessary to prevent the layer from being + // scaled during dyanmic resizes (especially with devtools open). + [local_layer_ setContentsGravity:kCAGravityTopLeft]; + [local_layer_ setAnchorPoint:CGPointMake(0, 0)]; + [flipped_layer_ addSublayer:local_layer_]; } +} - // Open the provided IOSurface. - if (io_surface_layer_) { - 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 IOSurfaceLayer"; - } - } +void AcceleratedWidgetMac::GotIOSurfaceFrame( + base::ScopedCFTypeRef<IOSurfaceRef> io_surface, + const gfx::Size& pixel_size, + float scale_factor) { + // If there is not a layer for local frames, create one. + EnsureLocalLayer(); - // 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(); - } + id new_contents = static_cast<id>(io_surface.get()); - // Make the CALayer draw and set its size appropriately. - if (io_surface_layer_) { - [io_surface_layer_ gotNewFrame]; - - // 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. - CGRect new_layer_bounds = CGRectMake( - 0, 0, last_swap_size_dip_.width(), last_swap_size_dip_.height()); - bool bounds_changed = !CGRectEqualToRect( - new_layer_bounds, [io_surface_layer_ bounds]); - [io_surface_layer_ setBounds:new_layer_bounds]; - if (bounds_changed) - [io_surface_layer_ setNeedsDisplayAndDisplayAndAck]; + if (new_contents && new_contents == [local_layer_ contents]) { + [local_layer_ setContentsChanged]; + } else { + [local_layer_ setContents:new_contents]; } - // If this replacing a same-type layer, remove it now that the new layer is - // in the hierarchy. - if (old_io_surface_layer != io_surface_layer_) - DestroyIOSurfaceLayer(old_io_surface_layer); - - // Remove any different-type layers that this is replacing. - DestroyCAContextLayer(ca_context_layer_); - DestroySoftwareLayer(); -} - -void AcceleratedWidgetMac::GotSoftwareFrame(float scale_factor, - SkCanvas* canvas) { - if (!canvas || !view_) - return; + [local_layer_ setBounds:CGRectMake(0, 0, pixel_size.width() / scale_factor, + pixel_size.height() / scale_factor)]; - // Disable the fade-in or fade-out effect if we create or remove layers. - ScopedCAActionDisabler disabler; - - // If there is not a layer for software frames, create one. - if (!software_layer_) { - software_layer_.reset([[SoftwareLayer alloc] init]); - [flipped_layer_ addSublayer:software_layer_]; + if ([local_layer_ respondsToSelector:(@selector(contentsScale))] && + [local_layer_ respondsToSelector:(@selector(setContentsScale:))] && + [local_layer_ contentsScale] != scale_factor) { + DCHECK(base::mac::IsOSLionOrLater()); + [local_layer_ setContentsScale:scale_factor]; } - // Set the software layer to draw the provided canvas. - SkImageInfo info; - size_t row_bytes; - const void* pixels = canvas->peekPixels(&info, &row_bytes); - gfx::Size pixel_size(info.width(), info.height()); - [software_layer_ setContentsToData:pixels - withRowBytes:row_bytes - withPixelSize:pixel_size - withScaleFactor:scale_factor]; - last_swap_size_dip_ = gfx::ConvertSizeToDIP(scale_factor, pixel_size); - // Remove any different-type layers that this is replacing. DestroyCAContextLayer(ca_context_layer_); - DestroyIOSurfaceLayer(io_surface_layer_); } void AcceleratedWidgetMac::DestroyCAContextLayer( @@ -317,90 +216,37 @@ void AcceleratedWidgetMac::DestroyCAContextLayer( ca_context_layer_.reset(); } -void AcceleratedWidgetMac::DestroyIOSurfaceLayer( - base::scoped_nsobject<IOSurfaceLayer> io_surface_layer) { - if (!io_surface_layer) +void AcceleratedWidgetMac::DestroyLocalLayer() { + if (!local_layer_) return; - [io_surface_layer resetClient]; - [io_surface_layer removeFromSuperlayer]; - if (io_surface_layer == io_surface_layer_) - io_surface_layer_.reset(); -} - -void AcceleratedWidgetMac::DestroySoftwareLayer() { - if (!software_layer_) - return; - [software_layer_ removeFromSuperlayer]; - software_layer_.reset(); -} - -bool AcceleratedWidgetMac::IOSurfaceLayerShouldAckImmediately() const { - // If there is no view then the accelerated layer is not in the view - // hierarchy and will never draw. - if (!view_) - return true; - return view_->AcceleratedWidgetShouldIgnoreBackpressure(); -} - -void AcceleratedWidgetMac::IOSurfaceLayerDidDrawFrame() { - AcknowledgeAcceleratedFrame(); + [local_layer_ removeFromSuperlayer]; + local_layer_.reset(); } -void AcceleratedWidgetMac::AcknowledgeAcceleratedFrame() { - if (accelerated_frame_drawn_callback_.is_null()) - return; - accelerated_frame_drawn_callback_.Run(); - accelerated_frame_drawn_callback_.Reset(); - if (view_) - view_->AcceleratedWidgetSwapCompleted(accelerated_latency_info_); - accelerated_latency_info_.clear(); -} - -void AcceleratedWidgetMac::IOSurfaceLayerHitError() { - // Perform all acks that would have been done if the frame had succeeded, to - // un-block the compositor and renderer. - AcknowledgeAcceleratedFrame(); - - // Poison the context being used and request a mulligan. - [io_surface_layer_ poisonContextAndSharegroup]; - - if (view_) - view_->AcceleratedWidgetHitError(); -} - -void AcceleratedWidgetMacGotAcceleratedFrame( - gfx::AcceleratedWidget widget, uint64 surface_handle, - const std::vector<ui::LatencyInfo>& latency_info, +void AcceleratedWidgetMacGotFrame( + gfx::AcceleratedWidget widget, + CAContextID ca_context_id, + base::ScopedCFTypeRef<IOSurfaceRef> io_surface, const gfx::Size& pixel_size, float scale_factor, - const gfx::Rect& pixel_damage_rect, - const base::Closure& drawn_callback, - bool* disable_throttling, int* renderer_id, - base::TimeTicks* vsync_timebase, base::TimeDelta* vsync_interval) { - AcceleratedWidgetMac* accelerated_widget_mac = - GetHelperFromAcceleratedWidget(widget); - if (accelerated_widget_mac) { - accelerated_widget_mac->GotAcceleratedFrame( - surface_handle, latency_info, pixel_size, scale_factor, - pixel_damage_rect, drawn_callback); - *disable_throttling = - accelerated_widget_mac->IsRendererThrottlingDisabled(); - *renderer_id = accelerated_widget_mac->GetRendererID(); - accelerated_widget_mac->GetVSyncParameters(vsync_timebase, vsync_interval); - } else { - *disable_throttling = false; - *renderer_id = 0; + base::TimeTicks* vsync_timebase, + base::TimeDelta* vsync_interval) { + if (vsync_timebase) *vsync_timebase = base::TimeTicks(); + if (vsync_interval) *vsync_interval = base::TimeDelta(); - } -} -void AcceleratedWidgetMacGotSoftwareFrame( - gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas) { AcceleratedWidgetMac* accelerated_widget_mac = GetHelperFromAcceleratedWidget(widget); - if (accelerated_widget_mac) - accelerated_widget_mac->GotSoftwareFrame(scale_factor, canvas); + + if (accelerated_widget_mac) { + accelerated_widget_mac->GotFrame(ca_context_id, io_surface, pixel_size, + scale_factor); + if (vsync_timebase && vsync_interval) { + accelerated_widget_mac->GetVSyncParameters(vsync_timebase, + vsync_interval); + } + } } } // namespace ui diff --git a/chromium/ui/accelerated_widget_mac/display_link_mac.cc b/chromium/ui/accelerated_widget_mac/display_link_mac.cc index 1945d2bcaba..d9cc46876f9 100644 --- a/chromium/ui/accelerated_widget_mac/display_link_mac.cc +++ b/chromium/ui/accelerated_widget_mac/display_link_mac.cc @@ -4,6 +4,8 @@ #include "ui/accelerated_widget_mac/display_link_mac.h" +#include <stdint.h> + #include "base/logging.h" #include "base/message_loop/message_loop.h" #include "base/trace_event/trace_event.h" @@ -12,8 +14,9 @@ namespace base { template<> struct ScopedTypeRefTraits<CVDisplayLinkRef> { - static void Retain(CVDisplayLinkRef object) { - CVDisplayLinkRetain(object); + static CVDisplayLinkRef InvalidValue() { return nullptr; } + static CVDisplayLinkRef Retain(CVDisplayLinkRef object) { + return CVDisplayLinkRetain(object); } static void Release(CVDisplayLinkRef object) { CVDisplayLinkRelease(object); @@ -120,8 +123,8 @@ void DisplayLinkMac::Tick(const CVTimeStamp& cv_time) { DCHECK((cv_time.videoRefreshPeriod & ~0xffffFFFFull) == 0ull); // Verify that the numerator and denominator make some sense. - uint32 numerator = static_cast<uint32>(cv_time.videoRefreshPeriod); - uint32 denominator = cv_time.videoTimeScale; + uint32_t numerator = static_cast<uint32_t>(cv_time.videoRefreshPeriod); + uint32_t denominator = cv_time.videoTimeScale; if (numerator <= 0 || denominator <= 0) { LOG(WARNING) << "Unexpected numerator or denominator, bailing."; return; @@ -130,7 +133,7 @@ void DisplayLinkMac::Tick(const CVTimeStamp& cv_time) { timebase_ = base::TimeTicks::FromInternalValue( cv_time.hostTime / 1000); interval_ = base::TimeDelta::FromMicroseconds( - 1000000 * static_cast<int64>(numerator) / denominator); + 1000000 * static_cast<int64_t>(numerator) / denominator); timebase_and_interval_valid_ = true; // Don't restart the display link for 10 seconds. diff --git a/chromium/ui/accelerated_widget_mac/io_surface_context.h b/chromium/ui/accelerated_widget_mac/io_surface_context.h index bf2b2547113..b84eb719675 100644 --- a/chromium/ui/accelerated_widget_mac/io_surface_context.h +++ b/chromium/ui/accelerated_widget_mac/io_surface_context.h @@ -8,7 +8,6 @@ #include <OpenGL/OpenGL.h> #include <map> -#include "base/basictypes.h" #include "base/lazy_instance.h" #include "base/mac/scoped_nsobject.h" #include "base/memory/ref_counted.h" diff --git a/chromium/ui/accelerated_widget_mac/io_surface_layer.h b/chromium/ui/accelerated_widget_mac/io_surface_layer.h deleted file mode 100644 index 6e2597954a6..00000000000 --- a/chromium/ui/accelerated_widget_mac/io_surface_layer.h +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2013 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_ACCELERATED_WIDGET_MAC_IO_SURFACE_LAYER_H_ -#define UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_LAYER_H_ - -#import <Cocoa/Cocoa.h> - -#include "base/mac/scoped_cftyperef.h" -#include "base/memory/ref_counted.h" -#include "base/timer/timer.h" -#include "ui/gfx/geometry/size.h" - -@class IOSurfaceLayer; - -namespace ui { - -class IOSurfaceTexture; -class IOSurfaceContext; - -// The interface through which the IOSurfaceLayer calls back into -// the structrue that created it (RenderWidgetHostViewMac or -// BrowserCompositorViewMac). -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 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 IOSurfaceLayerDidDrawFrame() = 0; - - // Called when an error prevents the frame from being drawn. - virtual void IOSurfaceLayerHitError() = 0; -}; - -// 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(); - - // Called when the IOSurfaceLayer gets a new frame. - void GotNewFrame(); - - // Called whenever -[IOSurfaceLayer setNeedsDisplay] is called. - 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. - IOSurfaceLayerClient* const client_; - - // The layer that owns this helper. - 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 - // that cause setNeedsDisplay to be called on the layer. - bool needs_display_; - - // This is set when a frame is received, and un-set when the frame is drawn. - bool has_pending_frame_; - - // Incremented every time that this layer is asked to draw but does not have - // new content to draw. - uint64 did_not_draw_counter_; - - // Set when inside a BeginPumpingFrames/EndPumpingFrames block. - bool is_pumping_frames_; - - // The browser places back-pressure on the GPU by not acknowledging swap - // 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 timer_; -}; - -} // namespace ui - -// The CoreAnimation layer for drawing accelerated content. -@interface IOSurfaceLayer : CAOpenGLLayer { - @private - scoped_refptr<ui::IOSurfaceTexture> iosurface_; - scoped_refptr<ui::IOSurfaceContext> context_; - - scoped_ptr<ui::IOSurfaceLayerHelper> helper_; -} - -- (id)initWithClient:(ui::IOSurfaceLayerClient*)client - withScaleFactor:(float)scale_factor - needsGLFinishWorkaround:(bool)needs_gl_finish_workaround; - -- (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. -- (void)resetClient; - -// Called when a new frame is received. -- (void)gotNewFrame; - -// Force a draw immediately (even if this means re-displaying a previously -// displayed frame). -- (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 -// run loop. -- (void)beginPumpingFrames; -- (void)endPumpingFrames; -@end - -#endif // UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_LAYER_H_ diff --git a/chromium/ui/accelerated_widget_mac/io_surface_layer.mm b/chromium/ui/accelerated_widget_mac/io_surface_layer.mm deleted file mode 100644 index d880316d916..00000000000 --- a/chromium/ui/accelerated_widget_mac/io_surface_layer.mm +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2013 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/accelerated_widget_mac/io_surface_layer.h" - -#include <CoreFoundation/CoreFoundation.h> -#include <OpenGL/CGLIOSurface.h> -#include <OpenGL/CGLRenderers.h> -#include <OpenGL/gl.h> -#include <OpenGL/OpenGL.h> - -#include "base/mac/sdk_forward_declarations.h" -#include "base/trace_event/trace_event.h" -#include "ui/accelerated_widget_mac/io_surface_context.h" -#include "ui/accelerated_widget_mac/io_surface_texture.h" -#include "ui/base/cocoa/animation_utils.h" -#include "ui/gfx/geometry/size_conversions.h" -#include "ui/gl/gpu_switching_manager.h" - -//////////////////////////////////////////////////////////////////////////////// -// IOSurfaceLayerHelper - -namespace ui { - -IOSurfaceLayerHelper::IOSurfaceLayerHelper( - IOSurfaceLayerClient* client, - IOSurfaceLayer* layer) - : client_(client), - layer_(layer), - needs_display_(false), - has_pending_frame_(false), - did_not_draw_counter_(0), - is_pumping_frames_(false), - timer_( - FROM_HERE, - base::TimeDelta::FromSeconds(1) / 6, - this, - &IOSurfaceLayerHelper::TimerFired) {} - -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 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); - - has_pending_frame_ = true; - needs_display_ = true; - timer_.Reset(); - - // If reqested, draw immediately and don't bother trying to use the - // 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_->IOSurfaceLayerShouldAckImmediately()) { - SetNeedsDisplayAndDisplayAndAck(); - } else { - if (![layer_ isAsynchronous]) - [layer_ setAsynchronous:YES]; - } -} - -void IOSurfaceLayerHelper::SetNeedsDisplay() { - needs_display_ = true; -} - -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_) { - did_not_draw_counter_ = 0; - } else { - did_not_draw_counter_ += 1; - if (did_not_draw_counter_ == 30) - [layer_ setAsynchronous:NO]; - } - - if (needs_display_) { - // If there is a draw pending then increase the signal from 2 to 3, to - // indicate that we are in the state where there is a swap pending and - // CoreAnimation has been committed to draw it. - TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 3); - } else { - // If there is not a draw pending, then give an instantaneous blip up from - // 0 to 1, indicating that CoreAnimation was ready to draw a frame but we - // were not (or didn't have new content to draw). - TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 1); - TRACE_COUNTER_ID1("browser", "PendingSwapAck", this, 0); - } - - return needs_display_; -} - -void IOSurfaceLayerHelper::DidDraw(bool success) { - needs_display_ = false; - AckPendingFrame(success); -} - -void IOSurfaceLayerHelper::AckPendingFrame(bool success) { - if (!has_pending_frame_) - return; - has_pending_frame_ = false; - if (success) - client_->IOSurfaceLayerDidDrawFrame(); - else - 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 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 - // workaround. - // http://crbug.com/395827 - if ([layer_ isAsynchronous]) - [layer_ setAsynchronous:NO]; - - [layer_ setNeedsDisplay]; - DisplayIfNeededAndAck(); -} - -void IOSurfaceLayerHelper::DisplayIfNeededAndAck() { - if (!needs_display_) - return; - - // As in SetNeedsDisplayAndDisplayAndAck, disable asynchronous drawing before - // issuing displayIfNeeded. - // http://crbug.com/395827 - if ([layer_ isAsynchronous]) - [layer_ setAsynchronous:NO]; - - // Do not bother drawing while pumping new frames -- wait until the waiting - // block ends to draw any of the new frames. - if (!is_pumping_frames_) - [layer_ displayIfNeeded]; - - // Calls to setNeedsDisplay can sometimes be ignored, especially if issued - // rapidly (e.g, with vsync off). This is unacceptable because the failure - // to ack a single frame will hang the renderer. Ensure that the renderer - // not be blocked by lying and claiming that we drew the frame. - AckPendingFrame(true); -} - -void IOSurfaceLayerHelper::TimerFired() { - DisplayIfNeededAndAck(); -} - -void IOSurfaceLayerHelper::BeginPumpingFrames() { - is_pumping_frames_ = true; -} - -void IOSurfaceLayerHelper::EndPumpingFrames() { - is_pumping_frames_ = false; - DisplayIfNeededAndAck(); -} - -} // namespace ui - -//////////////////////////////////////////////////////////////////////////////// -// IOSurfaceLayer - -@implementation IOSurfaceLayer - -- (id)initWithClient:(ui::IOSurfaceLayerClient*)client - withScaleFactor:(float)scale_factor - needsGLFinishWorkaround:(bool)needs_gl_finish_workaround { - if (self = [super init]) { - helper_.reset(new ui::IOSurfaceLayerHelper(client, self)); - - iosurface_ = ui::IOSurfaceTexture::Create( - needs_gl_finish_workaround, false); - context_ = ui::IOSurfaceContext::Get( - ui::IOSurfaceContext::kCALayerContext); - if (!iosurface_.get() || !context_.get()) { - LOG(ERROR) << "Failed create CompositingIOSurface or context"; - [self resetClient]; - [self release]; - return nil; - } - - [self setAnchorPoint:CGPointMake(0, 0)]; - // Setting contents gravity is necessary to prevent the layer from being - // scaled during dyanmic resizes (especially with devtools open). - [self setContentsGravity:kCAGravityTopLeft]; - if ([self respondsToSelector:(@selector(setContentsScale:))]) { - [self setContentsScale:scale_factor]; - } - } - return self; -} - -- (void)dealloc { - DCHECK(!helper_); - [super dealloc]; -} - -- (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id - withPixelSize:(gfx::Size)pixel_size - withScaleFactor:(float)scale_factor { - return iosurface_->SetIOSurface(io_surface_id, pixel_size); -} - -- (void)poisonContextAndSharegroup { - context_->PoisonContextAndSharegroup(); -} - -- (bool)hasBeenPoisoned { - return context_->HasBeenPoisoned(); -} - -- (float)scaleFactor { - if ([self respondsToSelector:(@selector(contentsScale))]) - return [self contentsScale]; - return 1; -} - -- (int)rendererID { - GLint current_renderer_id = -1; - if (CGLGetParameter(context_->cgl_context(), - kCGLCPCurrentRendererID, - ¤t_renderer_id) == kCGLNoError) { - return current_renderer_id & kCGLRendererIDMatchingMask; - } - return -1; -} - -- (void)resetClient { - helper_.reset(); -} - -- (void)gotNewFrame { - helper_->GotNewFrame(); -} - -- (void)setNeedsDisplayAndDisplayAndAck { - helper_->SetNeedsDisplayAndDisplayAndAck(); -} - -- (void)displayIfNeededAndAck { - helper_->DisplayIfNeededAndAck(); -} - -- (void)beginPumpingFrames { - helper_->BeginPumpingFrames(); -} - -- (void)endPumpingFrames { - helper_->EndPumpingFrames(); -} - -// The remaining methods implement the CAOpenGLLayer interface. - -- (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { - if (!context_.get()) - return [super copyCGLPixelFormatForDisplayMask:mask]; - return CGLRetainPixelFormat(CGLGetPixelFormat(context_->cgl_context())); -} - -- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { - if (!context_.get()) - return [super copyCGLContextForPixelFormat:pixelFormat]; - return CGLRetainContext(context_->cgl_context()); -} - -- (void)setNeedsDisplay { - if (helper_) - helper_->SetNeedsDisplay(); - [super setNeedsDisplay]; -} - -- (BOOL)canDrawInCGLContext:(CGLContextObj)glContext - pixelFormat:(CGLPixelFormatObj)pixelFormat - forLayerTime:(CFTimeInterval)timeInterval - displayTime:(const CVTimeStamp*)timeStamp { - if (helper_) - return helper_->CanDraw(); - return NO; -} - -- (void)drawInCGLContext:(CGLContextObj)glContext - pixelFormat:(CGLPixelFormatObj)pixelFormat - forLayerTime:(CFTimeInterval)timeInterval - displayTime:(const CVTimeStamp*)timeStamp { - TRACE_EVENT0("browser", "IOSurfaceLayer::drawInCGLContext"); - - bool draw_succeeded = iosurface_->DrawIOSurface(); - if (helper_) - helper_->DidDraw(draw_succeeded); - - [super drawInCGLContext:glContext - pixelFormat:pixelFormat - forLayerTime:timeInterval - displayTime:timeStamp]; -} - -@end diff --git a/chromium/ui/accelerated_widget_mac/io_surface_texture.h b/chromium/ui/accelerated_widget_mac/io_surface_texture.h deleted file mode 100644 index d971b584f34..00000000000 --- a/chromium/ui/accelerated_widget_mac/io_surface_texture.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) 2012 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_ACCELERATED_WIDGET_MAC_IO_SURFACE_TEXTURE_H_ -#define UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_TEXTURE_H_ - -#include <deque> -#include <list> -#include <vector> - -#import <Cocoa/Cocoa.h> -#include <IOSurface/IOSurface.h> -#include <QuartzCore/QuartzCore.h> - -#include "base/callback.h" -#include "base/lazy_instance.h" -#include "base/mac/scoped_cftyperef.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/time/time.h" -#include "ui/gfx/geometry/size.h" -#include "ui/gfx/native_widget_types.h" - -class SkBitmap; - -namespace gfx { -class Rect; -} - -namespace ui { - -class IOSurfaceContext; -class RenderWidgetHostViewFrameSubscriber; -class RenderWidgetHostViewMac; - -// This class manages an OpenGL context and IOSurfaceTexture for the accelerated -// compositing code path. The GL context is attached to -// RenderWidgetHostViewCocoa for blitting the IOSurfaceTexture. -class IOSurfaceTexture - : public base::RefCounted<IOSurfaceTexture> { - public: - static scoped_refptr<IOSurfaceTexture> Create( - bool needs_gl_finish_workaround, - bool use_ns_apis); - - // Returns true if there is no need to call SetIOSurface with the provided - // values. - bool IsUpToDate( - IOSurfaceID io_surface_id, const gfx::Size& pixel_size) const; - - // Set IOSurfaceTexture that will be drawn on the next NSView drawRect. - bool SetIOSurface( - IOSurfaceID io_surface_id, - const gfx::Size& pixel_size) WARN_UNUSED_RESULT; - - // Blit the IOSurface to the rectangle specified by |window_rect| in DIPs, - // with the origin in the lower left corner. If the window rect's size is - // larger than the IOSurface, the remaining right and bottom edges will be - // white. |window_scale_factor| is 1 in normal views, 2 in HiDPI views. - bool DrawIOSurface() WARN_UNUSED_RESULT; - bool DrawIOSurfaceWithDamageRect(gfx::Rect damage_rect) WARN_UNUSED_RESULT; - - // Returns true if the offscreen context used by this surface has been - // poisoned. - bool HasBeenPoisoned() const; - - private: - friend class base::RefCounted<IOSurfaceTexture>; - - IOSurfaceTexture( - const scoped_refptr<IOSurfaceContext>& context, - bool use_ns_apis, - bool needs_gl_finish_workaround); - ~IOSurfaceTexture(); - - // Unref the IOSurfaceTexture and delete the associated GL texture. If the GPU - // process is no longer referencing it, this will delete the IOSurface. - void ReleaseIOSurfaceAndTexture(); - - // Check for GL errors and store the result in error_. Only return new - // errors - GLenum GetAndSaveGLError(); - - // Offscreen context used for all operations other than drawing to the - // screen. This is in the same share group as the contexts used for - // drawing, and is the same for all IOSurfaces in all windows. - scoped_refptr<IOSurfaceContext> offscreen_context_; - - // The IOSurface and its non-rounded size. - base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; - gfx::Size pixel_size_; - - // The "live" OpenGL texture referring to this IOSurfaceRef. Note - // that per the CGLTexImageIOSurface2D API we do not need to - // explicitly update this texture's contents once created. All we - // need to do is ensure it is re-bound before attempting to draw - // with it. - GLuint texture_; - - // Error saved by GetAndSaveGLError - GLint gl_error_; - - // Aggressive IOSurface eviction logic. When using CoreAnimation, IOSurfaces - // are used only transiently to transfer from the GPU process to the browser - // process. Once the IOSurface has been drawn to its CALayer, the CALayer - // will not need updating again until its view is hidden and re-shown. - // Aggressively evict surfaces when more than 8 (the number allowed by the - // memory manager for fast tab switching) are allocated. - enum { - kMaximumUnevictedSurfaces = 8, - }; - typedef std::list<IOSurfaceTexture*> EvictionQueue; - void EvictionMarkUpdated(); - void EvictionMarkEvicted(); - EvictionQueue::iterator eviction_queue_iterator_; - bool eviction_has_been_drawn_since_updated_; - - const bool needs_gl_finish_workaround_; - - // Set if this is for access through NS APIs. - const bool using_ns_apis_; - - static void EvictionScheduleDoEvict(); - static void EvictionDoEvict(); - static base::LazyInstance<EvictionQueue> eviction_queue_; - static bool eviction_scheduled_; -}; - -} // namespace ui - -#endif // UI_ACCELERATED_WIDGET_MAC_IO_SURFACE_TEXTURE_H_ diff --git a/chromium/ui/accelerated_widget_mac/io_surface_texture.mm b/chromium/ui/accelerated_widget_mac/io_surface_texture.mm deleted file mode 100644 index 1069a0b9c51..00000000000 --- a/chromium/ui/accelerated_widget_mac/io_surface_texture.mm +++ /dev/null @@ -1,325 +0,0 @@ -// Copyright (c) 2012 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/accelerated_widget_mac/io_surface_texture.h" - -#include <OpenGL/CGLIOSurface.h> -#include <OpenGL/CGLRenderers.h> -#include <OpenGL/gl.h> -#include <OpenGL/OpenGL.h> - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/callback_helpers.h" -#include "base/command_line.h" -#include "base/logging.h" -#include "base/mac/bind_objc_block.h" -#include "base/message_loop/message_loop.h" -#include "base/threading/platform_thread.h" -#include "base/trace_event/trace_event.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/accelerated_widget_mac/io_surface_context.h" -#include "ui/base/ui_base_switches.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/gfx/geometry/size_conversions.h" -#include "ui/gl/gl_context.h" - -namespace ui { - -// static -scoped_refptr<IOSurfaceTexture> IOSurfaceTexture::Create( - bool needs_gl_finish_workaround, - bool use_ns_apis) { - scoped_refptr<IOSurfaceContext> offscreen_context; - if (!use_ns_apis) { - offscreen_context = IOSurfaceContext::Get( - IOSurfaceContext::kOffscreenContext); - if (!offscreen_context.get()) { - LOG(ERROR) << "Failed to create context for offscreen operations"; - return NULL; - } - } - return new IOSurfaceTexture( - offscreen_context, use_ns_apis, needs_gl_finish_workaround); -} - -IOSurfaceTexture::IOSurfaceTexture( - const scoped_refptr<IOSurfaceContext>& offscreen_context, - bool use_ns_apis, - bool needs_gl_finish_workaround) - : offscreen_context_(offscreen_context), - texture_(0), - gl_error_(GL_NO_ERROR), - eviction_queue_iterator_(eviction_queue_.Get().end()), - eviction_has_been_drawn_since_updated_(false), - needs_gl_finish_workaround_(needs_gl_finish_workaround), - using_ns_apis_(use_ns_apis) { -} - -IOSurfaceTexture::~IOSurfaceTexture() { - ReleaseIOSurfaceAndTexture(); - offscreen_context_ = NULL; - DCHECK(eviction_queue_iterator_ == eviction_queue_.Get().end()); -} - -bool IOSurfaceTexture::DrawIOSurface() { - return DrawIOSurfaceWithDamageRect(gfx::Rect(pixel_size_)); -} - -bool IOSurfaceTexture::DrawIOSurfaceWithDamageRect(gfx::Rect damage_rect) { - TRACE_EVENT0("browser", "IOSurfaceTexture::DrawIOSurfaceWithDamageRect"); - DCHECK(CGLGetCurrentContext()); - - // If we have release the IOSurface, clear the screen to light grey and - // early-out. - if (!io_surface_) { - glClearColor(0.9, 0.9, 0.9, 1); - glClear(GL_COLOR_BUFFER_BIT); - return false; - } - - // The viewport is the size of the CALayer, which should always match the - // IOSurface pixel size. - GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); - gfx::Rect viewport_rect(viewport[0], viewport[1], viewport[2], viewport[3]); - - // Set the projection matrix to match 1 unit to 1 pixel. - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, viewport_rect.width(), - pixel_size_.height() - viewport_rect.height(), pixel_size_.height(), - -1, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - // Draw a quad the size of the IOSurface. This should cover the full viewport. - glColor4f(1, 1, 1, 1); - glEnable(GL_TEXTURE_RECTANGLE_ARB); - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); - glBegin(GL_QUADS); - glTexCoord2f(damage_rect.x(), damage_rect.y()); - glVertex2f(damage_rect.x(), damage_rect.y()); - glTexCoord2f(damage_rect.right(), damage_rect.y()); - glVertex2f(damage_rect.right(), damage_rect.y()); - glTexCoord2f(damage_rect.right(), damage_rect.bottom()); - glVertex2f(damage_rect.right(), damage_rect.bottom()); - glTexCoord2f(damage_rect.x(), damage_rect.bottom()); - glVertex2f(damage_rect.x(), damage_rect.bottom()); - glEnd(); - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - glDisable(GL_TEXTURE_RECTANGLE_ARB); - - // Workaround for issue 158469. Issue a dummy draw call with texture_ not - // bound to a texture, in order to shake all references to the IOSurface out - // of the driver. - glBegin(GL_TRIANGLES); - glEnd(); - - if (needs_gl_finish_workaround_) { - TRACE_EVENT0("gpu", "glFinish"); - glFinish(); - } - - // Check if any of the drawing calls result in an error. - GetAndSaveGLError(); - bool result = true; - if (gl_error_ != GL_NO_ERROR) { - LOG(ERROR) << "GL error in DrawIOSurface: " << gl_error_; - result = false; - // If there was an error, clear the screen to a light grey to avoid - // rendering artifacts. - glClearColor(0.8, 0.8, 0.8, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - } - - eviction_has_been_drawn_since_updated_ = true; - return result; -} - -bool IOSurfaceTexture::IsUpToDate( - IOSurfaceID io_surface_id, const gfx::Size& pixel_size) const { - return io_surface_ && - io_surface_id == IOSurfaceGetID(io_surface_) && - pixel_size == pixel_size_; -} - -bool IOSurfaceTexture::SetIOSurface( - IOSurfaceID io_surface_id, const gfx::Size& pixel_size) { - TRACE_EVENT0("browser", "IOSurfaceTexture::MapIOSurfaceToTexture"); - - // Destroy the old IOSurface and texture if it is no longer needed. - bool needs_new_iosurface = - !io_surface_ || io_surface_id != IOSurfaceGetID(io_surface_); - if (needs_new_iosurface) - ReleaseIOSurfaceAndTexture(); - - // Note that because IOSurface sizes are rounded, the same IOSurface may have - // two different sizes associated with it, so update the sizes before the - // early-out. - pixel_size_ = pixel_size; - - // Early-out if the IOSurface has not changed. - if (!needs_new_iosurface) - return true; - - // If we early-out at any point from now on, it's because of an error, and we - // should destroy the texture and release the IOSurface. - base::ScopedClosureRunner error_runner(base::BindBlock(^{ - ReleaseIOSurfaceAndTexture(); - })); - - // Open the IOSurface handle. - io_surface_.reset(IOSurfaceLookup(io_surface_id)); - if (!io_surface_) - return false; - - // Actual IOSurface size is rounded up to reduce reallocations during window - // resize. Get the actual size to properly map the texture. - gfx::Size rounded_size(IOSurfaceGetWidth(io_surface_), - IOSurfaceGetHeight(io_surface_)); - - // Create the GL texture and set it to be backed by the IOSurface. - CGLError cgl_error = kCGLNoError; - { - scoped_ptr<gfx::ScopedCGLSetCurrentContext> scoped_set_current_context; - if (offscreen_context_) { - scoped_set_current_context.reset(new gfx::ScopedCGLSetCurrentContext( - offscreen_context_->cgl_context())); - } else { - DCHECK(CGLGetCurrentContext()); - } - - glGenTextures(1, &texture_); - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); - glTexParameterf( - GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf( - GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - cgl_error = CGLTexImageIOSurface2D( - CGLGetCurrentContext(), - GL_TEXTURE_RECTANGLE_ARB, - GL_RGBA, - rounded_size.width(), - rounded_size.height(), - GL_BGRA, - GL_UNSIGNED_INT_8_8_8_8_REV, - io_surface_.get(), - 0 /* plane */); - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); - GetAndSaveGLError(); - } - - // Return failure if an error was encountered by CGL or GL. - if (cgl_error != kCGLNoError) { - LOG(ERROR) << "CGLTexImageIOSurface2D failed with CGL error: " << cgl_error; - return false; - } - if (gl_error_ != GL_NO_ERROR) { - LOG(ERROR) << "Hit GL error in SetIOSurface: " << gl_error_; - return false; - } - - ignore_result(error_runner.Release()); - return true; -} - -void IOSurfaceTexture::ReleaseIOSurfaceAndTexture() { - scoped_ptr<gfx::ScopedCGLSetCurrentContext> scoped_set_current_context; - if (offscreen_context_) { - scoped_set_current_context.reset(new gfx::ScopedCGLSetCurrentContext( - offscreen_context_->cgl_context())); - } else { - DCHECK(CGLGetCurrentContext()); - } - - if (texture_) { - glDeleteTextures(1, &texture_); - texture_ = 0; - } - pixel_size_ = gfx::Size(); - io_surface_.reset(); - - EvictionMarkEvicted(); -} - -bool IOSurfaceTexture::HasBeenPoisoned() const { - if (offscreen_context_) - return offscreen_context_->HasBeenPoisoned(); - return false; -} - -GLenum IOSurfaceTexture::GetAndSaveGLError() { - GLenum gl_error = glGetError(); - if (gl_error_ == GL_NO_ERROR) - gl_error_ = gl_error; - return gl_error; -} - -void IOSurfaceTexture::EvictionMarkUpdated() { - EvictionMarkEvicted(); - eviction_queue_.Get().push_back(this); - eviction_queue_iterator_ = --eviction_queue_.Get().end(); - eviction_has_been_drawn_since_updated_ = false; - EvictionScheduleDoEvict(); -} - -void IOSurfaceTexture::EvictionMarkEvicted() { - if (eviction_queue_iterator_ == eviction_queue_.Get().end()) - return; - eviction_queue_.Get().erase(eviction_queue_iterator_); - eviction_queue_iterator_ = eviction_queue_.Get().end(); - eviction_has_been_drawn_since_updated_ = false; -} - -// static -void IOSurfaceTexture::EvictionScheduleDoEvict() { - if (eviction_scheduled_) - return; - if (eviction_queue_.Get().size() <= kMaximumUnevictedSurfaces) - return; - - eviction_scheduled_ = true; - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&IOSurfaceTexture::EvictionDoEvict)); -} - -// static -void IOSurfaceTexture::EvictionDoEvict() { - eviction_scheduled_ = false; - // Walk the list of allocated surfaces from least recently used to most - // recently used. - for (EvictionQueue::iterator it = eviction_queue_.Get().begin(); - it != eviction_queue_.Get().end();) { - IOSurfaceTexture* surface = *it; - ++it; - - // If the number of IOSurfaces allocated is less than the threshold, - // stop walking the list of surfaces. - if (eviction_queue_.Get().size() <= kMaximumUnevictedSurfaces) - break; - - // Don't evict anything that has not yet been drawn. - if (!surface->eviction_has_been_drawn_since_updated_) - continue; - - // Don't evict anything that doesn't have an offscreen context (as we have - // context in which to delete the texture). - if (!surface->offscreen_context_) - continue; - - // Evict the surface. - surface->ReleaseIOSurfaceAndTexture(); - } -} - -// static -base::LazyInstance<IOSurfaceTexture::EvictionQueue> - IOSurfaceTexture::eviction_queue_; - -// static -bool IOSurfaceTexture::eviction_scheduled_ = false; - -} // namespace ui diff --git a/chromium/ui/accelerated_widget_mac/software_layer.h b/chromium/ui/accelerated_widget_mac/software_layer.h deleted file mode 100644 index 314314e99db..00000000000 --- a/chromium/ui/accelerated_widget_mac/software_layer.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_ACCELERATED_WIDGET_MAC_SOFTWARE_LAYER_H_ -#define UI_ACCELERATED_WIDGET_MAC_SOFTWARE_LAYER_H_ - -#import <Cocoa/Cocoa.h> - -#include "ui/gfx/geometry/size.h" - -@interface SoftwareLayer : CALayer -- (id)init; - -- (void)setContentsToData:(const void *)data - withRowBytes:(size_t)rowBytes - withPixelSize:(gfx::Size)pixelSize - withScaleFactor:(float)scaleFactor; -@end - - -#endif // UI_ACCELERATED_WIDGET_MAC_SOFTWARE_LAYER_H_ diff --git a/chromium/ui/accelerated_widget_mac/software_layer.mm b/chromium/ui/accelerated_widget_mac/software_layer.mm deleted file mode 100644 index abdef169059..00000000000 --- a/chromium/ui/accelerated_widget_mac/software_layer.mm +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/accelerated_widget_mac/software_layer.h" - -#include "base/mac/mac_util.h" -#include "base/mac/scoped_cftyperef.h" -#include "base/mac/sdk_forward_declarations.h" -#include "base/trace_event/trace_event.h" -#include "ui/base/cocoa/animation_utils.h" - -@implementation SoftwareLayer - -- (id)init { - if (self = [super init]) { - [self setAnchorPoint:CGPointMake(0, 0)]; - // Setting contents gravity is necessary to prevent the layer from being - // scaled during dyanmic resizes (especially with devtools open). - [self setContentsGravity:kCAGravityTopLeft]; - } - return self; -} - -- (void)setContentsToData:(const void *)data - withRowBytes:(size_t)rowBytes - withPixelSize:(gfx::Size)pixelSize - withScaleFactor:(float)scaleFactor { - TRACE_EVENT0("browser", "-[SoftwareLayer setContentsToData]"); - - // Disable animating the contents change or the scale factor change. - ScopedCAActionDisabler disabler; - - // Set the contents of the software CALayer to be a CGImage with the provided - // pixel data. Make a copy of the data before backing the image with them, - // because the same buffer will be reused for the next frame. - base::ScopedCFTypeRef<CFDataRef> dataCopy( - CFDataCreate(NULL, - static_cast<const UInt8 *>(data), - rowBytes * pixelSize.height())); - base::ScopedCFTypeRef<CGDataProviderRef> dataProvider( - CGDataProviderCreateWithCFData(dataCopy)); - base::ScopedCFTypeRef<CGImageRef> image( - CGImageCreate(pixelSize.width(), - pixelSize.height(), - 8, - 32, - rowBytes, - base::mac::GetSystemColorSpace(), - kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, - dataProvider, - NULL, - false, - kCGRenderingIntentDefault)); - [self setContents:(id)image.get()]; - [self setBounds:CGRectMake( - 0, 0, pixelSize.width() / scaleFactor, pixelSize.height() / scaleFactor)]; - - // Set the contents scale of the software CALayer. - if ([self respondsToSelector:(@selector(contentsScale))] && - [self respondsToSelector:(@selector(setContentsScale:))] && - [self contentsScale] != scaleFactor) { - [self setContentsScale:scaleFactor]; - } -} - -@end diff --git a/chromium/ui/accelerated_widget_mac/surface_handle_types.cc b/chromium/ui/accelerated_widget_mac/surface_handle_types.cc deleted file mode 100644 index 22d2f6dc67a..00000000000 --- a/chromium/ui/accelerated_widget_mac/surface_handle_types.cc +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/accelerated_widget_mac/surface_handle_types.h" - -#include "base/logging.h" - -namespace ui { -namespace { - -// The type of the handle is stored in the upper 64 bits. -const uint64 kTypeMask = 0xFFFFFFFFull << 32; - -const uint64 kTypeIOSurface = 0x01010101ull << 32; -const uint64 kTypeCAContext = 0x02020202ull << 32; - -// To make it a bit less likely that we'll just cast off the top bits of the -// handle to get the ID, XOR lower bits with a type-specific mask. -const uint32 kXORMaskIOSurface = 0x01010101; -const uint32 kXORMaskCAContext = 0x02020202; - -} // namespace - -SurfaceHandleType GetSurfaceHandleType(uint64 surface_handle) { - switch(surface_handle & kTypeMask) { - case kTypeIOSurface: - return kSurfaceHandleTypeIOSurface; - case kTypeCAContext: - return kSurfaceHandleTypeCAContext; - } - return kSurfaceHandleTypeInvalid; -} - -IOSurfaceID IOSurfaceIDFromSurfaceHandle(uint64 surface_handle) { - DCHECK_EQ(kSurfaceHandleTypeIOSurface, GetSurfaceHandleType(surface_handle)); - return static_cast<uint32>(surface_handle) ^ kXORMaskIOSurface; -} - -CAContextID CAContextIDFromSurfaceHandle(uint64 surface_handle) { - DCHECK_EQ(kSurfaceHandleTypeCAContext, GetSurfaceHandleType(surface_handle)); - return static_cast<uint32>(surface_handle) ^ kXORMaskCAContext; -} - -uint64 SurfaceHandleFromIOSurfaceID(IOSurfaceID io_surface_id) { - return kTypeIOSurface | (io_surface_id ^ kXORMaskIOSurface); -} - -uint64 SurfaceHandleFromCAContextID(CAContextID ca_context_id) { - return kTypeCAContext | (ca_context_id ^ kXORMaskCAContext); -} - -} // namespace ui diff --git a/chromium/ui/accelerated_widget_mac/surface_handle_types.h b/chromium/ui/accelerated_widget_mac/surface_handle_types.h deleted file mode 100644 index 7b55ec94a51..00000000000 --- a/chromium/ui/accelerated_widget_mac/surface_handle_types.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_ACCELERATED_WIDGET_MAC_SURFACE_HANDLE_TYPES_H_ -#define UI_ACCELERATED_WIDGET_MAC_SURFACE_HANDLE_TYPES_H_ - -#include <IOSurface/IOSurface.h> -#include <OpenGL/CGLIOSurface.h> - -#include "base/basictypes.h" -#include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" -#include "ui/base/cocoa/remote_layer_api.h" - -namespace ui { - -// The surface handle passed between the GPU and browser process may refer to -// an IOSurface or a CAContext. These helper functions must be used to identify -// and translate between the types. -enum SurfaceHandleType { - kSurfaceHandleTypeInvalid, - kSurfaceHandleTypeIOSurface, - kSurfaceHandleTypeCAContext, -}; - -SurfaceHandleType GetSurfaceHandleType(uint64 surface_handle); - -CAContextID CAContextIDFromSurfaceHandle(uint64 surface_handle); -IOSurfaceID IOSurfaceIDFromSurfaceHandle(uint64 surface_handle); - -ACCELERATED_WIDGET_MAC_EXPORT -uint64 SurfaceHandleFromIOSurfaceID(IOSurfaceID io_surface_id); - -ACCELERATED_WIDGET_MAC_EXPORT -uint64 SurfaceHandleFromCAContextID(CAContextID ca_context_id); - -} // namespace ui - -#endif // UI_ACCELERATED_WIDGET_MAC_SURFACE_HANDLE_TYPES_H_ diff --git a/chromium/ui/accelerated_widget_mac/window_resize_helper_mac.cc b/chromium/ui/accelerated_widget_mac/window_resize_helper_mac.cc index f36aa91dcc4..f44f7ae829d 100644 --- a/chromium/ui/accelerated_widget_mac/window_resize_helper_mac.cc +++ b/chromium/ui/accelerated_widget_mac/window_resize_helper_mac.cc @@ -4,10 +4,13 @@ #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" +#include <stdint.h> + #include <list> #include "base/bind.h" #include "base/callback.h" +#include "base/macros.h" #include "base/single_thread_task_runner.h" #include "base/synchronization/lock.h" #include "base/synchronization/waitable_event.h" @@ -40,7 +43,7 @@ class WrappedTask { base::Closure closure_; base::TimeTicks can_run_time_; bool has_run_; - uint64 sequence_number_; + uint64_t sequence_number_; WrappedTaskQueue::iterator iterator_; // Back pointer to the pumpable task runner that this task is enqueued in. @@ -146,7 +149,7 @@ void WrappedTask::AddToTaskRunnerQueue( PumpableTaskRunner* pumpable_task_runner) { pumpable_task_runner_ = pumpable_task_runner; base::AutoLock lock(pumpable_task_runner_->task_queue_lock_); - static uint64 last_sequence_number = 0; + static uint64_t last_sequence_number = 0; last_sequence_number += 1; sequence_number_ = last_sequence_number; iterator_ = pumpable_task_runner_->task_queue_.insert( |