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 // 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.
37 const gfx::Rect
& canvas_rect
,
39 RenderingStatsInstrumentation
* rendering_stats_instrumentation
);
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.
47 const gfx::Rect
& canvas_rect
,
49 RenderingStatsInstrumentation
* stats_instrumentation
) const;
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
,
57 RenderingStatsInstrumentation
* stats_instrumentation
) const;
59 skia::RefPtr
<SkPicture
> GetFlattenedPicture();
61 struct CC_EXPORT Analysis
{
69 void AnalyzeInRect(const gfx::Rect
& content_rect
,
71 Analysis
* analysis
) const;
74 const gfx::Rect
& content_rect
,
77 RenderingStatsInstrumentation
* stats_instrumentation
) const;
79 class CC_EXPORT PixelRefIterator
{
81 PixelRefIterator(const gfx::Rect
& content_rect
,
83 const PicturePileImpl
* picture_pile
);
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_
; }
92 void AdvanceToTilePictureWithPixelRefs();
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_
;
101 void DidBeginTracing();
104 friend class PicturePile
;
105 friend class PixelRefIterator
;
108 explicit PicturePileImpl(const PicturePileBase
* other
);
109 virtual ~PicturePileImpl();
112 typedef std::map
<const Picture
*, Region
> PictureRegionMap
;
114 void CoalesceRasters(const gfx::Rect
& canvas_rect
,
115 const gfx::Rect
& content_rect
,
116 float contents_scale
,
117 PictureRegionMap
* result
) const;
121 SkDrawPictureCallback
* callback
,
122 const gfx::Rect
& canvas_rect
,
123 float contents_scale
,
124 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
125 bool is_analysis
) const;
127 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl
);
132 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_