| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_RESOURCES_RASTER_SOURCE_H_ | 5 #ifndef CC_RESOURCES_RASTER_SOURCE_H_ |
| 6 #define CC_RESOURCES_RASTER_SOURCE_H_ | 6 #define CC_RESOURCES_RASTER_SOURCE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 #include "cc/debug/traced_value.h" |
| 13 #include "skia/ext/refptr.h" |
| 12 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
| 13 | 15 |
| 14 class SkCanvas; | 16 class SkCanvas; |
| 17 class SkPicture; |
| 15 | 18 |
| 16 namespace cc { | 19 namespace cc { |
| 17 | 20 |
| 18 class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> { | 21 class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> { |
| 19 public: | 22 public: |
| 20 struct CC_EXPORT SolidColorAnalysis { | 23 struct CC_EXPORT SolidColorAnalysis { |
| 21 SolidColorAnalysis() | 24 SolidColorAnalysis() |
| 22 : is_solid_color(false), solid_color(SK_ColorTRANSPARENT) {} | 25 : is_solid_color(false), solid_color(SK_ColorTRANSPARENT) {} |
| 23 ~SolidColorAnalysis() {} | 26 ~SolidColorAnalysis() {} |
| 24 | 27 |
| 25 bool is_solid_color; | 28 bool is_solid_color; |
| 26 SkColor solid_color; | 29 SkColor solid_color; |
| 27 }; | 30 }; |
| 28 | 31 |
| 29 // Raster a subrect of this RasterSource into the given canvas. It is | 32 // Raster a subrect of this RasterSource into the given canvas. It is |
| 30 // assumed that contents_scale has already been applied to this canvas. | 33 // assumed that contents_scale has already been applied to this canvas. |
| 31 // Writes the total number of pixels rasterized and the time spent | 34 // Writes the total number of pixels rasterized and the time spent |
| 32 // rasterizing to the stats if the respective pointer is not nullptr. | 35 // rasterizing to the stats if the respective pointer is not nullptr. |
| 36 // It is assumed that the canvas passed here will only be rasterized by |
| 37 // this raster source via this call. |
| 33 virtual void PlaybackToCanvas(SkCanvas* canvas, | 38 virtual void PlaybackToCanvas(SkCanvas* canvas, |
| 34 const gfx::Rect& canvas_rect, | 39 const gfx::Rect& canvas_rect, |
| 35 float contents_scale) const = 0; | 40 float contents_scale) const = 0; |
| 36 | 41 |
| 42 // Similar to above, except that the canvas passed here can (or was already) |
| 43 // rasterized into by another raster source. That is, it is not safe to clear |
| 44 // the canvas or discard its underlying memory. |
| 45 virtual void PlaybackToSharedCanvas(SkCanvas* canvas, |
| 46 const gfx::Rect& canvas_rect, |
| 47 float contents_scale) const = 0; |
| 48 |
| 37 // Analyze to determine if the given rect at given scale is of solid color in | 49 // Analyze to determine if the given rect at given scale is of solid color in |
| 38 // this raster source. | 50 // this raster source. |
| 39 virtual void PerformSolidColorAnalysis( | 51 virtual void PerformSolidColorAnalysis( |
| 40 const gfx::Rect& content_rect, | 52 const gfx::Rect& content_rect, |
| 41 float contents_scale, | 53 float contents_scale, |
| 42 SolidColorAnalysis* analysis) const = 0; | 54 SolidColorAnalysis* analysis) const = 0; |
| 43 | 55 |
| 56 // Returns true iff the whole raster source is of solid color. |
| 57 virtual bool IsSolidColor() const = 0; |
| 58 |
| 59 // Returns the color of the raster source if it is solid color. The results |
| 60 // are unspecified if IsSolidColor returns false. |
| 61 virtual SkColor GetSolidColor() const = 0; |
| 62 |
| 63 // Returns the size of this raster source. |
| 64 virtual gfx::Size GetSize() const = 0; |
| 65 |
| 44 // Populate the given list with all SkPixelRefs that may overlap the given | 66 // Populate the given list with all SkPixelRefs that may overlap the given |
| 45 // rect at given scale. | 67 // rect at given scale. |
| 46 virtual void GatherPixelRefs(const gfx::Rect& content_rect, | 68 virtual void GatherPixelRefs(const gfx::Rect& content_rect, |
| 47 float contents_scale, | 69 float contents_scale, |
| 48 std::vector<SkPixelRef*>* pixel_refs) const = 0; | 70 std::vector<SkPixelRef*>* pixel_refs) const = 0; |
| 49 | 71 |
| 50 // Return true iff this raster source can raster the given rect at given | 72 // Return true iff this raster source can raster the given rect at given |
| 51 // scale. | 73 // scale. |
| 52 virtual bool CoversRect(const gfx::Rect& content_rect, | 74 virtual bool CoversRect(const gfx::Rect& content_rect, |
| 53 float contents_scale) const = 0; | 75 float contents_scale) const = 0; |
| 54 | 76 |
| 77 // Returns true if this raster source has anything to rasterize. |
| 78 virtual bool HasRecordings() const = 0; |
| 79 |
| 80 // Informs the raster source that it should attempt to use distance field text |
| 81 // during rasterization. |
| 82 virtual void SetShouldAttemptToUseDistanceFieldText() = 0; |
| 83 |
| 55 // Return true iff this raster source would benefit from using distance | 84 // Return true iff this raster source would benefit from using distance |
| 56 // field text. | 85 // field text. |
| 57 virtual bool SuitableForDistanceFieldText() const = 0; | 86 virtual bool ShouldAttemptToUseDistanceFieldText() const = 0; |
| 87 |
| 88 // Tracing functionality. |
| 89 virtual void DidBeginTracing() = 0; |
| 90 virtual void AsValueInto(base::debug::TracedValue* array) const = 0; |
| 91 virtual skia::RefPtr<SkPicture> GetFlattenedPicture() = 0; |
| 92 |
| 93 // TODO(vmpstr): This should be a layer property. |
| 94 virtual bool IsMask() const = 0; |
| 58 | 95 |
| 59 protected: | 96 protected: |
| 60 friend class base::RefCountedThreadSafe<RasterSource>; | 97 friend class base::RefCountedThreadSafe<RasterSource>; |
| 61 | 98 |
| 62 RasterSource() {} | 99 RasterSource() {} |
| 63 virtual ~RasterSource() {} | 100 virtual ~RasterSource() {} |
| 64 | 101 |
| 65 private: | 102 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(RasterSource); | 103 DISALLOW_COPY_AND_ASSIGN(RasterSource); |
| 67 }; | 104 }; |
| 68 | 105 |
| 69 } // namespace cc | 106 } // namespace cc |
| 70 | 107 |
| 71 #endif // CC_RESOURCES_RASTER_SOURCE_H_ | 108 #endif // CC_RESOURCES_RASTER_SOURCE_H_ |
| OLD | NEW |