Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / playback / raster_source.h
bloba9bbcf10b33c656be919207ac2309c8acf45b04a
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_
8 #include <vector>
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/discardable_image_utils.h"
14 #include "skia/ext/refptr.h"
15 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/size.h"
19 class SkCanvas;
20 class SkPicture;
22 namespace cc {
24 class Picture;
26 class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> {
27 public:
28 struct CC_EXPORT SolidColorAnalysis {
29 SolidColorAnalysis()
30 : is_solid_color(false), solid_color(SK_ColorTRANSPARENT) {}
31 ~SolidColorAnalysis() {}
33 bool is_solid_color;
34 SkColor solid_color;
37 // Raster a subrect of this RasterSource into the given canvas. It is
38 // assumed that contents_scale has already been applied to this canvas.
39 // Writes the total number of pixels rasterized and the time spent
40 // rasterizing to the stats if the respective pointer is not nullptr.
41 // It is assumed that the canvas passed here will only be rasterized by
42 // this raster source via this call.
43 virtual void PlaybackToCanvas(SkCanvas* canvas,
44 const gfx::Rect& canvas_bitmap_rect,
45 const gfx::Rect& canvas_playback_rect,
46 float contents_scale) const = 0;
48 // Similar to above, except that the canvas passed here can (or was already)
49 // rasterized into by another raster source. That is, it is not safe to clear
50 // the canvas or discard its underlying memory.
51 virtual void PlaybackToSharedCanvas(SkCanvas* canvas,
52 const gfx::Rect& canvas_rect,
53 float contents_scale) const = 0;
55 // Analyze to determine if the given rect at given scale is of solid color in
56 // this raster source.
57 virtual void PerformSolidColorAnalysis(
58 const gfx::Rect& content_rect,
59 float contents_scale,
60 SolidColorAnalysis* analysis) const = 0;
62 // Returns true iff the whole raster source is of solid color.
63 virtual bool IsSolidColor() const = 0;
65 // Returns the color of the raster source if it is solid color. The results
66 // are unspecified if IsSolidColor returns false.
67 virtual SkColor GetSolidColor() const = 0;
69 // Returns the size of this raster source.
70 virtual gfx::Size GetSize() const = 0;
72 // Populate the given list with all images that may overlap the given
73 // rect in layer space.
74 virtual void GatherDiscardableImages(
75 const gfx::Rect& layer_rect,
76 std::vector<skia::PositionImage>* images) const = 0;
78 // Return true iff this raster source can raster the given rect in layer
79 // space.
80 virtual bool CoversRect(const gfx::Rect& layer_rect) const = 0;
82 // Returns true if this raster source has anything to rasterize.
83 virtual bool HasRecordings() const = 0;
85 // Valid rectangle in which everything is recorded and can be rastered from.
86 virtual gfx::Rect RecordedViewport() const = 0;
88 // Informs the raster source that it should attempt to use distance field text
89 // during rasterization.
90 virtual void SetShouldAttemptToUseDistanceFieldText() = 0;
92 // Return true iff this raster source would benefit from using distance
93 // field text.
94 virtual bool ShouldAttemptToUseDistanceFieldText() const = 0;
96 // Tracing functionality.
97 virtual void DidBeginTracing() = 0;
98 virtual void AsValueInto(base::trace_event::TracedValue* array) const = 0;
99 virtual skia::RefPtr<SkPicture> GetFlattenedPicture() = 0;
100 virtual size_t GetPictureMemoryUsage() const = 0;
102 // Return true if LCD anti-aliasing may be used when rastering text.
103 virtual bool CanUseLCDText() const = 0;
105 virtual scoped_refptr<RasterSource> CreateCloneWithoutLCDText() const = 0;
107 protected:
108 friend class base::RefCountedThreadSafe<RasterSource>;
110 RasterSource() {}
111 virtual ~RasterSource() {}
113 private:
114 DISALLOW_COPY_AND_ASSIGN(RasterSource);
117 } // namespace cc
119 #endif // CC_PLAYBACK_RASTER_SOURCE_H_