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

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

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

Powered by Google App Engine
This is Rietveld 408576698