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