| 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 UI_ACCELERATED_WIDGET_MAC_CA_LAYER_TREE_MAC_H_ | |
| 6 #define UI_ACCELERATED_WIDGET_MAC_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 "ui/accelerated_widget_mac/accelerated_widget_mac_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 ui { | |
| 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 ACCELERATED_WIDGET_MAC_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 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | |
| 46 const gfx::RectF& contents_rect, | |
| 47 const gfx::Rect& rect, | |
| 48 unsigned background_color, | |
| 49 unsigned edge_aa_mask, | |
| 50 float opacity); | |
| 51 | |
| 52 // Create a CALayer tree for the scheduled layers, and set |superlayer| to | |
| 53 // have only this tree as its sublayers. If |old_tree| is non-null, then try | |
| 54 // to re-use the CALayers of |old_tree| as much as possible. |old_tree| will | |
| 55 // be destroyed at the end of the function, and any CALayers in it which were | |
| 56 // not re-used by |this| will be removed from the CALayer hierarchy. | |
| 57 void CommitScheduledCALayers(CALayer* superlayer, | |
| 58 std::unique_ptr<CALayerTree> old_tree, | |
| 59 float scale_factor); | |
| 60 | |
| 61 private: | |
| 62 struct RootLayer; | |
| 63 struct ClipAndSortingLayer; | |
| 64 struct TransformLayer; | |
| 65 struct ContentLayer; | |
| 66 | |
| 67 struct RootLayer { | |
| 68 RootLayer(); | |
| 69 | |
| 70 // This will remove |ca_layer| from its superlayer, if |ca_layer| is | |
| 71 // non-nil. | |
| 72 ~RootLayer(); | |
| 73 | |
| 74 // Append a new content layer, without modifying the actual CALayer | |
| 75 // structure. | |
| 76 bool AddContentLayer( | |
| 77 bool is_clipped, | |
| 78 const gfx::Rect& clip_rect, | |
| 79 unsigned sorting_context_id, | |
| 80 const gfx::Transform& transform, | |
| 81 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 82 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | |
| 83 const gfx::RectF& contents_rect, | |
| 84 const gfx::Rect& rect, | |
| 85 unsigned background_color, | |
| 86 unsigned edge_aa_mask, | |
| 87 float opacity); | |
| 88 | |
| 89 // Allocate CALayers for this layer and its children, and set their | |
| 90 // properties appropriately. Re-use the CALayers from |old_layer| if | |
| 91 // possible. If re-using a CALayer from |old_layer|, reset its |ca_layer| | |
| 92 // to nil, so that its destructor will not remove an active CALayer. | |
| 93 void CommitToCA(CALayer* superlayer, | |
| 94 RootLayer* old_layer, | |
| 95 float scale_factor); | |
| 96 | |
| 97 std::vector<ClipAndSortingLayer> clip_and_sorting_layers; | |
| 98 base::scoped_nsobject<CALayer> ca_layer; | |
| 99 | |
| 100 private: | |
| 101 DISALLOW_COPY_AND_ASSIGN(RootLayer); | |
| 102 }; | |
| 103 struct ClipAndSortingLayer { | |
| 104 ClipAndSortingLayer(bool is_clipped, | |
| 105 gfx::Rect clip_rect, | |
| 106 unsigned sorting_context_id, | |
| 107 bool is_singleton_sorting_context); | |
| 108 ClipAndSortingLayer(ClipAndSortingLayer&& layer); | |
| 109 | |
| 110 // See the behavior of RootLayer for the effects of these functions on the | |
| 111 // |ca_layer| member and |old_layer| argument. | |
| 112 ~ClipAndSortingLayer(); | |
| 113 void AddContentLayer( | |
| 114 const gfx::Transform& transform, | |
| 115 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 116 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | |
| 117 const gfx::RectF& contents_rect, | |
| 118 const gfx::Rect& rect, | |
| 119 unsigned background_color, | |
| 120 unsigned edge_aa_mask, | |
| 121 float opacity); | |
| 122 void CommitToCA(CALayer* superlayer, | |
| 123 ClipAndSortingLayer* old_layer, | |
| 124 float scale_factor); | |
| 125 | |
| 126 std::vector<TransformLayer> transform_layers; | |
| 127 bool is_clipped = false; | |
| 128 gfx::Rect clip_rect; | |
| 129 unsigned sorting_context_id = 0; | |
| 130 bool is_singleton_sorting_context = false; | |
| 131 base::scoped_nsobject<CALayer> ca_layer; | |
| 132 | |
| 133 private: | |
| 134 DISALLOW_COPY_AND_ASSIGN(ClipAndSortingLayer); | |
| 135 }; | |
| 136 struct TransformLayer { | |
| 137 TransformLayer(const gfx::Transform& transform); | |
| 138 TransformLayer(TransformLayer&& layer); | |
| 139 | |
| 140 // See the behavior of RootLayer for the effects of these functions on the | |
| 141 // |ca_layer| member and |old_layer| argument. | |
| 142 ~TransformLayer(); | |
| 143 void AddContentLayer( | |
| 144 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 145 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | |
| 146 const gfx::RectF& contents_rect, | |
| 147 const gfx::Rect& rect, | |
| 148 unsigned background_color, | |
| 149 unsigned edge_aa_mask, | |
| 150 float opacity); | |
| 151 void CommitToCA(CALayer* superlayer, | |
| 152 TransformLayer* old_layer, | |
| 153 float scale_factor); | |
| 154 | |
| 155 gfx::Transform transform; | |
| 156 std::vector<ContentLayer> content_layers; | |
| 157 base::scoped_nsobject<CALayer> ca_layer; | |
| 158 | |
| 159 private: | |
| 160 DISALLOW_COPY_AND_ASSIGN(TransformLayer); | |
| 161 }; | |
| 162 struct ContentLayer { | |
| 163 ContentLayer(base::ScopedCFTypeRef<IOSurfaceRef> io_surface, | |
| 164 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer, | |
| 165 const gfx::RectF& contents_rect, | |
| 166 const gfx::Rect& rect, | |
| 167 unsigned background_color, | |
| 168 unsigned edge_aa_mask, | |
| 169 float opacity); | |
| 170 ContentLayer(ContentLayer&& layer); | |
| 171 | |
| 172 // See the behavior of RootLayer for the effects of these functions on the | |
| 173 // |ca_layer| member and |old_layer| argument. | |
| 174 ~ContentLayer(); | |
| 175 void CommitToCA(CALayer* parent, | |
| 176 ContentLayer* old_layer, | |
| 177 float scale_factor); | |
| 178 | |
| 179 // Ensure that the IOSurface be marked as in-use as soon as it is received. | |
| 180 // When they are committed to the window server, that will also increment | |
| 181 // their use count. | |
| 182 const gfx::ScopedInUseIOSurface io_surface; | |
| 183 const base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; | |
| 184 gfx::RectF contents_rect; | |
| 185 gfx::Rect rect; | |
| 186 unsigned background_color = 0; | |
| 187 // Note that the CoreAnimation edge antialiasing mask is not the same as | |
| 188 // the edge antialiasing mask passed to the constructor. | |
| 189 CAEdgeAntialiasingMask ca_edge_aa_mask = 0; | |
| 190 float opacity = 1; | |
| 191 base::scoped_nsobject<CALayer> ca_layer; | |
| 192 | |
| 193 // If this layer's contents can be represented as an | |
| 194 // AVSampleBufferDisplayLayer, then |ca_layer| will point to |av_layer|. | |
| 195 base::scoped_nsobject<AVSampleBufferDisplayLayer> av_layer; | |
| 196 bool use_av_layer = false; | |
| 197 | |
| 198 private: | |
| 199 DISALLOW_COPY_AND_ASSIGN(ContentLayer); | |
| 200 }; | |
| 201 | |
| 202 RootLayer root_layer_; | |
| 203 float scale_factor_ = 1; | |
| 204 bool has_committed_ = false; | |
| 205 | |
| 206 private: | |
| 207 DISALLOW_COPY_AND_ASSIGN(CALayerTree); | |
| 208 }; | |
| 209 | |
| 210 } // namespace ui | |
| 211 | |
| 212 #endif // UI_ACCELERATED_WIDGET_MAC_CA_LAYER_TREE_MAC_H_ | |
| OLD | NEW |