| 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_RENDERER_LAYER_TREE_H_ | 5 #ifndef UI_ACCELERATED_WIDGET_MAC_CA_RENDERER_LAYER_TREE_H_ |
| 6 #define UI_ACCELERATED_WIDGET_MAC_CA_RENDERER_LAYER_TREE_H_ | 6 #define UI_ACCELERATED_WIDGET_MAC_CA_RENDERER_LAYER_TREE_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 |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
| 16 #include "base/mac/scoped_nsobject.h" | 16 #include "base/mac/scoped_nsobject.h" |
| 17 #include "base/memory/ref_counted.h" |
| 17 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" | 18 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/rect_f.h" | 20 #include "ui/gfx/geometry/rect_f.h" |
| 20 #include "ui/gfx/mac/io_surface.h" | 21 #include "ui/gfx/mac/io_surface.h" |
| 21 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 22 | 23 |
| 23 @class AVSampleBufferDisplayLayer; | 24 @class AVSampleBufferDisplayLayer; |
| 24 | 25 |
| 25 namespace ui { | 26 namespace ui { |
| 26 | 27 |
| 27 struct CARendererLayerParams; | 28 struct CARendererLayerParams; |
| 28 | 29 |
| 29 // The CARendererLayerTree will construct a hierarchy of CALayers from a linear | 30 // The CARendererLayerTree will construct a hierarchy of CALayers from a linear |
| 30 // list provided by the CoreAnimation renderer using the algorithm and structure | 31 // list provided by the CoreAnimation renderer using the algorithm and structure |
| 31 // referenced described in | 32 // referenced described in |
| 32 // https://docs.google.com/document/d/1DtSN9zzvCF44_FQPM7ie01UxGHagQ66zfF5L9Hnig
QY/edit?usp=sharing | 33 // https://docs.google.com/document/d/1DtSN9zzvCF44_FQPM7ie01UxGHagQ66zfF5L9Hnig
QY/edit?usp=sharing |
| 33 class ACCELERATED_WIDGET_MAC_EXPORT CARendererLayerTree { | 34 class ACCELERATED_WIDGET_MAC_EXPORT CARendererLayerTree { |
| 34 public: | 35 public: |
| 35 CARendererLayerTree(bool allow_av_sample_buffer_display_layer); | 36 CARendererLayerTree(bool allow_av_sample_buffer_display_layer, |
| 37 bool allow_solid_color_layers); |
| 36 | 38 |
| 37 // This will remove all CALayers from this tree from their superlayer. | 39 // This will remove all CALayers from this tree from their superlayer. |
| 38 ~CARendererLayerTree(); | 40 ~CARendererLayerTree(); |
| 39 | 41 |
| 40 // Append the description of a new CALayer to the tree. This will not | 42 // Append the description of a new CALayer to the tree. This will not |
| 41 // create any new CALayers until CommitScheduledCALayers is called. This | 43 // create any new CALayers until CommitScheduledCALayers is called. This |
| 42 // cannot be called anymore after CommitScheduledCALayers has been called. | 44 // cannot be called anymore after CommitScheduledCALayers has been called. |
| 43 bool ScheduleCALayer(const CARendererLayerParams& params); | 45 bool ScheduleCALayer(const CARendererLayerParams& params); |
| 44 | 46 |
| 45 // Create a CALayer tree for the scheduled layers, and set |superlayer| to | 47 // Create a CALayer tree for the scheduled layers, and set |superlayer| to |
| 46 // have only this tree as its sublayers. If |old_tree| is non-null, then try | 48 // have only this tree as its sublayers. If |old_tree| is non-null, then try |
| 47 // to re-use the CALayers of |old_tree| as much as possible. |old_tree| will | 49 // to re-use the CALayers of |old_tree| as much as possible. |old_tree| will |
| 48 // be destroyed at the end of the function, and any CALayers in it which were | 50 // be destroyed at the end of the function, and any CALayers in it which were |
| 49 // not re-used by |this| will be removed from the CALayer hierarchy. | 51 // not re-used by |this| will be removed from the CALayer hierarchy. |
| 50 void CommitScheduledCALayers(CALayer* superlayer, | 52 void CommitScheduledCALayers(CALayer* superlayer, |
| 51 std::unique_ptr<CARendererLayerTree> old_tree, | 53 std::unique_ptr<CARendererLayerTree> old_tree, |
| 52 float scale_factor); | 54 float scale_factor); |
| 53 | 55 |
| 54 // Check to see if the CALayer tree can be represented entirely by a video | 56 // Check to see if the CALayer tree can be represented entirely by a video |
| 55 // layer on a black background. If so, then set |fullscreen_low_power_layer| | 57 // layer on a black background. If so, then set |fullscreen_low_power_layer| |
| 56 // to draw this content and return true. Otherwise return false. This is to | 58 // to draw this content and return true. Otherwise return false. This is to |
| 57 // be called after committing scheduled CALayers. | 59 // be called after committing scheduled CALayers. |
| 58 bool CommitFullscreenLowPowerLayer( | 60 bool CommitFullscreenLowPowerLayer( |
| 59 AVSampleBufferDisplayLayer* fullscreen_low_power_layer); | 61 AVSampleBufferDisplayLayer* fullscreen_low_power_layer); |
| 60 | 62 |
| 63 // Returns the contents used for a given solid color. |
| 64 id ContentsForSolidColorForTesting(unsigned int color); |
| 65 |
| 61 private: | 66 private: |
| 67 class SolidColorContents; |
| 62 struct RootLayer; | 68 struct RootLayer; |
| 63 struct ClipAndSortingLayer; | 69 struct ClipAndSortingLayer; |
| 64 struct TransformLayer; | 70 struct TransformLayer; |
| 65 struct ContentLayer; | 71 struct ContentLayer; |
| 66 friend struct ContentLayer; | 72 friend struct ContentLayer; |
| 67 | 73 |
| 68 struct RootLayer { | 74 struct RootLayer { |
| 69 RootLayer(); | 75 RootLayer(); |
| 70 | 76 |
| 71 // This will remove |ca_layer| from its superlayer, if |ca_layer| is | 77 // This will remove |ca_layer| from its superlayer, if |ca_layer| is |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 ~ContentLayer(); | 160 ~ContentLayer(); |
| 155 void CommitToCA(CALayer* parent, | 161 void CommitToCA(CALayer* parent, |
| 156 ContentLayer* old_layer, | 162 ContentLayer* old_layer, |
| 157 float scale_factor); | 163 float scale_factor); |
| 158 | 164 |
| 159 // Ensure that the IOSurface be marked as in-use as soon as it is received. | 165 // Ensure that the IOSurface be marked as in-use as soon as it is received. |
| 160 // When they are committed to the window server, that will also increment | 166 // When they are committed to the window server, that will also increment |
| 161 // their use count. | 167 // their use count. |
| 162 const gfx::ScopedInUseIOSurface io_surface; | 168 const gfx::ScopedInUseIOSurface io_surface; |
| 163 const base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; | 169 const base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; |
| 170 scoped_refptr<SolidColorContents> solid_color_contents; |
| 164 gfx::RectF contents_rect; | 171 gfx::RectF contents_rect; |
| 165 gfx::Rect rect; | 172 gfx::Rect rect; |
| 166 unsigned background_color = 0; | 173 unsigned background_color = 0; |
| 167 // Note that the CoreAnimation edge antialiasing mask is not the same as | 174 // Note that the CoreAnimation edge antialiasing mask is not the same as |
| 168 // the edge antialiasing mask passed to the constructor. | 175 // the edge antialiasing mask passed to the constructor. |
| 169 CAEdgeAntialiasingMask ca_edge_aa_mask = 0; | 176 CAEdgeAntialiasingMask ca_edge_aa_mask = 0; |
| 170 float opacity = 1; | 177 float opacity = 1; |
| 171 NSString* const ca_filter = nil; | 178 NSString* const ca_filter = nil; |
| 172 base::scoped_nsobject<CALayer> ca_layer; | 179 base::scoped_nsobject<CALayer> ca_layer; |
| 173 | 180 |
| 174 // If this layer's contents can be represented as an | 181 // If this layer's contents can be represented as an |
| 175 // AVSampleBufferDisplayLayer, then |ca_layer| will point to |av_layer|. | 182 // AVSampleBufferDisplayLayer, then |ca_layer| will point to |av_layer|. |
| 176 base::scoped_nsobject<AVSampleBufferDisplayLayer> av_layer; | 183 base::scoped_nsobject<AVSampleBufferDisplayLayer> av_layer; |
| 177 bool use_av_layer = false; | 184 bool use_av_layer = false; |
| 178 | 185 |
| 179 private: | 186 private: |
| 180 DISALLOW_COPY_AND_ASSIGN(ContentLayer); | 187 DISALLOW_COPY_AND_ASSIGN(ContentLayer); |
| 181 }; | 188 }; |
| 182 | 189 |
| 183 RootLayer root_layer_; | 190 RootLayer root_layer_; |
| 184 float scale_factor_ = 1; | 191 float scale_factor_ = 1; |
| 185 bool has_committed_ = false; | 192 bool has_committed_ = false; |
| 186 const bool allow_av_sample_buffer_display_layer_ = true; | 193 const bool allow_av_sample_buffer_display_layer_ = true; |
| 194 const bool allow_solid_color_layers_ = true; |
| 187 | 195 |
| 188 private: | 196 private: |
| 189 DISALLOW_COPY_AND_ASSIGN(CARendererLayerTree); | 197 DISALLOW_COPY_AND_ASSIGN(CARendererLayerTree); |
| 190 }; | 198 }; |
| 191 | 199 |
| 192 } // namespace ui | 200 } // namespace ui |
| 193 | 201 |
| 194 #endif // UI_ACCELERATED_WIDGET_MAC_CA_LAYER_TREE_MAC_H_ | 202 #endif // UI_ACCELERATED_WIDGET_MAC_CA_LAYER_TREE_MAC_H_ |
| OLD | NEW |