OLD | NEW |
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 compositor drawing the contents of |cooca_view_|. |
18 scoped_ptr<ui::Compositor> compositor_; | 67 scoped_ptr<ui::Compositor> compositor_; |
19 | 68 |
20 // The layer hosted by this view. | 69 // The NSView drawn by the |compositor_| |
| 70 base::scoped_nsobject<BrowserCompositorViewCocoa> cocoa_view_; |
| 71 |
| 72 // The layer hosted by cocoa_view_. |
21 base::scoped_nsobject<CALayer> background_layer_; | 73 base::scoped_nsobject<CALayer> background_layer_; |
22 | 74 |
23 // 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 |
24 // 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 |
25 // 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 |
26 // 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 |
27 // window). This indirection is needed because flipping hosted layers (like | 79 // window). This indirection is needed because flipping hosted layers (like |
28 // |background_layer_|) leads to unpredictable behavior. | 80 // |background_layer_|) leads to unpredictable behavior. |
29 base::scoped_nsobject<CALayer> flipped_layer_; | 81 base::scoped_nsobject<CALayer> flipped_layer_; |
30 | 82 |
31 base::scoped_nsobject<CompositingIOSurfaceLayer> accelerated_layer_; | 83 base::scoped_nsobject<CompositingIOSurfaceLayer> accelerated_layer_; |
32 int accelerated_layer_output_surface_id_; | 84 int accelerated_layer_output_surface_id_; |
33 std::vector<ui::LatencyInfo> accelerated_latency_info_; | 85 std::vector<ui::LatencyInfo> accelerated_latency_info_; |
34 | 86 |
35 base::scoped_nsobject<SoftwareLayer> software_layer_; | 87 base::scoped_nsobject<SoftwareLayer> software_layer_; |
36 | |
37 content::BrowserCompositorViewMacClient* client_; | |
38 scoped_ptr<content::BrowserCompositorViewCocoaHelper> helper_; | |
39 } | |
40 | |
41 // Change the client and superview of the view. If this is set to NULL then | |
42 // the compositor will be prepared to be recycled. | |
43 - (void)setClient:(content::BrowserCompositorViewMacClient*)client; | |
44 | |
45 // This is called to destroy the underlying ui::Compositor, if it is known | |
46 // that this will not be recycled again. | |
47 - (void)destroyCompositor; | |
48 | |
49 // Access the underlying ui::Compositor for this view. | |
50 - (ui::Compositor*)compositor; | |
51 | |
52 // Called when the accelerated or software layer draws its frame to the screen. | |
53 - (void)layerDidDrawFrame; | |
54 | |
55 // Called when an error is encountered while drawing to the screen. | |
56 - (void)gotAcceleratedLayerError; | |
57 | |
58 @end // BrowserCompositorViewCocoa | |
59 | |
60 namespace content { | |
61 | |
62 // This class implements the parts of BrowserCompositorViewCocoa that need to | |
63 // be a C++ class and not an Objective C class. | |
64 class BrowserCompositorViewCocoaHelper | |
65 : public content::CompositingIOSurfaceLayerClient { | |
66 public: | |
67 BrowserCompositorViewCocoaHelper(BrowserCompositorViewCocoa* view) | |
68 : view_(view) {} | |
69 virtual ~BrowserCompositorViewCocoaHelper() {} | |
70 | |
71 private: | |
72 // CompositingIOSurfaceLayerClient implementation: | |
73 virtual void AcceleratedLayerDidDrawFrame(bool succeeded) OVERRIDE; | |
74 | |
75 BrowserCompositorViewCocoa* view_; | |
76 }; | 88 }; |
77 | 89 |
78 } // namespace content | 90 } // namespace content |
79 | 91 |
| 92 // BrowserCompositorViewCocoa is the actual NSView to which the layers drawn |
| 93 // by the ui::Compositor are attached. |
| 94 @interface BrowserCompositorViewCocoa : NSView { |
| 95 content::BrowserCompositorViewCocoaClient* client_; |
| 96 } |
| 97 |
| 98 - (id)initWithClient:(content::BrowserCompositorViewCocoaClient*)client; |
| 99 |
| 100 // Mark that the client provided at initialization is no longer valid and may |
| 101 // not be called back into. |
| 102 - (void)resetClient; |
| 103 @end |
| 104 |
80 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_PRIVATE_MAC_H_ | 105 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_PRIVATE_MAC_H_ |
OLD | NEW |