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

Side by Side Diff: content/browser/compositor/browser_compositor_view_private_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_BROWSER_COMPOSITOR_VIEW_PRIVATE_MAC_H_ 5 #ifndef CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_PRIVATE_MAC_H_
6 #define CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_PRIVATE_MAC_H_ 6 #define CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_PRIVATE_MAC_H_
7 7
8 #include "content/browser/compositor/browser_compositor_view_mac.h" 8 #include "content/browser/compositor/browser_compositor_view_mac.h"
9 9
10 @class BrowserCompositorViewCocoa;
11
10 namespace content { 12 namespace content {
11 class BrowserCompositorViewCocoaHelper;
12 }
13 13
14 // An NSView drawn by a ui::Compositor. This structure is expensive to create, 14 // BrowserCompositorViewCocoaClient is the interface through which
15 // because it has a ui::Compositor. As a result, this structure may be recycled 15 // gfx::NativeWidget (aka NSView aka BrowserCompositorViewCocoa) calls back to
16 // across multiple BrowserCompositorViewMac objects. 16 // BrowserCompositorViewMacInternal.
17 @interface BrowserCompositorViewCocoa : NSView { 17 class BrowserCompositorViewCocoaClient {
18 public:
19 virtual void GotAcceleratedIOSurfaceFrame(
20 IOSurfaceID io_surface_id,
21 int output_surface_id,
22 const std::vector<ui::LatencyInfo>& latency_info,
23 gfx::Size pixel_size,
24 float scale_factor) = 0;
25
26 virtual void GotSoftwareFrame(
27 cc::SoftwareFrameData* frame_data,
28 float scale_factor,
29 SkCanvas* canvas) = 0;
30 };
31
32 // BrowserCompositorViewMacInternal owns a NSView and a ui::Compositor that
33 // draws that view.
34 class BrowserCompositorViewMacInternal
35 : public BrowserCompositorViewCocoaClient,
36 public CompositingIOSurfaceLayerClient {
37 public:
38 BrowserCompositorViewMacInternal();
39 virtual ~BrowserCompositorViewMacInternal();
40
41 void SetClient(BrowserCompositorViewMacClient* client);
42 void ResetClient();
43
44 ui::Compositor* compositor() const { return compositor_.get(); }
45
46 private:
47 // BrowserCompositorViewCocoaClient implementation:
48 virtual void GotAcceleratedIOSurfaceFrame(
49 IOSurfaceID io_surface_id,
50 int output_surface_id,
51 const std::vector<ui::LatencyInfo>& latency_info,
52 gfx::Size pixel_size,
53 float scale_factor) OVERRIDE;
54 virtual void GotSoftwareFrame(
55 cc::SoftwareFrameData* frame_data,
56 float scale_factor,
57 SkCanvas* canvas) OVERRIDE;
58
59 // CompositingIOSurfaceLayerClient implementation:
60 virtual void AcceleratedLayerDidDrawFrame(bool succeeded) OVERRIDE;
61
62 // The client of the BrowserCompositorViewMac that is using this as its
63 // internals.
64 BrowserCompositorViewMacClient* client_;
65
66 // The NSView drawn by the |compositor_|
67 base::scoped_nsobject<BrowserCompositorViewCocoa> cocoa_view_;
68
69 // The compositor drawing the contents of |cooca_view_|. Note that this must
70 // be declared after |cocoa_view_|, so that it be destroyed first (because it
71 // will reach into |cocoa_view_|).
18 scoped_ptr<ui::Compositor> compositor_; 72 scoped_ptr<ui::Compositor> compositor_;
19 73
74
20 // A flipped layer, which acts as the parent of the compositing and software 75 // A flipped layer, which acts as the parent of the compositing and software
21 // layers. This layer is flipped so that the we don't need to recompute the 76 // layers. This layer is flipped so that the we don't need to recompute the
22 // origin for sub-layers when their position changes (this is impossible when 77 // origin for sub-layers when their position changes (this is impossible when
23 // using remote layers, as their size change cannot be synchronized with the 78 // using remote layers, as their size change cannot be synchronized with the
24 // window). This indirection is needed because flipping hosted layers (like 79 // window). This indirection is needed because flipping hosted layers (like
25 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable 80 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable
26 // behavior. 81 // behavior.
27 base::scoped_nsobject<CALayer> flipped_layer_; 82 base::scoped_nsobject<CALayer> flipped_layer_;
28 83
29 base::scoped_nsobject<CompositingIOSurfaceLayer> accelerated_layer_; 84 base::scoped_nsobject<CompositingIOSurfaceLayer> accelerated_layer_;
30 int accelerated_layer_output_surface_id_; 85 int accelerated_layer_output_surface_id_;
31 std::vector<ui::LatencyInfo> accelerated_latency_info_; 86 std::vector<ui::LatencyInfo> accelerated_latency_info_;
32 87
33 base::scoped_nsobject<SoftwareLayer> software_layer_; 88 base::scoped_nsobject<SoftwareLayer> software_layer_;
34
35 content::BrowserCompositorViewMacClient* client_;
36 scoped_ptr<content::BrowserCompositorViewCocoaHelper> helper_;
37 }
38
39 // Change the client and superview of the view. If this is set to NULL then
40 // the compositor will be prepared to be recycled.
41 - (void)setClient:(content::BrowserCompositorViewMacClient*)client;
42
43 // This is called to destroy the underlying ui::Compositor, if it is known
44 // that this will not be recycled again.
45 - (void)destroyCompositor;
46
47 // Access the underlying ui::Compositor for this view.
48 - (ui::Compositor*)compositor;
49
50 // Called when the accelerated or software layer draws its frame to the screen.
51 - (void)layerDidDrawFrame;
52
53 // Called when an error is encountered while drawing to the screen.
54 - (void)gotAcceleratedLayerError;
55
56 @end // BrowserCompositorViewCocoa
57
58 namespace content {
59
60 // This class implements the parts of BrowserCompositorViewCocoa that need to
61 // be a C++ class and not an Objective C class.
62 class BrowserCompositorViewCocoaHelper
63 : public content::CompositingIOSurfaceLayerClient {
64 public:
65 BrowserCompositorViewCocoaHelper(BrowserCompositorViewCocoa* view)
66 : view_(view) {}
67 virtual ~BrowserCompositorViewCocoaHelper() {}
68
69 private:
70 // CompositingIOSurfaceLayerClient implementation:
71 virtual void AcceleratedLayerDidDrawFrame(bool succeeded) OVERRIDE;
72
73 BrowserCompositorViewCocoa* view_;
74 }; 89 };
75 90
76 } // namespace content 91 } // namespace content
77 92
93 // BrowserCompositorViewCocoa is the actual NSView to which the layers drawn
94 // by the ui::Compositor are attached.
95 @interface BrowserCompositorViewCocoa : NSView {
96 content::BrowserCompositorViewCocoaClient* client_;
97 }
98
99 - (id)initWithClient:(content::BrowserCompositorViewCocoaClient*)client;
100
101 // Mark that the client provided at initialization is no longer valid and may
102 // not be called back into.
103 - (void)resetClient;
104 @end
105
78 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_PRIVATE_MAC_H_ 106 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_PRIVATE_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698