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.
5 #ifndef CC_RESOURCES_PICTURE_PILE_IMPL_H_
6 #define CC_RESOURCES_PICTURE_PILE_IMPL_H_
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"
23 class CC_EXPORT PicturePileImpl
: public PicturePileBase
{
25 static scoped_refptr
<PicturePileImpl
> Create();
26 static scoped_refptr
<PicturePileImpl
> CreateFromOther(
27 const PicturePileBase
* other
);
29 // Get paint-safe version of this picture for a specific thread.
30 PicturePileImpl
* GetCloneForDrawingOnThread(unsigned thread_index
) const;
32 // Raster a subrect of this PicturePileImpl into the given canvas.
33 // It's only safe to call paint on a cloned version. It is assumed
34 // that contents_scale has already been applied to this canvas.
35 // Writes the total number of pixels rasterized and the time spent
36 // rasterizing to the stats if the respective pointer is not
37 // NULL. When slow-down-raster-scale-factor is set to a value
38 // greater than 1, the reported rasterize time is the minimum
39 // measured value over all runs.
42 const gfx::Rect
& canvas_rect
,
44 RenderingStatsInstrumentation
* rendering_stats_instrumentation
);
46 // Similar to the above RasterDirect method, but this is a convenience method
47 // for when it is known that the raster is going to an intermediate bitmap
48 // that itself will then be blended and thus that a canvas clear is required.
51 const gfx::Rect
& canvas_rect
,
53 RenderingStatsInstrumentation
* stats_instrumentation
);
55 // Called when analyzing a tile. We can use AnalysisCanvas as
56 // SkDrawPictureCallback, which allows us to early out from analysis.
57 void RasterForAnalysis(
58 skia::AnalysisCanvas
* canvas
,
59 const gfx::Rect
& canvas_rect
,
61 RenderingStatsInstrumentation
* stats_instrumentation
);
63 skia::RefPtr
<SkPicture
> GetFlattenedPicture();
65 struct CC_EXPORT Analysis
{
74 void AnalyzeInRect(const gfx::Rect
& content_rect
,
78 void AnalyzeInRect(const gfx::Rect
& content_rect
,
81 RenderingStatsInstrumentation
* stats_instrumentation
);
83 class CC_EXPORT PixelRefIterator
{
85 PixelRefIterator(const gfx::Rect
& content_rect
,
87 const PicturePileImpl
* picture_pile
);
90 SkPixelRef
* operator->() const { return *pixel_ref_iterator_
; }
91 SkPixelRef
* operator*() const { return *pixel_ref_iterator_
; }
92 PixelRefIterator
& operator++();
93 operator bool() const { return pixel_ref_iterator_
; }
96 void AdvanceToTilePictureWithPixelRefs();
98 const PicturePileImpl
* picture_pile_
;
99 gfx::Rect layer_rect_
;
100 TilingData::Iterator tile_iterator_
;
101 Picture::PixelRefIterator pixel_ref_iterator_
;
102 std::set
<const void*> processed_pictures_
;
105 void DidBeginTracing();
108 friend class PicturePile
;
109 friend class PixelRefIterator
;
112 explicit PicturePileImpl(const PicturePileBase
* other
);
113 virtual ~PicturePileImpl();
116 class ClonesForDrawing
{
118 ClonesForDrawing(const PicturePileImpl
* pile
, int num_threads
);
121 typedef std::vector
<scoped_refptr
<PicturePileImpl
> > PicturePileVector
;
122 PicturePileVector clones_
;
125 static scoped_refptr
<PicturePileImpl
> CreateCloneForDrawing(
126 const PicturePileImpl
* other
, unsigned thread_index
);
128 PicturePileImpl(const PicturePileImpl
* other
, unsigned thread_index
);
131 typedef std::map
<Picture
*, Region
> PictureRegionMap
;
132 void CoalesceRasters(const gfx::Rect
& canvas_rect
,
133 const gfx::Rect
& content_rect
,
134 float contents_scale
,
135 PictureRegionMap
* result
);
139 SkDrawPictureCallback
* callback
,
140 const gfx::Rect
& canvas_rect
,
141 float contents_scale
,
142 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
145 // Once instantiated, |clones_for_drawing_| can't be modified. This
146 // guarantees thread-safe access during the life time of a PicturePileImpl
147 // instance. This member variable must be last so that other member
148 // variables have already been initialized and can be clonable.
149 const ClonesForDrawing clones_for_drawing_
;
151 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl
);
156 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_