1 // Copyright 2014 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_PLAYBACK_RASTER_SOURCE_H_
6 #define CC_PLAYBACK_RASTER_SOURCE_H_
10 #include "base/memory/ref_counted.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/debug/traced_value.h"
13 #include "skia/ext/pixel_ref_utils.h"
14 #include "skia/ext/refptr.h"
15 #include "third_party/skia/include/core/SkColor.h"
16 #include "third_party/skia/include/core/SkPixelRef.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h"
27 class CC_EXPORT RasterSource
: public base::RefCountedThreadSafe
<RasterSource
> {
29 struct CC_EXPORT SolidColorAnalysis
{
31 : is_solid_color(false), solid_color(SK_ColorTRANSPARENT
) {}
32 ~SolidColorAnalysis() {}
38 // Raster a subrect of this RasterSource into the given canvas. It is
39 // assumed that contents_scale has already been applied to this canvas.
40 // Writes the total number of pixels rasterized and the time spent
41 // rasterizing to the stats if the respective pointer is not nullptr.
42 // It is assumed that the canvas passed here will only be rasterized by
43 // this raster source via this call.
44 virtual void PlaybackToCanvas(SkCanvas
* canvas
,
45 const gfx::Rect
& canvas_bitmap_rect
,
46 const gfx::Rect
& canvas_playback_rect
,
47 float contents_scale
) const = 0;
49 // Similar to above, except that the canvas passed here can (or was already)
50 // rasterized into by another raster source. That is, it is not safe to clear
51 // the canvas or discard its underlying memory.
52 virtual void PlaybackToSharedCanvas(SkCanvas
* canvas
,
53 const gfx::Rect
& canvas_rect
,
54 float contents_scale
) const = 0;
56 // Analyze to determine if the given rect at given scale is of solid color in
57 // this raster source.
58 virtual void PerformSolidColorAnalysis(
59 const gfx::Rect
& content_rect
,
61 SolidColorAnalysis
* analysis
) const = 0;
63 // Returns true iff the whole raster source is of solid color.
64 virtual bool IsSolidColor() const = 0;
66 // Returns the color of the raster source if it is solid color. The results
67 // are unspecified if IsSolidColor returns false.
68 virtual SkColor
GetSolidColor() const = 0;
70 // Returns the size of this raster source.
71 virtual gfx::Size
GetSize() const = 0;
73 // Populate the given list with all SkPixelRefs that may overlap the given
74 // rect in layer space.
75 virtual void GatherPixelRefs(
76 const gfx::Rect
& layer_rect
,
77 std::vector
<skia::PositionPixelRef
>* pixel_refs
) const = 0;
79 // Return true iff this raster source can raster the given rect in layer
81 virtual bool CoversRect(const gfx::Rect
& layer_rect
) const = 0;
83 // Returns true if this raster source has anything to rasterize.
84 virtual bool HasRecordings() const = 0;
86 // Valid rectangle in which everything is recorded and can be rastered from.
87 virtual gfx::Rect
RecordedViewport() const = 0;
89 // Informs the raster source that it should attempt to use distance field text
90 // during rasterization.
91 virtual void SetShouldAttemptToUseDistanceFieldText() = 0;
93 // Return true iff this raster source would benefit from using distance
95 virtual bool ShouldAttemptToUseDistanceFieldText() const = 0;
97 // Tracing functionality.
98 virtual void DidBeginTracing() = 0;
99 virtual void AsValueInto(base::trace_event::TracedValue
* array
) const = 0;
100 virtual skia::RefPtr
<SkPicture
> GetFlattenedPicture() = 0;
101 virtual size_t GetPictureMemoryUsage() const = 0;
103 // Return true if LCD anti-aliasing may be used when rastering text.
104 virtual bool CanUseLCDText() const = 0;
106 virtual scoped_refptr
<RasterSource
> CreateCloneWithoutLCDText() const = 0;
109 friend class base::RefCountedThreadSafe
<RasterSource
>;
112 virtual ~RasterSource() {}
115 DISALLOW_COPY_AND_ASSIGN(RasterSource
);
120 #endif // CC_PLAYBACK_RASTER_SOURCE_H_