| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #ifndef GPU_IPC_SERVICE_CA_LAYER_TREE_MAC_H_ | |
| 6 #define GPU_IPC_SERVICE_CA_LAYER_TREE_MAC_H_ | |
| 7 | |
| 8 #include <IOSurface/IOSurface.h> | |
| 9 #include <QuartzCore/QuartzCore.h> | |
| 10 | |
| 11 #include <deque> | |
| 12 #include <memory> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/mac/scoped_cftyperef.h" | |
| 16 #include "base/mac/scoped_nsobject.h" | |
| 17 #include "gpu/gpu_export.h" | |
| 18 #include "ui/gfx/geometry/rect.h" | |
| 19 #include "ui/gfx/geometry/rect_f.h" | |
| 20 #include "ui/gfx/mac/io_surface.h" | |
| 21 #include "ui/gfx/transform.h" | |
| 22 | |
| 23 @class AVSampleBufferDisplayLayer; | |
| 24 | |
| 25 namespace gpu { | |
| 26 | |
| 27 // The CALayerTree will construct a hierarchy of CALayers from a linear list, | |
| 28 // using the algorithm and structure referenced described in | |
| 29 // https://docs.google.com/document/d/1DtSN9zzvCF44_FQPM7ie01UxGHagQ66zfF5L9Hnig
QY/edit?usp=sharing | |
| 30 class GPU_EXPORT CALayerTree { | |
| 31 public: | |
| 32 CALayerTree(); | |
| 33 | |
| 34 // This will remove all CALayers from this tree from their superlayer. | |
| 35 ~CALayerTree(); | |
| 36 | |
| 37 // Append the description of a new CALayer to the tree. This will not | |
| 38 // create any new CALayers until CommitScheduledCALayers is called. This | |
| 39 // cannot be called anymore after CommitScheduledCALayers has been called. | |
| 40 bool ScheduleCALayer(bool is_clipped, | |
| 41 const gfx::Rect& clip_rect, | |
| 42 unsigned sorting_context_id, | |
| 43 const gfx::Transform& transform, | |
| 44 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 45 const gfx::RectF& contents_rect, | |
| 46 const gfx::Rect& rect, | |
| 47 unsigned background_color, | |
| 48 unsigned edge_aa_mask, | |
| 49 float opacity); | |
| 50 | |
| 51 // Create a CALayer tree for the scheduled layers, and set |superlayer| to | |
| 52 // have only this tree as its sublayers. If |old_tree| is non-null, then try | |
| 53 // to re-use the CALayers of |old_tree| as much as possible. |old_tree| will | |
| 54 // be destroyed at the end of the function, and any CALayers in it which were | |
| 55 // not re-used by |this| will be removed from the CALayer hierarchy. | |
| 56 void CommitScheduledCALayers(CALayer* superlayer, | |
| 57 std::unique_ptr<CALayerTree> old_tree, | |
| 58 float scale_factor); | |
| 59 | |
| 60 private: | |
| 61 struct RootLayer; | |
| 62 struct ClipAndSortingLayer; | |
| 63 struct TransformLayer; | |
| 64 struct ContentLayer; | |
| 65 | |
| 66 struct RootLayer { | |
| 67 RootLayer(); | |
| 68 | |
| 69 // This will remove |ca_layer| from its superlayer, if |ca_layer| is | |
| 70 // non-nil. | |
| 71 ~RootLayer(); | |
| 72 | |
| 73 // Append a new content layer, without modifying the actual CALayer | |
| 74 // structure. | |
| 75 bool AddContentLayer(bool is_clipped, | |
| 76 const gfx::Rect& clip_rect, | |
| 77 unsigned sorting_context_id, | |
| 78 const gfx::Transform& transform, | |
| 79 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 80 const gfx::RectF& contents_rect, | |
| 81 const gfx::Rect& rect, | |
| 82 unsigned background_color, | |
| 83 unsigned edge_aa_mask, | |
| 84 float opacity); | |
| 85 | |
| 86 // Allocate CALayers for this layer and its children, and set their | |
| 87 // properties appropriately. Re-use the CALayers from |old_layer| if | |
| 88 // possible. If re-using a CALayer from |old_layer|, reset its |ca_layer| | |
| 89 // to nil, so that its destructor will not remove an active CALayer. | |
| 90 void CommitToCA(CALayer* superlayer, | |
| 91 RootLayer* old_layer, | |
| 92 float scale_factor); | |
| 93 | |
| 94 std::vector<ClipAndSortingLayer> clip_and_sorting_layers; | |
| 95 base::scoped_nsobject<CALayer> ca_layer; | |
| 96 | |
| 97 private: | |
| 98 DISALLOW_COPY_AND_ASSIGN(RootLayer); | |
| 99 }; | |
| 100 struct ClipAndSortingLayer { | |
| 101 ClipAndSortingLayer(bool is_clipped, | |
| 102 gfx::Rect clip_rect, | |
| 103 unsigned sorting_context_id, | |
| 104 bool is_singleton_sorting_context); | |
| 105 ClipAndSortingLayer(ClipAndSortingLayer&& layer); | |
| 106 | |
| 107 // See the behavior of RootLayer for the effects of these functions on the | |
| 108 // |ca_layer| member and |old_layer| argument. | |
| 109 ~ClipAndSortingLayer(); | |
| 110 void AddContentLayer(const gfx::Transform& transform, | |
| 111 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 112 const gfx::RectF& contents_rect, | |
| 113 const gfx::Rect& rect, | |
| 114 unsigned background_color, | |
| 115 unsigned edge_aa_mask, | |
| 116 float opacity); | |
| 117 void CommitToCA(CALayer* superlayer, | |
| 118 ClipAndSortingLayer* old_layer, | |
| 119 float scale_factor); | |
| 120 | |
| 121 std::vector<TransformLayer> transform_layers; | |
| 122 bool is_clipped = false; | |
| 123 gfx::Rect clip_rect; | |
| 124 unsigned sorting_context_id = 0; | |
| 125 bool is_singleton_sorting_context = false; | |
| 126 base::scoped_nsobject<CALayer> ca_layer; | |
| 127 | |
| 128 private: | |
| 129 DISALLOW_COPY_AND_ASSIGN(ClipAndSortingLayer); | |
| 130 }; | |
| 131 struct TransformLayer { | |
| 132 TransformLayer(const gfx::Transform& transform); | |
| 133 TransformLayer(TransformLayer&& layer); | |
| 134 | |
| 135 // See the behavior of RootLayer for the effects of these functions on the | |
| 136 // |ca_layer| member and |old_layer| argument. | |
| 137 ~TransformLayer(); | |
| 138 void AddContentLayer(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 139 const gfx::RectF& contents_rect, | |
| 140 const gfx::Rect& rect, | |
| 141 unsigned background_color, | |
| 142 unsigned edge_aa_mask, | |
| 143 float opacity); | |
| 144 void CommitToCA(CALayer* superlayer, | |
| 145 TransformLayer* old_layer, | |
| 146 float scale_factor); | |
| 147 | |
| 148 gfx::Transform transform; | |
| 149 std::vector<ContentLayer> content_layers; | |
| 150 base::scoped_nsobject<CALayer> ca_layer; | |
| 151 | |
| 152 private: | |
| 153 DISALLOW_COPY_AND_ASSIGN(TransformLayer); | |
| 154 }; | |
| 155 struct ContentLayer { | |
| 156 ContentLayer(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 157 const gfx::RectF& contents_rect, | |
| 158 const gfx::Rect& rect, | |
| 159 unsigned background_color, | |
| 160 unsigned edge_aa_mask, | |
| 161 float opacity); | |
| 162 ContentLayer(ContentLayer&& layer); | |
| 163 | |
| 164 // See the behavior of RootLayer for the effects of these functions on the | |
| 165 // |ca_layer| member and |old_layer| argument. | |
| 166 ~ContentLayer(); | |
| 167 void CommitToCA(CALayer* parent, | |
| 168 ContentLayer* old_layer, | |
| 169 float scale_factor); | |
| 170 | |
| 171 // Ensure that the IOSurface be marked as in-use as soon as it is received. | |
| 172 // When they are committed to the window server, that will also increment | |
| 173 // their use count. | |
| 174 const gfx::ScopedInUseIOSurface io_surface; | |
| 175 gfx::RectF contents_rect; | |
| 176 gfx::Rect rect; | |
| 177 unsigned background_color = 0; | |
| 178 // Note that the CoreAnimation edge antialiasing mask is not the same as | |
| 179 // the edge antialiasing mask passed to the constructor. | |
| 180 CAEdgeAntialiasingMask ca_edge_aa_mask = 0; | |
| 181 float opacity = 1; | |
| 182 base::scoped_nsobject<CALayer> ca_layer; | |
| 183 | |
| 184 // If this layer's contents can be represented as an | |
| 185 // AVSampleBufferDisplayLayer, then |ca_layer| will point to |av_layer|. | |
| 186 base::scoped_nsobject<AVSampleBufferDisplayLayer> av_layer; | |
| 187 bool use_av_layer = false; | |
| 188 | |
| 189 private: | |
| 190 DISALLOW_COPY_AND_ASSIGN(ContentLayer); | |
| 191 }; | |
| 192 | |
| 193 RootLayer root_layer_; | |
| 194 float scale_factor_ = 1; | |
| 195 bool has_committed_ = false; | |
| 196 | |
| 197 private: | |
| 198 DISALLOW_COPY_AND_ASSIGN(CALayerTree); | |
| 199 }; | |
| 200 | |
| 201 } // namespace gpu | |
| 202 | |
| 203 #endif // GPU_IPC_SERVICE_CA_LAYER_TREE_MAC_H_ | |
| OLD | NEW |