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

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

Issue 596703006: Revert IOSurface CoreAnimation simplifications on ccameron@'s advice. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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_COMPOSITOR_IO_SURFACE_LAYER_MAC_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_
6 #define CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_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 #include <IOSurface/IOSurfaceAPI.h>
10 9
11 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
14 #include "ui/gfx/size.h" 13 #include "ui/gfx/size.h"
15 #include "ui/gl/scoped_cgl.h"
16 14
17 @class IOSurfaceLayer; 15 @class IOSurfaceLayer;
18 16
19 namespace content { 17 namespace content {
20 class IOSurfaceLayerHelper; 18 class CompositingIOSurfaceMac;
19 class CompositingIOSurfaceContext;
21 20
22 // The interface through which the IOSurfaceLayer calls back into 21 // The interface through which the IOSurfaceLayer calls back into
23 // the structrue that created it (RenderWidgetHostViewMac or 22 // the structrue that created it (RenderWidgetHostViewMac or
24 // BrowserCompositorViewMac). 23 // BrowserCompositorViewMac).
25 class IOSurfaceLayerClient { 24 class IOSurfaceLayerClient {
26 public: 25 public:
27 // 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
28 // 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
29 // immediately. 28 // immediately.
30 virtual bool IOSurfaceLayerShouldAckImmediately() const = 0; 29 virtual bool IOSurfaceLayerShouldAckImmediately() const = 0;
31 30
32 // 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
33 // is known that the frame will never drawn. 32 // is known that the frame will never drawn.
34 virtual void IOSurfaceLayerDidDrawFrame() = 0; 33 virtual void IOSurfaceLayerDidDrawFrame() = 0;
35 34
36 // Called when an error prevents the frame from being drawn. 35 // Called when an error prevents the frame from being drawn.
37 virtual void IOSurfaceLayerHitError() = 0; 36 virtual void IOSurfaceLayerHitError() = 0;
38 }; 37 };
39 38
40 } // namespace content 39 // IOSurfaceLayerHelper provides C++ functionality needed for the
40 // IOSurfaceLayer class, and does most of the heavy lifting for the
41 // class.
42 // TODO(ccameron): This class should own IOSurfaceLayer, rather than
43 // vice versa.
44 class IOSurfaceLayerHelper {
45 public:
46 IOSurfaceLayerHelper(IOSurfaceLayerClient* client,
47 IOSurfaceLayer* layer);
48 ~IOSurfaceLayerHelper();
41 49
42 // The CoreAnimation layer for drawing accelerated content. 50 // Called when the IOSurfaceLayer gets a new frame.
43 @interface IOSurfaceLayer : CAOpenGLLayer { 51 void GotNewFrame();
44 @private 52
45 content::IOSurfaceLayerClient* client_; 53 // Called whenever -[IOSurfaceLayer setNeedsDisplay] is called.
46 scoped_ptr<content::IOSurfaceLayerHelper> helper_; 54 void SetNeedsDisplay();
55
56 // Called whenever -[IOSurfaceLayer canDrawInCGLContext] is called,
57 // to determine if a new frame should be drawn.
58 bool CanDraw();
59
60 // Called whenever -[IOSurfaceLayer drawInCGLContext] draws a
61 // frame.
62 void DidDraw(bool success);
63
64 // Immediately re-draw the layer, even if the content has not changed, and
65 // ensure that the frame be acked.
66 void SetNeedsDisplayAndDisplayAndAck();
67
68 // Immediately draw the layer, only if one is pending, and ensure that the
69 // frame be acked.
70 void DisplayIfNeededAndAck();
71
72 // Mark a bracket in which new frames are being pumped in a restricted nested
73 // run loop. During this time frames are acked immediately and draws are
74 // deferred until the bracket ends.
75 void BeginPumpingFrames();
76 void EndPumpingFrames();
77
78 private:
79 // Called whenever the frame provided in GotNewFrame should be acknowledged
80 // (this may be because it was drawn, or it may be to unblock the
81 // compositor).
82 void AckPendingFrame(bool success);
83
84 void TimerFired();
85
86 // The client that the owning layer was created with.
87 content::IOSurfaceLayerClient* const client_;
88
89 // The layer that owns this helper.
90 IOSurfaceLayer* const layer_;
47 91
48 // Used to track when canDrawInCGLContext should return YES. This can be 92 // Used to track when canDrawInCGLContext should return YES. This can be
49 // 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
50 // that cause setNeedsDisplay to be called on the layer. 94 // that cause setNeedsDisplay to be called on the layer.
51 bool needs_display_; 95 bool needs_display_;
52 96
53 // 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.
54 bool has_pending_frame_; 98 bool has_pending_frame_;
55 99
56 // 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
57 // new content to draw. 101 // new content to draw.
58 uint64 did_not_draw_counter_; 102 uint64 did_not_draw_counter_;
59 103
60 // Set when inside a BeginPumpingFrames/EndPumpingFrames block. 104 // Set when inside a BeginPumpingFrames/EndPumpingFrames block.
61 bool is_pumping_frames_; 105 bool is_pumping_frames_;
62 106
63 // The IOSurface being drawn by this layer. 107 // The browser places back-pressure on the GPU by not acknowledging swap
64 base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; 108 // calls until they appear on the screen. This can lead to hangs if the
109 // view is moved offscreen (among other things). Prevent hangs by always
110 // acknowledging the frame after timeout of 1/6th of a second has passed.
111 base::DelayTimer<IOSurfaceLayerHelper> timer_;
112 };
65 113
66 // The size of the frame in pixels. This will be less or equal than the pixel 114 } // namespace content
67 // size of |io_surface_|.
68 gfx::Size frame_pixel_size_;
69 115
70 // The GL texture that was bound to |io_surface_| during the last draw call, 116 // The CoreAnimation layer for drawing accelerated content.
71 // along with the context that was done in, and the value of |io_surface_| at 117 @interface IOSurfaceLayer : CAOpenGLLayer {
72 // the time of the bind. 118 @private
73 GLuint io_surface_texture_; 119 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_;
74 base::ScopedTypeRef<CGLContextObj> io_surface_texture_context_; 120 scoped_refptr<content::CompositingIOSurfaceContext> context_;
75 base::ScopedCFTypeRef<IOSurfaceRef> io_surface_texture_io_surface_;
76 121
77 // The CGL renderer ID, captured at draw time. 122 scoped_ptr<content::IOSurfaceLayerHelper> helper_;
78 GLint cgl_renderer_id_;
79 } 123 }
80 124
81 - (id)initWithClient:(content::IOSurfaceLayerClient*)client 125 - (id)initWithClient:(content::IOSurfaceLayerClient*)client
82 withScaleFactor:(float)scale_factor; 126 withScaleFactor:(float)scale_factor;
83 127
84 // Called when a new frame is received. 128 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id
85 - (void)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id
86 withPixelSize:(gfx::Size)pixel_size 129 withPixelSize:(gfx::Size)pixel_size
87 withScaleFactor:(float)scale_factor; 130 withScaleFactor:(float)scale_factor;
88 131
132 // Context poison accessors.
133 - (void)poisonContextAndSharegroup;
134 - (bool)hasBeenPoisoned;
135
89 - (float)scaleFactor; 136 - (float)scaleFactor;
90 137
91 // The CGL renderer ID. 138 // The CGL renderer ID.
92 - (int)rendererID; 139 - (int)rendererID;
93 140
94 // 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
95 // must be called before the layer is destroyed. 142 // must be called before the layer is destroyed.
96 - (void)resetClient; 143 - (void)resetClient;
97 144
145 // Called when a new frame is received.
146 - (void)gotNewFrame;
147
98 // 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
99 // displayed frame). 149 // displayed frame).
100 - (void)setNeedsDisplayAndDisplayAndAck; 150 - (void)setNeedsDisplayAndDisplayAndAck;
101 151
152 // Force a draw immediately, but only if one was requested.
153 - (void)displayIfNeededAndAck;
154
102 // 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
103 // run loop. 156 // run loop.
104 - (void)beginPumpingFrames; 157 - (void)beginPumpingFrames;
105 - (void)endPumpingFrames; 158 - (void)endPumpingFrames;
106 @end 159 @end
107 160
108 #endif // CONTENT_BROWSER_COMPOSITOR_IO_SURFACE_LAYER_MAC_H_ 161 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_
OLDNEW
« no previous file with comments | « content/browser/compositor/browser_compositor_view_private_mac.mm ('k') | content/browser/compositor/io_surface_layer_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698