OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "ui/gfx/size.h" |
13 | 14 |
14 @class CompositingIOSurfaceLayer; | 15 @class IOSurfaceLayer; |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 class CompositingIOSurfaceMac; | 18 class CompositingIOSurfaceMac; |
18 class CompositingIOSurfaceContext; | 19 class CompositingIOSurfaceContext; |
19 | 20 |
20 // The interface through which the CompositingIOSurfaceLayer calls back into | 21 // The interface through which the IOSurfaceLayer calls back into |
21 // the structrue that created it (RenderWidgetHostViewMac or | 22 // the structrue that created it (RenderWidgetHostViewMac or |
22 // BrowserCompositorViewMac). | 23 // BrowserCompositorViewMac). |
23 class CompositingIOSurfaceLayerClient { | 24 class IOSurfaceLayerClient { |
24 public: | 25 public: |
25 // Used to indicate that the layer should attempt to draw immediately and | 26 // Used to indicate that the layer should attempt to draw immediately and |
26 // should (even if the draw is elided by the system), ack the frame | 27 // should (even if the draw is elided by the system), ack the frame |
27 // immediately. | 28 // immediately. |
28 virtual bool AcceleratedLayerShouldAckImmediately() const = 0; | 29 virtual bool IOSurfaceLayerShouldAckImmediately() const = 0; |
29 | 30 |
30 // Called when a frame is drawn or when, because the layer is not visible, it | 31 // Called when a frame is drawn or when, because the layer is not visible, it |
31 // is known that the frame will never drawn. | 32 // is known that the frame will never drawn. |
32 virtual void AcceleratedLayerDidDrawFrame() = 0; | 33 virtual void IOSurfaceLayerDidDrawFrame() = 0; |
33 | 34 |
34 // Called when an error prevents the frame from being drawn. | 35 // Called when an error prevents the frame from being drawn. |
35 virtual void AcceleratedLayerHitError() = 0; | 36 virtual void IOSurfaceLayerHitError() = 0; |
36 }; | 37 }; |
37 | 38 |
38 // CompositingIOSurfaceLayerHelper provides C++ functionality needed for the | 39 // IOSurfaceLayerHelper provides C++ functionality needed for the |
39 // CompositingIOSurfaceLayer class, and does most of the heavy lifting for the | 40 // IOSurfaceLayer class, and does most of the heavy lifting for the |
40 // class. | 41 // class. |
41 // TODO(ccameron): This class should own CompositingIOSurfaceLayer, rather than | 42 // TODO(ccameron): This class should own IOSurfaceLayer, rather than |
42 // vice versa. | 43 // vice versa. |
43 class CompositingIOSurfaceLayerHelper { | 44 class IOSurfaceLayerHelper { |
44 public: | 45 public: |
45 CompositingIOSurfaceLayerHelper(CompositingIOSurfaceLayerClient* client, | 46 IOSurfaceLayerHelper(IOSurfaceLayerClient* client, |
46 CompositingIOSurfaceLayer* layer); | 47 IOSurfaceLayer* layer); |
47 ~CompositingIOSurfaceLayerHelper(); | 48 ~IOSurfaceLayerHelper(); |
48 | 49 |
49 // Called when the CompositingIOSurfaceLayer gets a new frame. | 50 // Called when the IOSurfaceLayer gets a new frame. |
50 void GotNewFrame(); | 51 void GotNewFrame(); |
51 | 52 |
52 // Called whenever -[CompositingIOSurfaceLayer setNeedsDisplay] is called. | 53 // Called whenever -[IOSurfaceLayer setNeedsDisplay] is called. |
53 void SetNeedsDisplay(); | 54 void SetNeedsDisplay(); |
54 | 55 |
55 // Called whenever -[CompositingIOSurfaceLayer canDrawInCGLContext] is called, | 56 // Called whenever -[IOSurfaceLayer canDrawInCGLContext] is called, |
56 // to determine if a new frame should be drawn. | 57 // to determine if a new frame should be drawn. |
57 bool CanDraw(); | 58 bool CanDraw(); |
58 | 59 |
59 // Called whenever -[CompositingIOSurfaceLayer drawInCGLContext] draws a | 60 // Called whenever -[IOSurfaceLayer drawInCGLContext] draws a |
60 // frame. | 61 // frame. |
61 void DidDraw(bool success); | 62 void DidDraw(bool success); |
62 | 63 |
63 // Immediately re-draw the layer, even if the content has not changed, and | 64 // Immediately re-draw the layer, even if the content has not changed, and |
64 // ensure that the frame be acked. | 65 // ensure that the frame be acked. |
65 void SetNeedsDisplayAndDisplayAndAck(); | 66 void SetNeedsDisplayAndDisplayAndAck(); |
66 | 67 |
67 // Immediately draw the layer, only if one is pending, and ensure that the | 68 // Immediately draw the layer, only if one is pending, and ensure that the |
68 // frame be acked. | 69 // frame be acked. |
69 void DisplayIfNeededAndAck(); | 70 void DisplayIfNeededAndAck(); |
70 | 71 |
71 // 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 |
72 // run loop. During this time frames are acked immediately and draws are | 73 // run loop. During this time frames are acked immediately and draws are |
73 // deferred until the bracket ends. | 74 // deferred until the bracket ends. |
74 void BeginPumpingFrames(); | 75 void BeginPumpingFrames(); |
75 void EndPumpingFrames(); | 76 void EndPumpingFrames(); |
76 | 77 |
77 private: | 78 private: |
78 // Called whenever the frame provided in GotNewFrame should be acknowledged | 79 // Called whenever the frame provided in GotNewFrame should be acknowledged |
79 // (this may be because it was drawn, or it may be to unblock the | 80 // (this may be because it was drawn, or it may be to unblock the |
80 // compositor). | 81 // compositor). |
81 void AckPendingFrame(bool success); | 82 void AckPendingFrame(bool success); |
82 | 83 |
83 void TimerFired(); | 84 void TimerFired(); |
84 | 85 |
85 // The client that the owning layer was created with. | 86 // The client that the owning layer was created with. |
86 content::CompositingIOSurfaceLayerClient* const client_; | 87 content::IOSurfaceLayerClient* const client_; |
87 | 88 |
88 // The layer that owns this helper. | 89 // The layer that owns this helper. |
89 CompositingIOSurfaceLayer* const layer_; | 90 IOSurfaceLayer* const layer_; |
90 | 91 |
91 // Used to track when canDrawInCGLContext should return YES. This can be | 92 // Used to track when canDrawInCGLContext should return YES. This can be |
92 // in response to receiving a new compositor frame, or from any of the events | 93 // in response to receiving a new compositor frame, or from any of the events |
93 // that cause setNeedsDisplay to be called on the layer. | 94 // that cause setNeedsDisplay to be called on the layer. |
94 bool needs_display_; | 95 bool needs_display_; |
95 | 96 |
96 // This is set when a frame is received, and un-set when the frame is drawn. | 97 // This is set when a frame is received, and un-set when the frame is drawn. |
97 bool has_pending_frame_; | 98 bool has_pending_frame_; |
98 | 99 |
99 // Incremented every time that this layer is asked to draw but does not have | 100 // Incremented every time that this layer is asked to draw but does not have |
100 // new content to draw. | 101 // new content to draw. |
101 uint64 did_not_draw_counter_; | 102 uint64 did_not_draw_counter_; |
102 | 103 |
103 // Set when inside a BeginPumpingFrames/EndPumpingFrames block. | 104 // Set when inside a BeginPumpingFrames/EndPumpingFrames block. |
104 bool is_pumping_frames_; | 105 bool is_pumping_frames_; |
105 | 106 |
106 // The browser places back-pressure on the GPU by not acknowledging swap | 107 // The browser places back-pressure on the GPU by not acknowledging swap |
107 // calls until they appear on the screen. This can lead to hangs if the | 108 // calls until they appear on the screen. This can lead to hangs if the |
108 // view is moved offscreen (among other things). Prevent hangs by always | 109 // view is moved offscreen (among other things). Prevent hangs by always |
109 // acknowledging the frame after timeout of 1/6th of a second has passed. | 110 // acknowledging the frame after timeout of 1/6th of a second has passed. |
110 base::DelayTimer<CompositingIOSurfaceLayerHelper> timer_; | 111 base::DelayTimer<IOSurfaceLayerHelper> timer_; |
111 }; | 112 }; |
112 | 113 |
113 } // namespace content | 114 } // namespace content |
114 | 115 |
115 // The CoreAnimation layer for drawing accelerated content. | 116 // The CoreAnimation layer for drawing accelerated content. |
116 @interface CompositingIOSurfaceLayer : CAOpenGLLayer { | 117 @interface IOSurfaceLayer : CAOpenGLLayer { |
117 @private | 118 @private |
118 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_; | 119 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_; |
119 scoped_refptr<content::CompositingIOSurfaceContext> context_; | 120 scoped_refptr<content::CompositingIOSurfaceContext> context_; |
120 | 121 |
121 scoped_ptr<content::CompositingIOSurfaceLayerHelper> helper_; | 122 scoped_ptr<content::IOSurfaceLayerHelper> helper_; |
122 } | 123 } |
123 | 124 |
124 - (content::CompositingIOSurfaceMac*)iosurface; | 125 - (id)initWithClient:(content::IOSurfaceLayerClient*)client |
125 - (content::CompositingIOSurfaceContext*)context; | 126 withScaleFactor:(float)scale_factor; |
126 | 127 |
127 - (id)initWithIOSurface:(scoped_refptr<content::CompositingIOSurfaceMac>) | 128 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id |
128 iosurface | 129 withPixelSize:(gfx::Size)pixel_size |
129 withScaleFactor:(float)scale_factor | 130 withScaleFactor:(float)scale_factor; |
130 withClient:(content::CompositingIOSurfaceLayerClient*)client; | 131 |
| 132 // Context poison accessors. |
| 133 - (void)poisonContextAndSharegroup; |
| 134 - (bool)hasBeenPoisoned; |
| 135 |
| 136 - (float)scaleFactor; |
| 137 |
| 138 // The CGL renderer ID. |
| 139 - (int)rendererID; |
131 | 140 |
132 // Mark that the client is no longer valid and cannot be called back into. This | 141 // Mark that the client is no longer valid and cannot be called back into. This |
133 // must be called before the layer is destroyed. | 142 // must be called before the layer is destroyed. |
134 - (void)resetClient; | 143 - (void)resetClient; |
135 | 144 |
136 // Called when a new frame is received. | 145 // Called when a new frame is received. |
137 - (void)gotNewFrame; | 146 - (void)gotNewFrame; |
138 | 147 |
139 // Force a draw immediately (even if this means re-displaying a previously | 148 // Force a draw immediately (even if this means re-displaying a previously |
140 // displayed frame). | 149 // displayed frame). |
141 - (void)setNeedsDisplayAndDisplayAndAck; | 150 - (void)setNeedsDisplayAndDisplayAndAck; |
142 | 151 |
143 // Force a draw immediately, but only if one was requested. | 152 // Force a draw immediately, but only if one was requested. |
144 - (void)displayIfNeededAndAck; | 153 - (void)displayIfNeededAndAck; |
145 | 154 |
146 // Mark a bracket in which new frames are being pumped in a restricted nested | 155 // Mark a bracket in which new frames are being pumped in a restricted nested |
147 // run loop. | 156 // run loop. |
148 - (void)beginPumpingFrames; | 157 - (void)beginPumpingFrames; |
149 - (void)endPumpingFrames; | 158 - (void)endPumpingFrames; |
150 @end | 159 @end |
151 | 160 |
152 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ | 161 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ |
OLD | NEW |