Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: content/browser/compositor/browser_compositor_ca_layer_tree_mac.h

Issue 745453002: Create an AcceleratedWidgetMac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chnage names from client to NSView Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_BROWSER_COMPOSITOR_CA_LAYER_TREE_MAC_H_ 5 #ifndef CONTENT_BROWSER_COMPOSITOR_ACCELERATED_WIDGET_HELPER_MAC_H_
6 #define CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_CA_LAYER_TREE_MAC_H_ 6 #define CONTENT_BROWSER_COMPOSITOR_ACCELERATED_WIDGET_HELPER_MAC_H_
7 7
8 #include <IOSurface/IOSurfaceAPI.h> 8 #include <IOSurface/IOSurfaceAPI.h>
9 #include <vector>
9 10
10 #include "content/browser/compositor/browser_compositor_view_mac.h" 11 #include "skia/ext/platform_canvas.h"
12 #include "ui/events/latency_info.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/gfx/native_widget_types.h"
11 15
12 #if defined(__OBJC__) 16 #if defined(__OBJC__)
13 #include <Cocoa/Cocoa.h> 17 #include <Cocoa/Cocoa.h>
14 #include "base/mac/scoped_nsobject.h" 18 #include "base/mac/scoped_nsobject.h"
15 #include "content/browser/compositor/io_surface_layer_mac.h" 19 #include "content/browser/compositor/io_surface_layer_mac.h"
16 #include "content/browser/compositor/software_layer_mac.h" 20 #include "content/browser/compositor/software_layer_mac.h"
17 #include "ui/base/cocoa/remote_layer_api.h" 21 #include "ui/base/cocoa/remote_layer_api.h"
18 #endif // __OBJC__ 22 #endif // __OBJC__
19 23
24 namespace cc {
25 class SoftwareFrameData;
26 }
27
20 namespace content { 28 namespace content {
21 29
30 class AcceleratedWidgetMac;
31
32 // 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
34 // throughout its lifetime (one at a time, though).
35 class AcceleratedWidgetMacNSView {
36 public:
37 virtual NSView* AcceleratedWidgetGetNSView() const = 0;
38 virtual bool AcceleratedWidgetShouldIgnoreBackpressure() const = 0;
39 virtual void AcceleratedWidgetSwapCompleted(
40 const std::vector<ui::LatencyInfo>& latency_info) = 0;
41 virtual void AcceleratedWidgetHitError() = 0;
42 };
43
22 #if defined(__OBJC__) 44 #if defined(__OBJC__)
23 45
24 // BrowserCompositorCALayerTreeMac owns tree of CALayer and a ui::Compositor 46 // AcceleratedWidgetMac owns a tree of CALayers. The widget may be passed
25 // that is used to draw the layers. The CALayer tree can be attached to the 47 // to a ui::Compositor, which will cause, through its output surface, calls to
26 // NSView of a BrowserCompositorViewMac 48 // GotAcceleratedFrame and GotSoftwareFrame. The CALayers may be installed
27 class BrowserCompositorCALayerTreeMac 49 // in an NSView by setting the AcceleratedWidgetMacNSView for the helper.
50 class AcceleratedWidgetMac
28 : public IOSurfaceLayerClient { 51 : public IOSurfaceLayerClient {
29 public: 52 public:
30 BrowserCompositorCALayerTreeMac(); 53 AcceleratedWidgetMac();
31 virtual ~BrowserCompositorCALayerTreeMac(); 54 virtual ~AcceleratedWidgetMac();
32 static BrowserCompositorCALayerTreeMac* FromAcceleratedWidget(
33 gfx::AcceleratedWidget widget);
34 55
35 void SetView(BrowserCompositorViewMac* view); 56 gfx::AcceleratedWidget accelerated_widget() { return native_widget_; }
36 void ResetView();
37 57
38 ui::Compositor* compositor() const { return compositor_.get(); } 58 void SetClient(AcceleratedWidgetMacNSView* view);
59 void ResetClient();
39 60
40 // Return true if the last frame swapped has a size in DIP of |dip_size|. 61 // Return true if the last frame swapped has a size in DIP of |dip_size|.
41 bool HasFrameOfSize(const gfx::Size& dip_size) const; 62 bool HasFrameOfSize(const gfx::Size& dip_size) const;
42 63
43 // Return the CGL renderer ID for the surface, if one is available. 64 // Return the CGL renderer ID for the surface, if one is available.
44 int GetRendererID() const; 65 int GetRendererID() const;
45 66
46 // Return true if the renderer should not be throttled by GPU back-pressure. 67 // Return true if the renderer should not be throttled by GPU back-pressure.
47 bool IsRendererThrottlingDisabled() const; 68 bool IsRendererThrottlingDisabled() const;
48 69
49 // Mark a bracket in which new frames are being pumped in a restricted nested 70 // Mark a bracket in which new frames are being pumped in a restricted nested
50 // run loop. 71 // run loop.
51 void BeginPumpingFrames(); 72 void BeginPumpingFrames();
52 void EndPumpingFrames(); 73 void EndPumpingFrames();
53 74
54 void GotAcceleratedFrame( 75 void GotAcceleratedFrame(
55 uint64 surface_handle, int output_surface_id, 76 uint64 surface_handle,
56 const std::vector<ui::LatencyInfo>& latency_info, 77 const std::vector<ui::LatencyInfo>& latency_info,
57 gfx::Size pixel_size, float scale_factor); 78 gfx::Size pixel_size,
79 float scale_factor,
80 const base::Closure& drawn_callback);
58 81
59 void GotSoftwareFrame( 82 void GotSoftwareFrame(
60 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas); 83 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas);
61 84
62 private: 85 private:
63 // IOSurfaceLayerClient implementation: 86 // IOSurfaceLayerClient implementation:
64 bool IOSurfaceLayerShouldAckImmediately() const override; 87 bool IOSurfaceLayerShouldAckImmediately() const override;
65 void IOSurfaceLayerDidDrawFrame() override; 88 void IOSurfaceLayerDidDrawFrame() override;
66 void IOSurfaceLayerHitError() override; 89 void IOSurfaceLayerHitError() override;
67 90
68 void GotAcceleratedCAContextFrame( 91 void GotAcceleratedCAContextFrame(
69 CAContextID ca_context_id, gfx::Size pixel_size, float scale_factor); 92 CAContextID ca_context_id, gfx::Size pixel_size, float scale_factor);
70 93
71 void GotAcceleratedIOSurfaceFrame( 94 void GotAcceleratedIOSurfaceFrame(
72 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor); 95 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor);
73 96
97 void AcknowledgeAcceleratedFrame();
98
74 // Remove a layer from the heirarchy and destroy it. Because the accelerated 99 // Remove a layer from the heirarchy and destroy it. Because the accelerated
75 // layer types may be replaced by a layer of the same type, the layer to 100 // layer types may be replaced by a layer of the same type, the layer to
76 // destroy is parameterized, and, if it is the current layer, the current 101 // destroy is parameterized, and, if it is the current layer, the current
77 // layer is reset. 102 // layer is reset.
78 void DestroyCAContextLayer( 103 void DestroyCAContextLayer(
79 base::scoped_nsobject<CALayerHost> ca_context_layer); 104 base::scoped_nsobject<CALayerHost> ca_context_layer);
80 void DestroyIOSurfaceLayer( 105 void DestroyIOSurfaceLayer(
81 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer); 106 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer);
82 void DestroySoftwareLayer(); 107 void DestroySoftwareLayer();
83 108
84 // The BrowserCompositorViewMac that is using this as its internals. 109 // The AcceleratedWidgetMacNSView that is using this as its internals.
85 BrowserCompositorViewMac* view_; 110 AcceleratedWidgetMacNSView* view_;
86 111
87 // A phony NSView handle used to identify this. 112 // A phony NSView handle used to identify this.
88 gfx::AcceleratedWidget native_widget_; 113 gfx::AcceleratedWidget native_widget_;
89 114
90 // The compositor drawing the contents of this view.
91 scoped_ptr<ui::Compositor> compositor_;
92
93 // A flipped layer, which acts as the parent of the compositing and software 115 // A flipped layer, which acts as the parent of the compositing and software
94 // layers. This layer is flipped so that the we don't need to recompute the 116 // layers. This layer is flipped so that the we don't need to recompute the
95 // origin for sub-layers when their position changes (this is impossible when 117 // origin for sub-layers when their position changes (this is impossible when
96 // using remote layers, as their size change cannot be synchronized with the 118 // using remote layers, as their size change cannot be synchronized with the
97 // window). This indirection is needed because flipping hosted layers (like 119 // window). This indirection is needed because flipping hosted layers (like
98 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable 120 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable
99 // behavior. 121 // behavior.
100 base::scoped_nsobject<CALayer> flipped_layer_; 122 base::scoped_nsobject<CALayer> flipped_layer_;
101 123
102 // The accelerated CoreAnimation layer hosted by the GPU process. 124 // The accelerated CoreAnimation layer hosted by the GPU process.
103 base::scoped_nsobject<CALayerHost> ca_context_layer_; 125 base::scoped_nsobject<CALayerHost> ca_context_layer_;
104 126
105 // The locally drawn accelerated CoreAnimation layer. 127 // The locally drawn accelerated CoreAnimation layer.
106 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer_; 128 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer_;
107 129
108 // The locally drawn software layer. 130 // The locally drawn software layer.
109 base::scoped_nsobject<SoftwareLayer> software_layer_; 131 base::scoped_nsobject<SoftwareLayer> software_layer_;
110 132
111 // The output surface and latency info of the last accelerated surface that 133 // The output surface and latency info of the last accelerated surface that
112 // was swapped. Sent back to the renderer when the accelerated surface is 134 // was swapped. Sent back to the renderer when the accelerated surface is
113 // drawn. 135 // drawn.
114 int accelerated_output_surface_id_; 136 bool has_unacknowledged_accelerated_frame_;
137 base::Closure accelerated_frame_drawn_callback_;
tapted 2014/11/20 05:38:53 could these be combined? i.e. just do has_unackno
ccameron 2014/11/20 21:33:51 Done.
115 std::vector<ui::LatencyInfo> accelerated_latency_info_; 138 std::vector<ui::LatencyInfo> accelerated_latency_info_;
116 139
117 // The size in DIP of the last swap received from |compositor_|. 140 // The size in DIP of the last swap received from |compositor_|.
118 gfx::Size last_swap_size_dip_; 141 gfx::Size last_swap_size_dip_;
119 }; 142 };
120 143
121 #endif // __OBJC__ 144 #endif // __OBJC__
122 145
123 void BrowserCompositorCALayerTreeMacGotAcceleratedFrame( 146 void AcceleratedWidgetMacGotAcceleratedFrame(
124 gfx::AcceleratedWidget widget, 147 gfx::AcceleratedWidget widget, uint64 surface_handle,
125 uint64 surface_handle, int surface_id,
126 const std::vector<ui::LatencyInfo>& latency_info, 148 const std::vector<ui::LatencyInfo>& latency_info,
127 gfx::Size pixel_size, float scale_factor, 149 gfx::Size pixel_size, float scale_factor,
150 const base::Closure& drawn_callback,
128 bool* disable_throttling, int* renderer_id); 151 bool* disable_throttling, int* renderer_id);
129 152
130 void BrowserCompositorCALayerTreeMacGotSoftwareFrame( 153 void AcceleratedWidgetMacGotSoftwareFrame(
131 gfx::AcceleratedWidget widget, 154 gfx::AcceleratedWidget widget,
132 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas); 155 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas);
133 156
134 } // namespace content 157 } // namespace content
135 158
136 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_CA_LAYER_TREE_MAC_H_ 159 #endif // CONTENT_BROWSER_COMPOSITOR_ACCELERATED_WIDGET_HELPER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698