| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 CC_RESOURCES_PICTURE_PILE_IMPL_H_ | 5 #ifndef CC_RESOURCES_PICTURE_PILE_IMPL_H_ |
| 6 #define CC_RESOURCES_PICTURE_PILE_IMPL_H_ | 6 #define CC_RESOURCES_PICTURE_PILE_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
| 15 #include "cc/debug/rendering_stats_instrumentation.h" | 15 #include "cc/debug/rendering_stats_instrumentation.h" |
| 16 #include "cc/resources/picture_pile_base.h" | 16 #include "cc/resources/picture_pile_base.h" |
| 17 #include "cc/resources/raster_source.h" |
| 17 #include "skia/ext/analysis_canvas.h" | 18 #include "skia/ext/analysis_canvas.h" |
| 18 #include "skia/ext/refptr.h" | 19 #include "skia/ext/refptr.h" |
| 19 #include "third_party/skia/include/core/SkPicture.h" | 20 #include "third_party/skia/include/core/SkPicture.h" |
| 20 | 21 |
| 21 namespace cc { | 22 namespace cc { |
| 22 | 23 |
| 23 class CC_EXPORT PicturePileImpl : public PicturePileBase { | 24 // TODO(vmpstr): Clean up PicturePileBase and make it a member. |
| 25 class CC_EXPORT PicturePileImpl : public PicturePileBase, public RasterSource { |
| 24 public: | 26 public: |
| 25 static scoped_refptr<PicturePileImpl> Create(); | 27 static scoped_refptr<PicturePileImpl> Create(); |
| 26 static scoped_refptr<PicturePileImpl> CreateFromOther( | 28 static scoped_refptr<PicturePileImpl> CreateFromOther( |
| 27 const PicturePileBase* other); | 29 const PicturePileBase* other); |
| 28 | 30 |
| 29 // Raster a subrect of this PicturePileImpl into the given canvas. It is | 31 // RasterSource overrides. See RasterSource header for full description. |
| 30 // assumed that contents_scale has already been applied to this canvas. | 32 // When slow-down-raster-scale-factor is set to a value greater than 1, the |
| 31 // Writes the total number of pixels rasterized and the time spent | 33 // reported rasterize time (in stats_instrumentation) is the minimum measured |
| 32 // rasterizing to the stats if the respective pointer is not NULL. When | 34 // value over all runs. |
| 33 // slow-down-raster-scale-factor is set to a value greater than 1, the | 35 void PlaybackToCanvas( |
| 34 // reported rasterize time is the minimum measured value over all runs. | 36 SkCanvas* canvas, |
| 37 const gfx::Rect& canvas_rect, |
| 38 float contents_scale, |
| 39 RenderingStatsInstrumentation* stats_instrumentation) const override; |
| 40 void AnalyzeInRect( |
| 41 const gfx::Rect& content_rect, |
| 42 float contents_scale, |
| 43 RasterSource::SolidColorAnalysis* analysis, |
| 44 RenderingStatsInstrumentation* stats_instrumentation) const override; |
| 45 void GatherPixelRefs(const gfx::Rect& content_rect, |
| 46 float contents_scale, |
| 47 std::vector<SkPixelRef*>* pixel_refs) const override; |
| 48 bool CoversRect(const gfx::Rect& content_rect, |
| 49 float contents_scale) const override; |
| 50 bool SuitableForDistanceFieldText() const override; |
| 51 |
| 52 // Raster into the canvas without applying clips. |
| 35 void RasterDirect( | 53 void RasterDirect( |
| 36 SkCanvas* canvas, | 54 SkCanvas* canvas, |
| 37 const gfx::Rect& canvas_rect, | 55 const gfx::Rect& canvas_rect, |
| 38 float contents_scale, | 56 float contents_scale, |
| 39 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 57 RenderingStatsInstrumentation* rendering_stats_instrumentation) const; |
| 40 | 58 |
| 41 // Similar to the above RasterDirect method, but this is a convenience method | 59 // Tracing functionality. |
| 42 // for when it is known that the raster is going to an intermediate bitmap | 60 void DidBeginTracing(); |
| 43 // that itself will then be blended and thus that a canvas clear is required. | |
| 44 // Note that this function may write outside the canvas_rect. | |
| 45 void RasterToBitmap( | |
| 46 SkCanvas* canvas, | |
| 47 const gfx::Rect& canvas_rect, | |
| 48 float contents_scale, | |
| 49 RenderingStatsInstrumentation* stats_instrumentation) const; | |
| 50 | |
| 51 // Called when analyzing a tile. We can use AnalysisCanvas as | |
| 52 // SkDrawPictureCallback, which allows us to early out from analysis. | |
| 53 void RasterForAnalysis( | |
| 54 skia::AnalysisCanvas* canvas, | |
| 55 const gfx::Rect& canvas_rect, | |
| 56 float contents_scale, | |
| 57 RenderingStatsInstrumentation* stats_instrumentation) const; | |
| 58 | |
| 59 skia::RefPtr<SkPicture> GetFlattenedPicture(); | 61 skia::RefPtr<SkPicture> GetFlattenedPicture(); |
| 60 | 62 |
| 61 bool likely_to_be_used_for_transform_animation() const { | |
| 62 return likely_to_be_used_for_transform_animation_; | |
| 63 } | |
| 64 void set_likely_to_be_used_for_transform_animation() { | 63 void set_likely_to_be_used_for_transform_animation() { |
| 65 likely_to_be_used_for_transform_animation_ = true; | 64 likely_to_be_used_for_transform_animation_ = true; |
| 66 } | 65 } |
| 67 | 66 |
| 68 struct CC_EXPORT Analysis { | 67 // Iterator used to return SkPixelRefs from this picture pile. |
| 69 Analysis(); | 68 // Public for testing. |
| 70 ~Analysis(); | |
| 71 | |
| 72 bool is_solid_color; | |
| 73 SkColor solid_color; | |
| 74 }; | |
| 75 | |
| 76 void AnalyzeInRect(const gfx::Rect& content_rect, | |
| 77 float contents_scale, | |
| 78 Analysis* analysis) const; | |
| 79 | |
| 80 void AnalyzeInRect( | |
| 81 const gfx::Rect& content_rect, | |
| 82 float contents_scale, | |
| 83 Analysis* analysis, | |
| 84 RenderingStatsInstrumentation* stats_instrumentation) const; | |
| 85 | |
| 86 class CC_EXPORT PixelRefIterator { | 69 class CC_EXPORT PixelRefIterator { |
| 87 public: | 70 public: |
| 88 PixelRefIterator(const gfx::Rect& content_rect, | 71 PixelRefIterator(const gfx::Rect& content_rect, |
| 89 float contents_scale, | 72 float contents_scale, |
| 90 const PicturePileImpl* picture_pile); | 73 const PicturePileImpl* picture_pile); |
| 91 ~PixelRefIterator(); | 74 ~PixelRefIterator(); |
| 92 | 75 |
| 93 SkPixelRef* operator->() const { return *pixel_ref_iterator_; } | 76 SkPixelRef* operator->() const { return *pixel_ref_iterator_; } |
| 94 SkPixelRef* operator*() const { return *pixel_ref_iterator_; } | 77 SkPixelRef* operator*() const { return *pixel_ref_iterator_; } |
| 95 PixelRefIterator& operator++(); | 78 PixelRefIterator& operator++(); |
| 96 operator bool() const { return pixel_ref_iterator_; } | 79 operator bool() const { return pixel_ref_iterator_; } |
| 97 | 80 |
| 98 private: | 81 private: |
| 99 void AdvanceToTilePictureWithPixelRefs(); | 82 void AdvanceToTilePictureWithPixelRefs(); |
| 100 | 83 |
| 101 const PicturePileImpl* picture_pile_; | 84 const PicturePileImpl* picture_pile_; |
| 102 gfx::Rect layer_rect_; | 85 gfx::Rect layer_rect_; |
| 103 TilingData::Iterator tile_iterator_; | 86 TilingData::Iterator tile_iterator_; |
| 104 Picture::PixelRefIterator pixel_ref_iterator_; | 87 Picture::PixelRefIterator pixel_ref_iterator_; |
| 105 std::set<const void*> processed_pictures_; | 88 std::set<const void*> processed_pictures_; |
| 106 }; | 89 }; |
| 107 | 90 |
| 108 void DidBeginTracing(); | |
| 109 | |
| 110 protected: | 91 protected: |
| 111 friend class PicturePile; | 92 friend class PicturePile; |
| 112 friend class PixelRefIterator; | 93 friend class PixelRefIterator; |
| 113 | 94 |
| 114 PicturePileImpl(); | 95 PicturePileImpl(); |
| 115 explicit PicturePileImpl(const PicturePileBase* other); | 96 explicit PicturePileImpl(const PicturePileBase* other); |
| 116 ~PicturePileImpl() override; | 97 ~PicturePileImpl() override; |
| 117 | 98 |
| 118 private: | 99 private: |
| 119 typedef std::map<const Picture*, Region> PictureRegionMap; | 100 typedef std::map<const Picture*, Region> PictureRegionMap; |
| 120 | 101 |
| 102 // Called when analyzing a tile. We can use AnalysisCanvas as |
| 103 // SkDrawPictureCallback, which allows us to early out from analysis. |
| 104 void RasterForAnalysis( |
| 105 skia::AnalysisCanvas* canvas, |
| 106 const gfx::Rect& canvas_rect, |
| 107 float contents_scale, |
| 108 RenderingStatsInstrumentation* stats_instrumentation) const; |
| 109 |
| 121 void CoalesceRasters(const gfx::Rect& canvas_rect, | 110 void CoalesceRasters(const gfx::Rect& canvas_rect, |
| 122 const gfx::Rect& content_rect, | 111 const gfx::Rect& content_rect, |
| 123 float contents_scale, | 112 float contents_scale, |
| 124 PictureRegionMap* result) const; | 113 PictureRegionMap* result) const; |
| 125 | 114 |
| 126 void RasterCommon( | 115 void RasterCommon( |
| 127 SkCanvas* canvas, | 116 SkCanvas* canvas, |
| 128 SkDrawPictureCallback* callback, | 117 SkDrawPictureCallback* callback, |
| 129 const gfx::Rect& canvas_rect, | 118 const gfx::Rect& canvas_rect, |
| 130 float contents_scale, | 119 float contents_scale, |
| 131 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 120 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 132 bool is_analysis) const; | 121 bool is_analysis) const; |
| 133 | 122 |
| 134 bool likely_to_be_used_for_transform_animation_; | 123 bool likely_to_be_used_for_transform_animation_; |
| 135 | 124 |
| 136 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl); | 125 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl); |
| 137 }; | 126 }; |
| 138 | 127 |
| 139 } // namespace cc | 128 } // namespace cc |
| 140 | 129 |
| 141 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_ | 130 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_ |
| OLD | NEW |