Make castv2 performance test work.
[chromium-blink-merge.git] / ui / accelerated_widget_mac / accelerated_widget_mac.h
blobbf7843369e6ca3b8d4cd6095134a4f9b4413592e
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/IOSurfaceAPI.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/size.h"
14 #include "ui/gfx/native_widget_types.h"
16 #if defined(__OBJC__)
17 #import <Cocoa/Cocoa.h>
18 #import "base/mac/scoped_nsobject.h"
19 #import "ui/accelerated_widget_mac/io_surface_layer.h"
20 #import "ui/accelerated_widget_mac/software_layer.h"
21 #include "ui/base/cocoa/remote_layer_api.h"
22 #endif // __OBJC__
24 class SkCanvas;
26 namespace cc {
27 class SoftwareFrameData;
30 namespace ui {
32 class AcceleratedWidgetMac;
34 // A class through which an AcceleratedWidget may be bound to draw the contents
35 // of an NSView. An AcceleratedWidget may be bound to multiple different views
36 // throughout its lifetime (one at a time, though).
37 class AcceleratedWidgetMacNSView {
38 public:
39 virtual NSView* AcceleratedWidgetGetNSView() const = 0;
40 virtual bool AcceleratedWidgetShouldIgnoreBackpressure() const = 0;
41 virtual void AcceleratedWidgetSwapCompleted(
42 const std::vector<ui::LatencyInfo>& latency_info) = 0;
43 virtual void AcceleratedWidgetHitError() = 0;
46 #if defined(__OBJC__)
48 // AcceleratedWidgetMac owns a tree of CALayers. The widget may be passed
49 // to a ui::Compositor, which will cause, through its output surface, calls to
50 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed
51 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper.
52 class ACCELERATED_WIDGET_MAC_EXPORT AcceleratedWidgetMac
53 : public IOSurfaceLayerClient {
54 public:
55 explicit AcceleratedWidgetMac(bool needs_gl_finish_workaround);
56 virtual ~AcceleratedWidgetMac();
58 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; }
60 void SetNSView(AcceleratedWidgetMacNSView* view);
61 void ResetNSView();
63 // Return true if the last frame swapped has a size in DIP of |dip_size|.
64 bool HasFrameOfSize(const gfx::Size& dip_size) const;
66 // Return the CGL renderer ID for the surface, if one is available.
67 int GetRendererID() const;
69 // Return true if the renderer should not be throttled by GPU back-pressure.
70 bool IsRendererThrottlingDisabled() const;
72 // Mark a bracket in which new frames are being pumped in a restricted nested
73 // run loop.
74 void BeginPumpingFrames();
75 void EndPumpingFrames();
77 void GotAcceleratedFrame(
78 uint64 surface_handle,
79 const std::vector<ui::LatencyInfo>& latency_info,
80 gfx::Size pixel_size,
81 float scale_factor,
82 const base::Closure& drawn_callback);
84 void GotSoftwareFrame(float scale_factor, SkCanvas* canvas);
86 private:
87 // IOSurfaceLayerClient implementation:
88 bool IOSurfaceLayerShouldAckImmediately() const override;
89 void IOSurfaceLayerDidDrawFrame() override;
90 void IOSurfaceLayerHitError() override;
92 void GotAcceleratedCAContextFrame(
93 CAContextID ca_context_id, gfx::Size pixel_size, float scale_factor);
95 void GotAcceleratedIOSurfaceFrame(
96 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor);
98 void AcknowledgeAcceleratedFrame();
100 // Remove a layer from the heirarchy and destroy it. Because the accelerated
101 // layer types may be replaced by a layer of the same type, the layer to
102 // destroy is parameterized, and, if it is the current layer, the current
103 // layer is reset.
104 void DestroyCAContextLayer(
105 base::scoped_nsobject<CALayerHost> ca_context_layer);
106 void DestroyIOSurfaceLayer(
107 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer);
108 void DestroySoftwareLayer();
110 // The AcceleratedWidgetMacNSView that is using this as its internals.
111 AcceleratedWidgetMacNSView* view_;
113 // A phony NSView handle used to identify this.
114 gfx::AcceleratedWidget native_widget_;
116 // A flipped layer, which acts as the parent of the compositing and software
117 // layers. This layer is flipped so that the we don't need to recompute the
118 // origin for sub-layers when their position changes (this is impossible when
119 // using remote layers, as their size change cannot be synchronized with the
120 // window). This indirection is needed because flipping hosted layers (like
121 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable
122 // behavior.
123 base::scoped_nsobject<CALayer> flipped_layer_;
125 // The accelerated CoreAnimation layer hosted by the GPU process.
126 base::scoped_nsobject<CALayerHost> ca_context_layer_;
128 // The locally drawn accelerated CoreAnimation layer.
129 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer_;
131 // The locally drawn software layer.
132 base::scoped_nsobject<SoftwareLayer> software_layer_;
134 // If an accelerated frame has come in which has not yet been drawn and acked
135 // then this is the latency info and the callback to make when the frame is
136 // drawn. If there is no such frame then the callback is null.
137 std::vector<ui::LatencyInfo> accelerated_latency_info_;
138 base::Closure accelerated_frame_drawn_callback_;
140 // The size in DIP of the last swap received from |compositor_|.
141 gfx::Size last_swap_size_dip_;
143 // Whether surfaces created by the widget should use the glFinish() workaround
144 // after compositing.
145 bool needs_gl_finish_workaround_;
147 DISALLOW_COPY_AND_ASSIGN(AcceleratedWidgetMac);
150 #endif // __OBJC__
152 ACCELERATED_WIDGET_MAC_EXPORT
153 void AcceleratedWidgetMacGotAcceleratedFrame(
154 gfx::AcceleratedWidget widget, uint64 surface_handle,
155 const std::vector<ui::LatencyInfo>& latency_info,
156 gfx::Size pixel_size, float scale_factor,
157 const base::Closure& drawn_callback,
158 bool* disable_throttling, int* renderer_id);
160 ACCELERATED_WIDGET_MAC_EXPORT
161 void AcceleratedWidgetMacGotSoftwareFrame(
162 gfx::AcceleratedWidget widget, float scale_factor, SkCanvas* canvas);
164 } // namespace ui
166 #endif // UI_ACCELERATED_WIDGET_MAC_ACCELERATED_WIDGET_MAC_H_