Remove APIPermission::kFileSystemWriteDirectory
[chromium-blink-merge.git] / ui / accelerated_widget_mac / accelerated_widget_mac.h
blob39142965f0f01bc3922f449b61a2d18b6c8f5068
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
3 // found in the LICENSE file.
5 #ifndef UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_
6 #define UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_
8 #include <IOSurface/IOSurface.h>
9 #include <vector>
11 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h"
12 #include "ui/events/latency_info.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gfx/native_widget_types.h"
17 #if defined(__OBJC__)
18 #import <Cocoa/Cocoa.h>
19 #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"
23 #endif // __OBJC__
25 class SkCanvas;
27 namespace cc {
28 class SoftwareFrameData;
31 namespace ui {
33 class AcceleratedWidgetMac;
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
37 // throughout its lifetime (one at a time, though).
38 class AcceleratedWidgetMacNSView {
39 public:
40 virtual NSView* AcceleratedWidgetGetNSView() const = 0;
41 virtual bool AcceleratedWidgetShouldIgnoreBackpressure() const = 0;
42 virtual void AcceleratedWidgetGetVSyncParameters(
43 base::TimeTicks* timebase, base::TimeDelta* interval) const = 0;
44 virtual void AcceleratedWidgetSwapCompleted(
45 const std::vector<ui::LatencyInfo>& latency_info) = 0;
46 virtual void AcceleratedWidgetHitError() = 0;
49 #if defined(__OBJC__)
51 // 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
53 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed
54 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper.
55 class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac
56 : public IOSurfaceLayerClient {
57 public:
58 explicit AcceleratedWidgetMac(bool needs_gl_finish_workaround);
59 virtual ~AcceleratedWidgetMac();
61 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; }
63 void SetNSView(AcceleratedWidgetMacNSView* view);
64 void ResetNSView();
66 // Return true if the last frame swapped has a size in DIP of |dip_size|.
67 bool HasFrameOfSize(const gfx::Size& dip_size) const;
69 // Return the CGL renderer ID for the surface, if one is available.
70 int GetRendererID() const;
72 // Populate the vsync parameters for the surface's display.
73 void GetVSyncParameters(
74 base::TimeTicks* timebase, base::TimeDelta* interval) const;
76 // Return true if the renderer should not be throttled by GPU back-pressure.
77 bool IsRendererThrottlingDisabled() const;
79 // Mark a bracket in which new frames are being pumped in a restricted nested
80 // run loop.
81 void BeginPumpingFrames();
82 void EndPumpingFrames();
84 void GotAcceleratedFrame(
85 uint64 surface_handle,
86 const std::vector<ui::LatencyInfo>& latency_info,
87 const gfx::Size& pixel_size,
88 float scale_factor,
89 const gfx::Rect& pixel_damage_rect,
90 const base::Closure& drawn_callback);
92 void GotSoftwareFrame(float scale_factor, SkCanvas* canvas);
94 private:
95 // IOSurfaceLayerClient implementation:
96 bool IOSurfaceLayerShouldAckImmediately() const override;
97 void IOSurfaceLayerDidDrawFrame() override;
98 void IOSurfaceLayerHitError() override;
100 void GotAcceleratedCAContextFrame(CAContextID ca_context_id,
101 const gfx::Size& pixel_size,
102 float scale_factor);
104 void GotAcceleratedIOSurfaceFrame(IOSurfaceID io_surface_id,
105 const gfx::Size& pixel_size,
106 float scale_factor);
108 void AcknowledgeAcceleratedFrame();
110 // 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
112 // destroy is parameterized, and, if it is the current layer, the current
113 // layer is reset.
114 void DestroyCAContextLayer(
115 base::scoped_nsobject<CALayerHost> ca_context_layer);
116 void DestroyIOSurfaceLayer(
117 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer);
118 void DestroySoftwareLayer();
120 // The AcceleratedWidgetMacNSView that is using this as its internals.
121 AcceleratedWidgetMacNSView* view_;
123 // A phony NSView handle used to identify this.
124 gfx::AcceleratedWidget native_widget_;
126 // 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
128 // 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
130 // window). This indirection is needed because flipping hosted layers (like
131 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable
132 // behavior.
133 base::scoped_nsobject<CALayer> flipped_layer_;
135 // The accelerated CoreAnimation layer hosted by the GPU process.
136 base::scoped_nsobject<CALayerHost> ca_context_layer_;
138 // The locally drawn accelerated CoreAnimation layer.
139 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer_;
141 // The locally drawn software layer.
142 base::scoped_nsobject<SoftwareLayer> software_layer_;
144 // 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
146 // drawn. If there is no such frame then the callback is null.
147 std::vector<ui::LatencyInfo> accelerated_latency_info_;
148 base::Closure accelerated_frame_drawn_callback_;
150 // The size in DIP of the last swap received from |compositor_|.
151 gfx::Size last_swap_size_dip_;
153 // Whether surfaces created by the widget should use the glFinish() workaround
154 // after compositing.
155 bool needs_gl_finish_workaround_;
157 DISALLOW_COPY_AND_ASSIGN(AcceleratedWidgetMac);
160 #endif // __OBJC__
162 ACCELERATED_WIDGET_MAC_EXPORT
163 void AcceleratedWidgetMacGotAcceleratedFrame(
164 gfx::AcceleratedWidget widget, uint64 surface_handle,
165 const std::vector<ui::LatencyInfo>& latency_info,
166 const gfx::Size& pixel_size,
167 float scale_factor,
168 const gfx::Rect& pixel_damage_rect,
169 const base::Closure& drawn_callback,
170 bool* disable_throttling, int* renderer_id,
171 base::TimeTicks* vsync_timebase, base::TimeDelta* vsync_interval);
173 ACCELERATED_WIDGET_MAC_EXPORT
174 void AcceleratedWidgetMacGotSoftwareFrame(
175 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas);
177 } // namespace ui
179 #endif // UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_