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

Side by Side Diff: content/browser/renderer_host/compositing_iosurface_layer_mac.h

Issue 394883007: Mac: Shift more code into C++ classes from ObjC classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@flip_fix
Patch Set: Touch-ups Created 6 years, 5 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_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
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();
38
39 // Called when the CompositingIOSurfaceLayer gets a new frame.
40 void GotNewFrame();
41
42 // Called when -[CompositingIOSurfaceLayer canDrawInCGLContext] is called,
43 // and is passed the result that will be returned. This manages transitioning
44 // the layer in and out of asynchronous mode, and some logging.
45 void CanDrawCalled(bool needs_display);
46
47 // Called whenever -[CompositingIOSurfaceLayer drawInCGLContext] draws a
48 // frame, or when we need to ack a frame that (due to the vagaries of
49 // CoreAnimation) happens not to have drawn.
50 void AckPendingFrame(bool success);
51
52 // Immediately draw a frame (disregarding vsync) and ensure that the frame is
53 // acknowledged.
54 void ImmediatelyForceDisplayAndAck();
55
56 private:
57 void TimerFired();
58
59 // The client that the owning layer was created with.
60 content::CompositingIOSurfaceLayerClient* client_;
miu 2014/07/16 22:31:55 nit: Please make const since client_ is never modi
ccameron 2014/07/17 02:30:02 Done.
61
62 // The layer that owns this helper.
63 CompositingIOSurfaceLayer* layer_;
miu 2014/07/16 22:31:55 ditto: pointer should be const.
ccameron 2014/07/17 02:30:02 Done.
64
65 // This is set when a frame is received, and un-set when the frame is drawn.
66 bool has_pending_frame_;
67
68 // Incremented every time that this layer is asked to draw but does not have
69 // new content to draw.
70 uint64 did_not_draw_counter_;
71
72 // The browser places back-pressure on the GPU by not acknowledging swap
73 // calls until they appear on the screen. This can lead to hangs if the
74 // view is moved offscreen (among other things). Prevent hangs by always
75 // acknowledging the frame after timeout of 1/6th of a second has passed.
76 base::DelayTimer<CompositingIOSurfaceLayerHelper> timer_;
77 };
78
24 } // namespace content 79 } // namespace content
25 80
26 // The CoreAnimation layer for drawing accelerated content. 81 // The CoreAnimation layer for drawing accelerated content.
27 @interface CompositingIOSurfaceLayer : CAOpenGLLayer { 82 @interface CompositingIOSurfaceLayer : CAOpenGLLayer {
28 @private 83 @private
29 content::CompositingIOSurfaceLayerClient* client_;
30 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_; 84 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_;
31 scoped_refptr<content::CompositingIOSurfaceContext> context_; 85 scoped_refptr<content::CompositingIOSurfaceContext> context_;
32 86
33 // The browser places back-pressure on the GPU by not acknowledging swap
34 // calls until they appear on the screen. This can lead to hangs if the
35 // view is moved offscreen (among other things). Prevent hangs by always
36 // acknowledging the frame after timeout of 1/6th of a second has passed.
37 scoped_ptr<content::CompositingIOSurfaceLayerHelper> helper_; 87 scoped_ptr<content::CompositingIOSurfaceLayerHelper> helper_;
38 scoped_ptr<base::DelayTimer<content::CompositingIOSurfaceLayerHelper>> timer_;
39 88
40 // Used to track when canDrawInCGLContext should return YES. This can be 89 // 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 90 // in response to receiving a new compositor frame, or from any of the events
42 // that cause setNeedsDisplay to be called on the layer. 91 // that cause setNeedsDisplay to be called on the layer.
43 BOOL needs_display_; 92 BOOL needs_display_;
miu 2014/07/16 22:31:55 IMHO, this state should be moved into the helper c
ccameron 2014/07/17 02:30:02 Moved.
44
45 // This is set when a frame is received, and un-set when the frame is drawn.
46 BOOL has_pending_frame_;
47
48 // Incremented every time that this layer is asked to draw but does not have
49 // new content to draw.
50 uint64 did_not_draw_counter_;
51 } 93 }
52 94
53 - (content::CompositingIOSurfaceMac*)iosurface; 95 - (content::CompositingIOSurfaceMac*)iosurface;
54 - (content::CompositingIOSurfaceContext*)context; 96 - (content::CompositingIOSurfaceContext*)context;
55 97
56 - (id)initWithIOSurface:(scoped_refptr<content::CompositingIOSurfaceMac>) 98 - (id)initWithIOSurface:(scoped_refptr<content::CompositingIOSurfaceMac>)
57 iosurface 99 iosurface
58 withScaleFactor:(float)scale_factor 100 withScaleFactor:(float)scale_factor
59 withClient:(content::CompositingIOSurfaceLayerClient*)client; 101 withClient:(content::CompositingIOSurfaceLayerClient*)client;
60 102
61 // Mark that the client is no longer valid and cannot be called back into. 103 // Mark that the client is no longer valid and cannot be called back into. This
104 // must be called before the layer is destroyed.
62 - (void)resetClient; 105 - (void)resetClient;
63 106
64 // Called when a new frame is received. 107 // Called when a new frame is received.
65 - (void)gotNewFrame; 108 - (void)gotNewFrame;
66 109
67 @end 110 @end
68 111
69 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_ 112 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_LAYER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698