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 CONTENT_BROWSER_COMPOSITOR_ACCELERATED_WIDGET_HELPER_MAC_H_ | 5 #ifndef UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ |
6 #define CONTENT_BROWSER_COMPOSITOR_ACCELERATED_WIDGET_HELPER_MAC_H_ | 6 #define UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ |
7 | 7 |
8 #include <IOSurface/IOSurfaceAPI.h> | 8 #include <IOSurface/IOSurfaceAPI.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "skia/ext/platform_canvas.h" | 11 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" |
12 #include "ui/events/latency_info.h" | 12 #include "ui/events/latency_info.h" |
13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
14 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
15 | 15 |
16 #if defined(__OBJC__) | 16 #if defined(__OBJC__) |
17 #include <Cocoa/Cocoa.h> | 17 #import <Cocoa/Cocoa.h> |
18 #include "base/mac/scoped_nsobject.h" | 18 #import "base/mac/scoped_nsobject.h" |
19 #include "content/browser/compositor/io_surface_layer_mac.h" | 19 #import "ui/accelerated_widget_mac/io_surface_layer.h" |
20 #include "content/browser/compositor/software_layer_mac.h" | 20 #import "ui/accelerated_widget_mac/software_layer.h" |
21 #include "ui/base/cocoa/remote_layer_api.h" | 21 #include "ui/base/cocoa/remote_layer_api.h" |
22 #endif // __OBJC__ | 22 #endif // __OBJC__ |
23 | 23 |
| 24 class SkCanvas; |
| 25 |
24 namespace cc { | 26 namespace cc { |
25 class SoftwareFrameData; | 27 class SoftwareFrameData; |
26 } | 28 } |
27 | 29 |
28 namespace content { | 30 namespace ui { |
29 | 31 |
30 class AcceleratedWidgetMac; | 32 class AcceleratedWidgetMac; |
31 | 33 |
32 // A class through which an AcceleratedWidget may be bound to draw the contents | 34 // A class through which an AcceleratedWidget may be bound to draw the contents |
33 // of an NSView. An AcceleratedWidget may be bound to multiple different views | 35 // of an NSView. An AcceleratedWidget may be bound to multiple different views |
34 // throughout its lifetime (one at a time, though). | 36 // throughout its lifetime (one at a time, though). |
35 class AcceleratedWidgetMacNSView { | 37 class AcceleratedWidgetMacNSView { |
36 public: | 38 public: |
37 virtual NSView* AcceleratedWidgetGetNSView() const = 0; | 39 virtual NSView* AcceleratedWidgetGetNSView() const = 0; |
38 virtual bool AcceleratedWidgetShouldIgnoreBackpressure() const = 0; | 40 virtual bool AcceleratedWidgetShouldIgnoreBackpressure() const = 0; |
39 virtual void AcceleratedWidgetSwapCompleted( | 41 virtual void AcceleratedWidgetSwapCompleted( |
40 const std::vector<ui::LatencyInfo>& latency_info) = 0; | 42 const std::vector<ui::LatencyInfo>& latency_info) = 0; |
41 virtual void AcceleratedWidgetHitError() = 0; | 43 virtual void AcceleratedWidgetHitError() = 0; |
42 }; | 44 }; |
43 | 45 |
44 #if defined(__OBJC__) | 46 #if defined(__OBJC__) |
45 | 47 |
46 // AcceleratedWidgetMac owns a tree of CALayers. The widget may be passed | 48 // AcceleratedWidgetMac owns a tree of CALayers. The widget may be passed |
47 // 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 |
48 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed | 50 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed |
49 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper. | 51 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper. |
50 class AcceleratedWidgetMac : public IOSurfaceLayerClient { | 52 class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac |
| 53 : public IOSurfaceLayerClient { |
51 public: | 54 public: |
52 AcceleratedWidgetMac(); | 55 explicit AcceleratedWidgetMac(bool needs_gl_finish_workaround); |
53 virtual ~AcceleratedWidgetMac(); | 56 virtual ~AcceleratedWidgetMac(); |
54 | 57 |
55 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; } | 58 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; } |
56 | 59 |
57 void SetNSView(AcceleratedWidgetMacNSView* view); | 60 void SetNSView(AcceleratedWidgetMacNSView* view); |
58 void ResetNSView(); | 61 void ResetNSView(); |
59 | 62 |
60 // Return true if the last frame swapped has a size in DIP of |dip_size|. | 63 // Return true if the last frame swapped has a size in DIP of |dip_size|. |
61 bool HasFrameOfSize(const gfx::Size& dip_size) const; | 64 bool HasFrameOfSize(const gfx::Size& dip_size) const; |
62 | 65 |
63 // Return the CGL renderer ID for the surface, if one is available. | 66 // Return the CGL renderer ID for the surface, if one is available. |
64 int GetRendererID() const; | 67 int GetRendererID() const; |
65 | 68 |
66 // Return true if the renderer should not be throttled by GPU back-pressure. | 69 // Return true if the renderer should not be throttled by GPU back-pressure. |
67 bool IsRendererThrottlingDisabled() const; | 70 bool IsRendererThrottlingDisabled() const; |
68 | 71 |
69 // Mark a bracket in which new frames are being pumped in a restricted nested | 72 // Mark a bracket in which new frames are being pumped in a restricted nested |
70 // run loop. | 73 // run loop. |
71 void BeginPumpingFrames(); | 74 void BeginPumpingFrames(); |
72 void EndPumpingFrames(); | 75 void EndPumpingFrames(); |
73 | 76 |
74 void GotAcceleratedFrame( | 77 void GotAcceleratedFrame( |
75 uint64 surface_handle, | 78 uint64 surface_handle, |
76 const std::vector<ui::LatencyInfo>& latency_info, | 79 const std::vector<ui::LatencyInfo>& latency_info, |
77 gfx::Size pixel_size, | 80 gfx::Size pixel_size, |
78 float scale_factor, | 81 float scale_factor, |
79 const base::Closure& drawn_callback); | 82 const base::Closure& drawn_callback); |
80 | 83 |
81 void GotSoftwareFrame( | 84 void GotSoftwareFrame(float scale_factor, SkCanvas* canvas); |
82 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas); | |
83 | 85 |
84 private: | 86 private: |
85 // IOSurfaceLayerClient implementation: | 87 // IOSurfaceLayerClient implementation: |
86 bool IOSurfaceLayerShouldAckImmediately() const override; | 88 bool IOSurfaceLayerShouldAckImmediately() const override; |
87 void IOSurfaceLayerDidDrawFrame() override; | 89 void IOSurfaceLayerDidDrawFrame() override; |
88 void IOSurfaceLayerHitError() override; | 90 void IOSurfaceLayerHitError() override; |
89 | 91 |
90 void GotAcceleratedCAContextFrame( | 92 void GotAcceleratedCAContextFrame( |
91 CAContextID ca_context_id, gfx::Size pixel_size, float scale_factor); | 93 CAContextID ca_context_id, gfx::Size pixel_size, float scale_factor); |
92 | 94 |
93 void GotAcceleratedIOSurfaceFrame( | 95 void GotAcceleratedIOSurfaceFrame( |
94 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor); | 96 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 133 |
132 // If an accelerated frame has come in which has not yet been drawn and acked | 134 // If an accelerated frame has come in which has not yet been drawn and acked |
133 // then this is the latency info and the callback to make when the frame is | 135 // then this is the latency info and the callback to make when the frame is |
134 // drawn. If there is no such frame then the callback is null. | 136 // drawn. If there is no such frame then the callback is null. |
135 std::vector<ui::LatencyInfo> accelerated_latency_info_; | 137 std::vector<ui::LatencyInfo> accelerated_latency_info_; |
136 base::Closure accelerated_frame_drawn_callback_; | 138 base::Closure accelerated_frame_drawn_callback_; |
137 | 139 |
138 // The size in DIP of the last swap received from |compositor_|. | 140 // The size in DIP of the last swap received from |compositor_|. |
139 gfx::Size last_swap_size_dip_; | 141 gfx::Size last_swap_size_dip_; |
140 | 142 |
| 143 // Whether surfaces created by the widget should use the glFinish() workaround |
| 144 // after compositing. |
| 145 bool needs_gl_finish_workaround_; |
| 146 |
141 DISALLOW_COPY_AND_ASSIGN(AcceleratedWidgetMac); | 147 DISALLOW_COPY_AND_ASSIGN(AcceleratedWidgetMac); |
142 }; | 148 }; |
143 | 149 |
144 #endif // __OBJC__ | 150 #endif // __OBJC__ |
145 | 151 |
| 152 ACCELERATED_WIDGET_MAC_EXPORT |
146 void AcceleratedWidgetMacGotAcceleratedFrame( | 153 void AcceleratedWidgetMacGotAcceleratedFrame( |
147 gfx::AcceleratedWidget widget, uint64 surface_handle, | 154 gfx::AcceleratedWidget widget, uint64 surface_handle, |
148 const std::vector<ui::LatencyInfo>& latency_info, | 155 const std::vector<ui::LatencyInfo>& latency_info, |
149 gfx::Size pixel_size, float scale_factor, | 156 gfx::Size pixel_size, float scale_factor, |
150 const base::Closure& drawn_callback, | 157 const base::Closure& drawn_callback, |
151 bool* disable_throttling, int* renderer_id); | 158 bool* disable_throttling, int* renderer_id); |
152 | 159 |
| 160 ACCELERATED_WIDGET_MAC_EXPORT |
153 void AcceleratedWidgetMacGotSoftwareFrame( | 161 void AcceleratedWidgetMacGotSoftwareFrame( |
154 gfx::AcceleratedWidget widget, | 162 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas); |
155 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas); | |
156 | 163 |
157 } // namespace content | 164 } // namespace ui |
158 | 165 |
159 #endif // CONTENT_BROWSER_COMPOSITOR_ACCELERATED_WIDGET_HELPER_MAC_H_ | 166 #endif // UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_ |
OLD | NEW |