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 | 13 |
14 @class CompositingIOSurfaceLayer; | |
15 | |
14 namespace content { | 16 namespace content { |
15 class CompositingIOSurfaceMac; | 17 class CompositingIOSurfaceMac; |
16 class CompositingIOSurfaceContext; | 18 class CompositingIOSurfaceContext; |
17 class CompositingIOSurfaceLayerHelper; | |
18 | 19 |
20 // The interface through which the CompositingIOSurfaceLayer calls back into | |
21 // the structrue that created it (RenderWidgetHostViewMac or | |
22 // BrowserCompositorViewMac). | |
19 class CompositingIOSurfaceLayerClient { | 23 class CompositingIOSurfaceLayerClient { |
20 public: | 24 public: |
21 virtual void AcceleratedLayerDidDrawFrame(bool succeeded) = 0; | 25 virtual void AcceleratedLayerDidDrawFrame(bool succeeded) = 0; |
22 }; | 26 }; |
23 | 27 |
24 } // namespace content | 28 // CompositingIOSurfaceLayerHelper provides C++ functionality needed for the |
29 // CompositingIOSurfaceLayer class, and does most of the heavy lifting for the | |
30 // class. | |
31 // TODO(ccameron): This class should own CompositingIOSurfaceLayer, rather than | |
32 // vice versa. | |
33 class CompositingIOSurfaceLayerHelper { | |
34 public: | |
35 CompositingIOSurfaceLayerHelper(CompositingIOSurfaceLayerClient* client, | |
36 CompositingIOSurfaceLayer* layer); | |
37 ~CompositingIOSurfaceLayerHelper(); | |
25 | 38 |
26 // The CoreAnimation layer for drawing accelerated content. | 39 // Called when the CompositingIOSurfaceLayer gets a new frame. |
27 @interface CompositingIOSurfaceLayer : CAOpenGLLayer { | 40 void GotNewFrame(); |
28 @private | |
29 content::CompositingIOSurfaceLayerClient* client_; | |
30 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_; | |
31 scoped_refptr<content::CompositingIOSurfaceContext> context_; | |
32 | 41 |
33 // The browser places back-pressure on the GPU by not acknowledging swap | 42 // Called whenever -[CompositingIOSurfaceLayer setNeedsDisplay] is called. |
34 // calls until they appear on the screen. This can lead to hangs if the | 43 void SetNeedsDisplay(); |
35 // view is moved offscreen (among other things). Prevent hangs by always | 44 |
36 // acknowledging the frame after timeout of 1/6th of a second has passed. | 45 // Called whenever -[CompositingIOSurfaceLayer canDrawInCGLContext] is called, |
37 scoped_ptr<content::CompositingIOSurfaceLayerHelper> helper_; | 46 // to determine if a new frame should be drawn. |
38 scoped_ptr<base::DelayTimer<content::CompositingIOSurfaceLayerHelper>> timer_; | 47 bool CanDraw(); |
48 | |
49 // Called whenever -[CompositingIOSurfaceLayer drawInCGLContext] draws a | |
50 // frame. | |
51 void DidDraw(bool success); | |
52 | |
53 private: | |
54 // Immediately draw a frame (disregarding vsync) and ensure that the frame is | |
55 // acknowledged. | |
56 void ImmediatelyForceDisplayAndAck(); | |
57 | |
58 // Called whenever the frame provided in GotNewFrame should be acknowledged | |
59 // (this may be because it was drawn, or it may be to unblock the | |
60 // compositor). | |
61 void AckPendingFrame(bool success); | |
62 | |
63 void TimerFired(); | |
64 | |
65 // The client that the owning layer was created with. | |
66 content::CompositingIOSurfaceLayerClient* const client_; | |
67 | |
68 // The layer that owns this helper. | |
69 CompositingIOSurfaceLayer* const layer_; | |
39 | 70 |
40 // Used to track when canDrawInCGLContext should return YES. This can be | 71 // Used to track when canDrawInCGLContext should return YES. This can be |
41 // in response to receiving a new compositor frame, or from any of the events | 72 // in response to receiving a new compositor frame, or from any of the events |
42 // that cause setNeedsDisplay to be called on the layer. | 73 // that cause setNeedsDisplay to be called on the layer. |
43 BOOL needs_display_; | 74 BOOL needs_display_; |
miu
2014/07/17 06:12:55
s/BOOL/bool/
| |
44 | 75 |
45 // This is set when a frame is received, and un-set when the frame is drawn. | 76 // This is set when a frame is received, and un-set when the frame is drawn. |
46 BOOL has_pending_frame_; | 77 bool has_pending_frame_; |
47 | 78 |
48 // Incremented every time that this layer is asked to draw but does not have | 79 // Incremented every time that this layer is asked to draw but does not have |
49 // new content to draw. | 80 // new content to draw. |
50 uint64 did_not_draw_counter_; | 81 uint64 did_not_draw_counter_; |
82 | |
83 // The browser places back-pressure on the GPU by not acknowledging swap | |
84 // calls until they appear on the screen. This can lead to hangs if the | |
85 // view is moved offscreen (among other things). Prevent hangs by always | |
86 // acknowledging the frame after timeout of 1/6th of a second has passed. | |
87 base::DelayTimer<CompositingIOSurfaceLayerHelper> timer_; | |
88 }; | |
89 | |
90 } // namespace content | |
91 | |
92 // The CoreAnimation layer for drawing accelerated content. | |
93 @interface CompositingIOSurfaceLayer : CAOpenGLLayer { | |
94 @private | |
95 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_; | |
96 scoped_refptr<content::CompositingIOSurfaceContext> context_; | |
97 | |
98 scoped_ptr<content::CompositingIOSurfaceLayerHelper> helper_; | |
51 } | 99 } |
52 | 100 |
53 - (content::CompositingIOSurfaceMac*)iosurface; | 101 - (content::CompositingIOSurfaceMac*)iosurface; |
54 - (content::CompositingIOSurfaceContext*)context; | 102 - (content::CompositingIOSurfaceContext*)context; |
55 | 103 |
56 - (id)initWithIOSurface:(scoped_refptr<content::CompositingIOSurfaceMac>) | 104 - (id)initWithIOSurface:(scoped_refptr<content::CompositingIOSurfaceMac>) |
57 iosurface | 105 iosurface |
58 withScaleFactor:(float)scale_factor | 106 withScaleFactor:(float)scale_factor |
59 withClient:(content::CompositingIOSurfaceLayerClient*)client; | 107 withClient:(content::CompositingIOSurfaceLayerClient*)client; |
60 | 108 |
61 // Mark that the client is no longer valid and cannot be called back into. | 109 // Mark that the client is no longer valid and cannot be called back into. This |
110 // must be called before the layer is destroyed. | |
62 - (void)resetClient; | 111 - (void)resetClient; |
63 | 112 |
64 // Called when a new frame is received. | 113 // Called when a new frame is received. |
65 - (void)gotNewFrame; | 114 - (void)gotNewFrame; |
66 | 115 |
67 @end | 116 @end |
68 | 117 |
69 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ | 118 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ |
OLD | NEW |