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 3 // found in the LICENSE file. 4 5 #ifndef CC_RESOURCES_PICTURE_PILE_IMPL_H_ 6 #define CC_RESOURCES_PICTURE_PILE_IMPL_H_ 7 8 #include <list> 9 #include <map> 10 #include <set> 11 #include <vector> 12 13 #include "base/time/time.h" 14 #include "cc/base/cc_export.h" 15 #include "cc/debug/rendering_stats_instrumentation.h" 16 #include "cc/resources/picture_pile_base.h" 17 #include "skia/ext/analysis_canvas.h" 18 #include "skia/ext/refptr.h" 19 #include "third_party/skia/include/core/SkPicture.h" 20 21 namespace cc { 22 23 class CC_EXPORT PicturePileImpl : public PicturePileBase { 24 public: 25 static scoped_refptr<PicturePileImpl> Create(); 26 static scoped_refptr<PicturePileImpl> CreateFromOther( 27 const PicturePileBase* other); 28 29 // Raster a subrect of this PicturePileImpl into the given canvas. It is 30 // assumed that contents_scale has already been applied to this canvas. 31 // Writes the total number of pixels rasterized and the time spent 32 // rasterizing to the stats if the respective pointer is not NULL. When 33 // slow-down-raster-scale-factor is set to a value greater than 1, the 34 // reported rasterize time is the minimum measured value over all runs. 35 void RasterDirect( 36 SkCanvas* canvas, 37 const gfx::Rect& canvas_rect, 38 float contents_scale, 39 RenderingStatsInstrumentation* rendering_stats_instrumentation); 40 41 // Similar to the above RasterDirect method, but this is a convenience method 42 // for when it is known that the raster is going to an intermediate bitmap 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(); 60 61 struct CC_EXPORT Analysis { 62 Analysis(); 63 ~Analysis(); 64 65 bool is_solid_color; 66 SkColor solid_color; 67 }; 68 69 void AnalyzeInRect(const gfx::Rect& content_rect, 70 float contents_scale, 71 Analysis* analysis) const; 72 73 void AnalyzeInRect( 74 const gfx::Rect& content_rect, 75 float contents_scale, 76 Analysis* analysis, 77 RenderingStatsInstrumentation* stats_instrumentation) const; 78 79 class CC_EXPORT PixelRefIterator { 80 public: 81 PixelRefIterator(const gfx::Rect& content_rect, 82 float contents_scale, 83 const PicturePileImpl* picture_pile); 84 ~PixelRefIterator(); 85 86 SkPixelRef* operator->() const { return *pixel_ref_iterator_; } 87 SkPixelRef* operator*() const { return *pixel_ref_iterator_; } 88 PixelRefIterator& operator++(); 89 operator bool() const { return pixel_ref_iterator_; } 90 91 private: 92 void AdvanceToTilePictureWithPixelRefs(); 93 94 const PicturePileImpl* picture_pile_; 95 gfx::Rect layer_rect_; 96 TilingData::Iterator tile_iterator_; 97 Picture::PixelRefIterator pixel_ref_iterator_; 98 std::set<const void*> processed_pictures_; 99 }; 100 101 void DidBeginTracing(); 102 103 protected: 104 friend class PicturePile; 105 friend class PixelRefIterator; 106 107 PicturePileImpl(); 108 explicit PicturePileImpl(const PicturePileBase* other); 109 virtual ~PicturePileImpl(); 110 111 private: 112 typedef std::map<const Picture*, Region> PictureRegionMap; 113 114 void CoalesceRasters(const gfx::Rect& canvas_rect, 115 const gfx::Rect& content_rect, 116 float contents_scale, 117 PictureRegionMap* result) const; 118 119 void RasterCommon( 120 SkCanvas* canvas, 121 SkDrawPictureCallback* callback, 122 const gfx::Rect& canvas_rect, 123 float contents_scale, 124 RenderingStatsInstrumentation* rendering_stats_instrumentation, 125 bool is_analysis) const; 126 127 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl); 128 }; 129 130 } // namespace cc 131 132 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_ 133