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 "cc/resources/raster_source.h"
18 #include "skia/ext/analysis_canvas.h"
19 #include "skia/ext/refptr.h"
20 #include "third_party/skia/include/core/SkPicture.h"
24 // TODO(vmpstr): Clean up PicturePileBase and make it a member.
25 class CC_EXPORT PicturePileImpl
: public PicturePileBase
, public RasterSource
{
27 static scoped_refptr
<PicturePileImpl
> Create();
28 static scoped_refptr
<PicturePileImpl
> CreateFromOther(
29 const PicturePileBase
* other
);
31 // RasterSource overrides. See RasterSource header for full description.
32 // When slow-down-raster-scale-factor is set to a value greater than 1, the
33 // reported rasterize time (in stats_instrumentation) is the minimum measured
34 // value over all runs.
35 void PlaybackToCanvas(SkCanvas
* canvas
,
36 const gfx::Rect
& canvas_rect
,
37 float contents_scale
) const override
;
38 void PerformSolidColorAnalysis(
39 const gfx::Rect
& content_rect
,
41 RasterSource::SolidColorAnalysis
* analysis
) const override
;
42 void GatherPixelRefs(const gfx::Rect
& content_rect
,
44 std::vector
<SkPixelRef
*>* pixel_refs
) const override
;
45 bool CoversRect(const gfx::Rect
& content_rect
,
46 float contents_scale
) const override
;
47 bool SuitableForDistanceFieldText() const override
;
49 // Raster into the canvas without applying clips.
50 void RasterDirect(SkCanvas
* canvas
,
51 const gfx::Rect
& canvas_rect
,
52 float contents_scale
) const;
54 // Tracing functionality.
55 void DidBeginTracing();
56 skia::RefPtr
<SkPicture
> GetFlattenedPicture();
58 void set_likely_to_be_used_for_transform_animation() {
59 likely_to_be_used_for_transform_animation_
= true;
62 // Iterator used to return SkPixelRefs from this picture pile.
63 // Public for testing.
64 class CC_EXPORT PixelRefIterator
{
66 PixelRefIterator(const gfx::Rect
& content_rect
,
68 const PicturePileImpl
* picture_pile
);
71 SkPixelRef
* operator->() const { return *pixel_ref_iterator_
; }
72 SkPixelRef
* operator*() const { return *pixel_ref_iterator_
; }
73 PixelRefIterator
& operator++();
74 operator bool() const { return pixel_ref_iterator_
; }
77 void AdvanceToTilePictureWithPixelRefs();
79 const PicturePileImpl
* picture_pile_
;
80 gfx::Rect layer_rect_
;
81 TilingData::Iterator tile_iterator_
;
82 Picture::PixelRefIterator pixel_ref_iterator_
;
83 std::set
<const void*> processed_pictures_
;
87 friend class PicturePile
;
88 friend class PixelRefIterator
;
91 explicit PicturePileImpl(const PicturePileBase
* other
);
92 ~PicturePileImpl() override
;
95 typedef std::map
<const Picture
*, Region
> PictureRegionMap
;
97 // Called when analyzing a tile. We can use AnalysisCanvas as
98 // SkDrawPictureCallback, which allows us to early out from analysis.
99 void RasterForAnalysis(skia::AnalysisCanvas
* canvas
,
100 const gfx::Rect
& canvas_rect
,
101 float contents_scale
) const;
103 void CoalesceRasters(const gfx::Rect
& canvas_rect
,
104 const gfx::Rect
& content_rect
,
105 float contents_scale
,
106 PictureRegionMap
* result
) const;
110 SkDrawPictureCallback
* callback
,
111 const gfx::Rect
& canvas_rect
,
112 float contents_scale
,
113 bool is_analysis
) const;
115 bool likely_to_be_used_for_transform_animation_
;
117 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl
);
122 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_