| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ | 5 #ifndef UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ |
| 6 #define UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ | 6 #define UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ |
| 7 | 7 |
| 8 #include <IOSurface/IOSurface.h> | 8 #include <IOSurface/IOSurface.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "base/time/time.h" |
| 12 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" | 13 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" |
| 13 #include "ui/accelerated_widget_mac/surface_handle_types.h" | 14 #include "ui/accelerated_widget_mac/surface_handle_types.h" |
| 14 #include "ui/events/latency_info.h" | |
| 15 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 18 | 18 |
| 19 #if defined(__OBJC__) | 19 #if defined(__OBJC__) |
| 20 #import <Cocoa/Cocoa.h> | 20 #import <Cocoa/Cocoa.h> |
| 21 #import "base/mac/scoped_nsobject.h" | 21 #import "base/mac/scoped_nsobject.h" |
| 22 #include "ui/base/cocoa/remote_layer_api.h" | 22 #include "ui/base/cocoa/remote_layer_api.h" |
| 23 #endif // __OBJC__ | 23 #endif // __OBJC__ |
| 24 | 24 |
| 25 class SkCanvas; | 25 class SkCanvas; |
| 26 | 26 |
| 27 namespace cc { | 27 namespace cc { |
| 28 class SoftwareFrameData; | 28 class SoftwareFrameData; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace ui { | 31 namespace ui { |
| 32 | 32 |
| 33 class AcceleratedWidgetMac; | 33 class AcceleratedWidgetMac; |
| 34 | 34 |
| 35 // A class through which an AcceleratedWidget may be bound to draw the contents | 35 // A class through which an AcceleratedWidget may be bound to draw the contents |
| 36 // of an NSView. An AcceleratedWidget may be bound to multiple different views | 36 // of an NSView. An AcceleratedWidget may be bound to multiple different views |
| 37 // throughout its lifetime (one at a time, though). | 37 // throughout its lifetime (one at a time, though). |
| 38 class AcceleratedWidgetMacNSView { | 38 class AcceleratedWidgetMacNSView { |
| 39 public: | 39 public: |
| 40 virtual NSView* AcceleratedWidgetGetNSView() const = 0; | 40 virtual NSView* AcceleratedWidgetGetNSView() const = 0; |
| 41 virtual bool AcceleratedWidgetShouldIgnoreBackpressure() const = 0; | |
| 42 virtual void AcceleratedWidgetGetVSyncParameters( | 41 virtual void AcceleratedWidgetGetVSyncParameters( |
| 43 base::TimeTicks* timebase, base::TimeDelta* interval) const = 0; | 42 base::TimeTicks* timebase, base::TimeDelta* interval) const = 0; |
| 44 virtual void AcceleratedWidgetSwapCompleted( | 43 virtual void AcceleratedWidgetSwapCompleted() = 0; |
| 45 const std::vector<ui::LatencyInfo>& latency_info) = 0; | |
| 46 virtual void AcceleratedWidgetHitError() = 0; | |
| 47 }; | 44 }; |
| 48 | 45 |
| 49 #if defined(__OBJC__) | 46 #if defined(__OBJC__) |
| 50 | 47 |
| 51 // AcceleratedWidgetMac owns a tree of CALayers. The widget may be passed | 48 // AcceleratedWidgetMac owns a tree of CALayers. The widget may be passed |
| 52 // to a ui::Compositor, which will cause, through its output surface, calls to | 49 // to a ui::Compositor, which will cause, through its output surface, calls to |
| 53 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed | 50 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed |
| 54 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper. | 51 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper. |
| 55 class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac { | 52 class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac { |
| 56 public: | 53 public: |
| 57 explicit AcceleratedWidgetMac(bool needs_gl_finish_workaround); | 54 explicit AcceleratedWidgetMac(bool needs_gl_finish_workaround); |
| 58 virtual ~AcceleratedWidgetMac(); | 55 virtual ~AcceleratedWidgetMac(); |
| 59 | 56 |
| 60 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; } | 57 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; } |
| 61 | 58 |
| 62 void SetNSView(AcceleratedWidgetMacNSView* view); | 59 void SetNSView(AcceleratedWidgetMacNSView* view); |
| 63 void ResetNSView(); | 60 void ResetNSView(); |
| 64 | 61 |
| 65 // Return true if the last frame swapped has a size in DIP of |dip_size|. | 62 // Return true if the last frame swapped has a size in DIP of |dip_size|. |
| 66 bool HasFrameOfSize(const gfx::Size& dip_size) const; | 63 bool HasFrameOfSize(const gfx::Size& dip_size) const; |
| 67 | 64 |
| 68 // Return the CGL renderer ID for the surface, if one is available. | |
| 69 int GetRendererID() const; | |
| 70 | |
| 71 // Populate the vsync parameters for the surface's display. | 65 // Populate the vsync parameters for the surface's display. |
| 72 void GetVSyncParameters( | 66 void GetVSyncParameters( |
| 73 base::TimeTicks* timebase, base::TimeDelta* interval) const; | 67 base::TimeTicks* timebase, base::TimeDelta* interval) const; |
| 74 | 68 |
| 75 // Return true if the renderer should not be throttled by GPU back-pressure. | 69 void GotFrame(CAContextID ca_context_id, |
| 76 bool IsRendererThrottlingDisabled() const; | 70 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 71 const gfx::Size& pixel_size, |
| 72 float scale_factor); |
| 77 | 73 |
| 78 // Mark a bracket in which new frames are being pumped in a restricted nested | 74 private: |
| 79 // run loop. | 75 void GotCAContextFrame(CAContextID ca_context_id, |
| 80 void BeginPumpingFrames(); | 76 const gfx::Size& pixel_size, |
| 81 void EndPumpingFrames(); | 77 float scale_factor); |
| 82 | |
| 83 void GotAcceleratedFrame(CAContextID ca_context_id, | |
| 84 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 85 const std::vector<ui::LatencyInfo>& latency_info, | |
| 86 const gfx::Size& pixel_size, | |
| 87 float scale_factor, | |
| 88 const gfx::Rect& pixel_damage_rect, | |
| 89 const base::Closure& drawn_callback); | |
| 90 | 78 |
| 91 void GotIOSurfaceFrame(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 79 void GotIOSurfaceFrame(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 92 const gfx::Size& pixel_size, | 80 const gfx::Size& pixel_size, |
| 93 float scale_factor, | 81 float scale_factor); |
| 94 bool flip_y); | |
| 95 | |
| 96 private: | |
| 97 void GotAcceleratedCAContextFrame(CAContextID ca_context_id, | |
| 98 const gfx::Size& pixel_size, | |
| 99 float scale_factor); | |
| 100 | |
| 101 void GotAcceleratedIOSurfaceFrame( | |
| 102 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 103 const gfx::Size& pixel_size, | |
| 104 float scale_factor); | |
| 105 | |
| 106 void AcknowledgeAcceleratedFrame(); | |
| 107 | 82 |
| 108 // Remove a layer from the heirarchy and destroy it. Because the accelerated | 83 // Remove a layer from the heirarchy and destroy it. Because the accelerated |
| 109 // layer types may be replaced by a layer of the same type, the layer to | 84 // layer types may be replaced by a layer of the same type, the layer to |
| 110 // destroy is parameterized, and, if it is the current layer, the current | 85 // destroy is parameterized, and, if it is the current layer, the current |
| 111 // layer is reset. | 86 // layer is reset. |
| 112 void DestroyCAContextLayer( | 87 void DestroyCAContextLayer( |
| 113 base::scoped_nsobject<CALayerHost> ca_context_layer); | 88 base::scoped_nsobject<CALayerHost> ca_context_layer); |
| 114 void DestroyLocalLayer(); | 89 void DestroyLocalLayer(); |
| 115 void EnsureLocalLayer(); | 90 void EnsureLocalLayer(); |
| 116 | 91 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 128 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable | 103 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable |
| 129 // behavior. | 104 // behavior. |
| 130 base::scoped_nsobject<CALayer> flipped_layer_; | 105 base::scoped_nsobject<CALayer> flipped_layer_; |
| 131 | 106 |
| 132 // The accelerated CoreAnimation layer hosted by the GPU process. | 107 // The accelerated CoreAnimation layer hosted by the GPU process. |
| 133 base::scoped_nsobject<CALayerHost> ca_context_layer_; | 108 base::scoped_nsobject<CALayerHost> ca_context_layer_; |
| 134 | 109 |
| 135 // The locally drawn layer, which has its contents set to an IOSurface. | 110 // The locally drawn layer, which has its contents set to an IOSurface. |
| 136 base::scoped_nsobject<CALayer> local_layer_; | 111 base::scoped_nsobject<CALayer> local_layer_; |
| 137 | 112 |
| 138 // If an accelerated frame has come in which has not yet been drawn and acked | |
| 139 // then this is the latency info and the callback to make when the frame is | |
| 140 // drawn. If there is no such frame then the callback is null. | |
| 141 std::vector<ui::LatencyInfo> accelerated_latency_info_; | |
| 142 base::Closure accelerated_frame_drawn_callback_; | |
| 143 | |
| 144 // The size in DIP of the last swap received from |compositor_|. | 113 // The size in DIP of the last swap received from |compositor_|. |
| 145 gfx::Size last_swap_size_dip_; | 114 gfx::Size last_swap_size_dip_; |
| 146 | 115 |
| 147 // Whether surfaces created by the widget should use the glFinish() workaround | 116 // Whether surfaces created by the widget should use the glFinish() workaround |
| 148 // after compositing. | 117 // after compositing. |
| 149 bool needs_gl_finish_workaround_; | 118 bool needs_gl_finish_workaround_; |
| 150 | 119 |
| 151 DISALLOW_COPY_AND_ASSIGN(AcceleratedWidgetMac); | 120 DISALLOW_COPY_AND_ASSIGN(AcceleratedWidgetMac); |
| 152 }; | 121 }; |
| 153 | 122 |
| 154 #endif // __OBJC__ | 123 #endif // __OBJC__ |
| 155 | 124 |
| 156 ACCELERATED_WIDGET_MAC_EXPORT | 125 ACCELERATED_WIDGET_MAC_EXPORT |
| 157 void AcceleratedWidgetMacGotAcceleratedFrame( | 126 void AcceleratedWidgetMacGotFrame( |
| 158 gfx::AcceleratedWidget widget, | 127 gfx::AcceleratedWidget widget, |
| 159 CAContextID ca_context_id, | 128 CAContextID ca_context_id, |
| 160 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | 129 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 161 const std::vector<ui::LatencyInfo>& latency_info, | |
| 162 const gfx::Size& pixel_size, | 130 const gfx::Size& pixel_size, |
| 163 float scale_factor, | 131 float scale_factor, |
| 164 const gfx::Rect& pixel_damage_rect, | |
| 165 const base::Closure& drawn_callback, | |
| 166 bool* disable_throttling, | |
| 167 int* renderer_id, | |
| 168 base::TimeTicks* vsync_timebase, | 132 base::TimeTicks* vsync_timebase, |
| 169 base::TimeDelta* vsync_interval); | 133 base::TimeDelta* vsync_interval); |
| 170 | 134 |
| 171 ACCELERATED_WIDGET_MAC_EXPORT | |
| 172 void AcceleratedWidgetMacGotIOSurfaceFrame( | |
| 173 gfx::AcceleratedWidget widget, | |
| 174 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 175 const gfx::Size& pixel_size, | |
| 176 float scale_factor, | |
| 177 bool flip_y); | |
| 178 | |
| 179 } // namespace ui | 135 } // namespace ui |
| 180 | 136 |
| 181 #endif // UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ | 137 #endif // UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ |
| OLD | NEW |