Chromecast: extracts Linux window creation code to a common place.
[chromium-blink-merge.git] / content / browser / compositor / browser_compositor_ca_layer_tree_mac.h
blobf59d865e2e393b958c038d4add54c5bf2c083e1b
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_CA_LAYER_TREE_MAC_H_
6 #define CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_CA_LAYER_TREE_MAC_H_
8 #include <IOSurface/IOSurfaceAPI.h>
10 #include "content/browser/compositor/browser_compositor_view_mac.h"
12 #if defined(__OBJC__)
13 #include <Cocoa/Cocoa.h>
14 #include "base/mac/scoped_nsobject.h"
15 #include "content/browser/compositor/io_surface_layer_mac.h"
16 #include "content/browser/compositor/software_layer_mac.h"
17 #include "ui/base/cocoa/remote_layer_api.h"
18 #endif // __OBJC__
20 namespace content {
22 #if defined(__OBJC__)
24 // BrowserCompositorCALayerTreeMac owns tree of CALayer and a ui::Compositor
25 // that is used to draw the layers. The CALayer tree can be attached to the
26 // NSView of a BrowserCompositorViewMac
27 class BrowserCompositorCALayerTreeMac
28 : public IOSurfaceLayerClient {
29 public:
30 BrowserCompositorCALayerTreeMac();
31 virtual ~BrowserCompositorCALayerTreeMac();
32 static BrowserCompositorCALayerTreeMac* FromAcceleratedWidget(
33 gfx::AcceleratedWidget widget);
35 void SetView(BrowserCompositorViewMac* view);
36 void ResetView();
38 ui::Compositor* compositor() const { return compositor_.get(); }
40 // Return true if the last frame swapped has a size in DIP of |dip_size|.
41 bool HasFrameOfSize(const gfx::Size& dip_size) const;
43 // Return the CGL renderer ID for the surface, if one is available.
44 int GetRendererID() const;
46 // Return true if the renderer should not be throttled by GPU back-pressure.
47 bool IsRendererThrottlingDisabled() const;
49 // Mark a bracket in which new frames are being pumped in a restricted nested
50 // run loop.
51 void BeginPumpingFrames();
52 void EndPumpingFrames();
54 void GotAcceleratedFrame(
55 uint64 surface_handle, int output_surface_id,
56 const std::vector<ui::LatencyInfo>& latency_info,
57 gfx::Size pixel_size, float scale_factor);
59 void GotSoftwareFrame(
60 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas);
62 private:
63 // IOSurfaceLayerClient implementation:
64 virtual bool IOSurfaceLayerShouldAckImmediately() const override;
65 virtual void IOSurfaceLayerDidDrawFrame() override;
66 virtual void IOSurfaceLayerHitError() override;
68 void GotAcceleratedCAContextFrame(
69 CAContextID ca_context_id, gfx::Size pixel_size, float scale_factor);
71 void GotAcceleratedIOSurfaceFrame(
72 IOSurfaceID io_surface_id, gfx::Size pixel_size, float scale_factor);
74 // Remove a layer from the heirarchy and destroy it. Because the accelerated
75 // layer types may be replaced by a layer of the same type, the layer to
76 // destroy is parameterized, and, if it is the current layer, the current
77 // layer is reset.
78 void DestroyCAContextLayer(
79 base::scoped_nsobject<CALayerHost> ca_context_layer);
80 void DestroyIOSurfaceLayer(
81 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer);
82 void DestroySoftwareLayer();
84 // The BrowserCompositorViewMac that is using this as its internals.
85 BrowserCompositorViewMac* view_;
87 // A phony NSView handle used to identify this.
88 gfx::AcceleratedWidget native_widget_;
90 // The compositor drawing the contents of this view.
91 scoped_ptr<ui::Compositor> compositor_;
93 // A flipped layer, which acts as the parent of the compositing and software
94 // layers. This layer is flipped so that the we don't need to recompute the
95 // origin for sub-layers when their position changes (this is impossible when
96 // using remote layers, as their size change cannot be synchronized with the
97 // window). This indirection is needed because flipping hosted layers (like
98 // |background_layer_| of RenderWidgetHostViewCocoa) leads to unpredictable
99 // behavior.
100 base::scoped_nsobject<CALayer> flipped_layer_;
102 // The accelerated CoreAnimation layer hosted by the GPU process.
103 base::scoped_nsobject<CALayerHost> ca_context_layer_;
105 // The locally drawn accelerated CoreAnimation layer.
106 base::scoped_nsobject<IOSurfaceLayer> io_surface_layer_;
108 // The locally drawn software layer.
109 base::scoped_nsobject<SoftwareLayer> software_layer_;
111 // The output surface and latency info of the last accelerated surface that
112 // was swapped. Sent back to the renderer when the accelerated surface is
113 // drawn.
114 int accelerated_output_surface_id_;
115 std::vector<ui::LatencyInfo> accelerated_latency_info_;
117 // The size in DIP of the last swap received from |compositor_|.
118 gfx::Size last_swap_size_dip_;
121 #endif // __OBJC__
123 void BrowserCompositorCALayerTreeMacGotAcceleratedFrame(
124 gfx::AcceleratedWidget widget,
125 uint64 surface_handle, int surface_id,
126 const std::vector<ui::LatencyInfo>& latency_info,
127 gfx::Size pixel_size, float scale_factor,
128 bool* disable_throttling, int* renderer_id);
130 void BrowserCompositorCALayerTreeMacGotSoftwareFrame(
131 gfx::AcceleratedWidget widget,
132 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas);
134 } // namespace content
136 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_CA_LAYER_TREE_MAC_H_