| 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 "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" | 12 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" |
| 12 #include "ui/events/latency_info.h" | 13 #include "ui/events/latency_info.h" |
| 13 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 14 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 15 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
| 16 | 17 |
| 17 #if defined(__OBJC__) | 18 #if defined(__OBJC__) |
| 18 #import <Cocoa/Cocoa.h> | 19 #import <Cocoa/Cocoa.h> |
| 19 #import "base/mac/scoped_nsobject.h" | 20 #import "base/mac/scoped_nsobject.h" |
| 20 #import "ui/accelerated_widget_mac/io_surface_layer.h" | |
| 21 #import "ui/accelerated_widget_mac/software_layer.h" | |
| 22 #include "ui/base/cocoa/remote_layer_api.h" | 21 #include "ui/base/cocoa/remote_layer_api.h" |
| 23 #endif // __OBJC__ | 22 #endif // __OBJC__ |
| 24 | 23 |
| 25 class SkCanvas; | 24 class SkCanvas; |
| 26 | 25 |
| 27 namespace cc { | 26 namespace cc { |
| 28 class SoftwareFrameData; | 27 class SoftwareFrameData; |
| 29 } | 28 } |
| 30 | 29 |
| 31 namespace ui { | 30 namespace ui { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 45 const std::vector<ui::LatencyInfo>& latency_info) = 0; | 44 const std::vector<ui::LatencyInfo>& latency_info) = 0; |
| 46 virtual void AcceleratedWidgetHitError() = 0; | 45 virtual void AcceleratedWidgetHitError() = 0; |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 #if defined(__OBJC__) | 48 #if defined(__OBJC__) |
| 50 | 49 |
| 51 // AcceleratedWidgetMac owns a tree of CALayers. The widget may be passed | 50 // 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 | 51 // to a ui::Compositor, which will cause, through its output surface, calls to |
| 53 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed | 52 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed |
| 54 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper. | 53 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper. |
| 55 class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac | 54 class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac { |
| 56 : public IOSurfaceLayerClient { | |
| 57 public: | 55 public: |
| 58 explicit AcceleratedWidgetMac(bool needs_gl_finish_workaround); | 56 explicit AcceleratedWidgetMac(bool needs_gl_finish_workaround); |
| 59 virtual ~AcceleratedWidgetMac(); | 57 virtual ~AcceleratedWidgetMac(); |
| 60 | 58 |
| 61 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; } | 59 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; } |
| 62 | 60 |
| 63 void SetNSView(AcceleratedWidgetMacNSView* view); | 61 void SetNSView(AcceleratedWidgetMacNSView* view); |
| 64 void ResetNSView(); | 62 void ResetNSView(); |
| 65 | 63 |
| 66 // Return true if the last frame swapped has a size in DIP of |dip_size|. | 64 // Return true if the last frame swapped has a size in DIP of |dip_size|. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 82 void EndPumpingFrames(); | 80 void EndPumpingFrames(); |
| 83 | 81 |
| 84 void GotAcceleratedFrame( | 82 void GotAcceleratedFrame( |
| 85 uint64 surface_handle, | 83 uint64 surface_handle, |
| 86 const std::vector<ui::LatencyInfo>& latency_info, | 84 const std::vector<ui::LatencyInfo>& latency_info, |
| 87 const gfx::Size& pixel_size, | 85 const gfx::Size& pixel_size, |
| 88 float scale_factor, | 86 float scale_factor, |
| 89 const gfx::Rect& pixel_damage_rect, | 87 const gfx::Rect& pixel_damage_rect, |
| 90 const base::Closure& drawn_callback); | 88 const base::Closure& drawn_callback); |
| 91 | 89 |
| 92 void GotSoftwareFrame(float scale_factor, SkCanvas* canvas); | 90 void GotIOSurfaceFrame(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 91 const gfx::Size& pixel_size, |
| 92 float scale_factor, |
| 93 bool flip_y); |
| 93 | 94 |
| 94 private: | 95 private: |
| 95 // IOSurfaceLayerClient implementation: | |
| 96 bool IOSurfaceLayerShouldAckImmediately() const override; | |
| 97 void IOSurfaceLayerDidDrawFrame() override; | |
| 98 void IOSurfaceLayerHitError() override; | |
| 99 | |
| 100 void GotAcceleratedCAContextFrame(CAContextID ca_context_id, | 96 void GotAcceleratedCAContextFrame(CAContextID ca_context_id, |
| 101 const gfx::Size& pixel_size, | 97 const gfx::Size& pixel_size, |
| 102 float scale_factor); | 98 float scale_factor); |
| 103 | 99 |
| 104 void GotAcceleratedIOSurfaceFrame(IOSurfaceID io_surface_id, | 100 void GotAcceleratedIOSurfaceFrame(IOSurfaceID io_surface_id, |
| 105 const gfx::Size& pixel_size, | 101 const gfx::Size& pixel_size, |
| 106 float scale_factor); | 102 float scale_factor); |
| 107 | 103 |
| 108 void AcknowledgeAcceleratedFrame(); | 104 void AcknowledgeAcceleratedFrame(); |
| 109 | 105 |
| 110 // Remove a layer from the heirarchy and destroy it. Because the accelerated | 106 // Remove a layer from the heirarchy and destroy it. Because the accelerated |
| 111 // layer types may be replaced by a layer of the same type, the layer to | 107 // layer types may be replaced by a layer of the same type, the layer to |
| 112 // destroy is parameterized, and, if it is the current layer, the current | 108 // destroy is parameterized, and, if it is the current layer, the current |
| 113 // layer is reset. | 109 // layer is reset. |
| 114 void DestroyCAContextLayer( | 110 void DestroyCAContextLayer( |
| 115 base::scoped_nsobject<CALayerHost> ca_context_layer); | 111 base::scoped_nsobject<CALayerHost> ca_context_layer); |
| 116 void DestroyIOSurfaceLayer( | 112 void DestroyLocalLayer(); |
| 117 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer); | 113 void EnsureLocalLayer(); |
| 118 void DestroySoftwareLayer(); | |
| 119 | 114 |
| 120 // The AcceleratedWidgetMacNSView that is using this as its internals. | 115 // The AcceleratedWidgetMacNSView that is using this as its internals. |
| 121 AcceleratedWidgetMacNSView* view_; | 116 AcceleratedWidgetMacNSView* view_; |
| 122 | 117 |
| 123 // A phony NSView handle used to identify this. | 118 // A phony NSView handle used to identify this. |
| 124 gfx::AcceleratedWidget native_widget_; | 119 gfx::AcceleratedWidget native_widget_; |
| 125 | 120 |
| 126 // A flipped layer, which acts as the parent of the compositing and software | 121 // A flipped layer, which acts as the parent of the compositing and software |
| 127 // layers. This layer is flipped so that the we don't need to recompute the | 122 // layers. This layer is flipped so that the we don't need to recompute the |
| 128 // origin for sub-layers when their position changes (this is impossible when | 123 // origin for sub-layers when their position changes (this is impossible when |
| 129 // using remote layers, as their size change cannot be synchronized with the | 124 // using remote layers, as their size change cannot be synchronized with the |
| 130 // window). This indirection is needed because flipping hosted layers (like | 125 // window). This indirection is needed because flipping hosted layers (like |
| 131 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable | 126 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable |
| 132 // behavior. | 127 // behavior. |
| 133 base::scoped_nsobject<CALayer> flipped_layer_; | 128 base::scoped_nsobject<CALayer> flipped_layer_; |
| 134 | 129 |
| 135 // The accelerated CoreAnimation layer hosted by the GPU process. | 130 // The accelerated CoreAnimation layer hosted by the GPU process. |
| 136 base::scoped_nsobject<CALayerHost> ca_context_layer_; | 131 base::scoped_nsobject<CALayerHost> ca_context_layer_; |
| 137 | 132 |
| 138 // The locally drawn accelerated CoreAnimation layer. | 133 // The locally drawn layer, which has its contents set to an IOSurface. |
| 139 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer_; | 134 base::scoped_nsobject<CALayer> local_layer_; |
| 140 | |
| 141 // The locally drawn software layer. | |
| 142 base::scoped_nsobject<SoftwareLayer> software_layer_; | |
| 143 | 135 |
| 144 // If an accelerated frame has come in which has not yet been drawn and acked | 136 // If an accelerated frame has come in which has not yet been drawn and acked |
| 145 // then this is the latency info and the callback to make when the frame is | 137 // then this is the latency info and the callback to make when the frame is |
| 146 // drawn. If there is no such frame then the callback is null. | 138 // drawn. If there is no such frame then the callback is null. |
| 147 std::vector<ui::LatencyInfo> accelerated_latency_info_; | 139 std::vector<ui::LatencyInfo> accelerated_latency_info_; |
| 148 base::Closure accelerated_frame_drawn_callback_; | 140 base::Closure accelerated_frame_drawn_callback_; |
| 149 | 141 |
| 150 // The size in DIP of the last swap received from |compositor_|. | 142 // The size in DIP of the last swap received from |compositor_|. |
| 151 gfx::Size last_swap_size_dip_; | 143 gfx::Size last_swap_size_dip_; |
| 152 | 144 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 164 gfx::AcceleratedWidget widget, uint64 surface_handle, | 156 gfx::AcceleratedWidget widget, uint64 surface_handle, |
| 165 const std::vector<ui::LatencyInfo>& latency_info, | 157 const std::vector<ui::LatencyInfo>& latency_info, |
| 166 const gfx::Size& pixel_size, | 158 const gfx::Size& pixel_size, |
| 167 float scale_factor, | 159 float scale_factor, |
| 168 const gfx::Rect& pixel_damage_rect, | 160 const gfx::Rect& pixel_damage_rect, |
| 169 const base::Closure& drawn_callback, | 161 const base::Closure& drawn_callback, |
| 170 bool* disable_throttling, int* renderer_id, | 162 bool* disable_throttling, int* renderer_id, |
| 171 base::TimeTicks* vsync_timebase, base::TimeDelta* vsync_interval); | 163 base::TimeTicks* vsync_timebase, base::TimeDelta* vsync_interval); |
| 172 | 164 |
| 173 ACCELERATED_WIDGET_MAC_EXPORT | 165 ACCELERATED_WIDGET_MAC_EXPORT |
| 174 void AcceleratedWidgetMacGotSoftwareFrame( | 166 void AcceleratedWidgetMacGotIOSurfaceFrame( |
| 175 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas); | 167 gfx::AcceleratedWidget widget, |
| 168 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, |
| 169 const gfx::Size& pixel_size, |
| 170 float scale_factor, |
| 171 bool flip_y); |
| 176 | 172 |
| 177 } // namespace ui | 173 } // namespace ui |
| 178 | 174 |
| 179 #endif // UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ | 175 #endif // UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ |
| OLD | NEW |