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

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: Rebase 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 whenever -[CompositingIOSurfaceLayer setNeedsDisplay] is called.
43 void SetNeedsDisplay();
44
45 // Called whenever -[CompositingIOSurfaceLayer canDrawInCGLContext] is called,
46 // to determine if a new frame should be drawn.
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_;
70
71 // Used to track when canDrawInCGLContext should return YES. This can be
72 // in response to receiving a new compositor frame, or from any of the events
73 // that cause setNeedsDisplay to be called on the layer.
74 bool needs_display_;
75
76 // This is set when a frame is received, and un-set when the frame is drawn.
77 bool has_pending_frame_;
78
79 // Incremented every time that this layer is asked to draw but does not have
80 // new content to draw.
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
24 } // namespace content 90 } // namespace content
25 91
26 // The CoreAnimation layer for drawing accelerated content. 92 // The CoreAnimation layer for drawing accelerated content.
27 @interface CompositingIOSurfaceLayer : CAOpenGLLayer { 93 @interface CompositingIOSurfaceLayer : CAOpenGLLayer {
28 @private 94 @private
29 content::CompositingIOSurfaceLayerClient* client_;
30 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_; 95 scoped_refptr<content::CompositingIOSurfaceMac> iosurface_;
31 scoped_refptr<content::CompositingIOSurfaceContext> context_; 96 scoped_refptr<content::CompositingIOSurfaceContext> context_;
32 97
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_; 98 scoped_ptr<content::CompositingIOSurfaceLayerHelper> helper_;
38 scoped_ptr<base::DelayTimer<content::CompositingIOSurfaceLayerHelper>> timer_;
39
40 // 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
42 // that cause setNeedsDisplay to be called on the layer.
43 BOOL needs_display_;
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 } 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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698