| 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_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ | 5 #ifndef CC_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ |
| 6 #define CC_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ | 6 #define CC_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 #include "cc/debug/rendering_stats_instrumentation.h" | 12 #include "cc/debug/rendering_stats_instrumentation.h" |
| 13 #include "cc/playback/display_list_recording_source.h" | 13 #include "cc/playback/display_list_recording_source.h" |
| 14 #include "cc/playback/raster_source.h" | 14 #include "cc/playback/position_image.h" |
| 15 #include "skia/ext/analysis_canvas.h" | 15 #include "skia/ext/analysis_canvas.h" |
| 16 #include "skia/ext/refptr.h" | 16 #include "skia/ext/refptr.h" |
| 17 #include "third_party/skia/include/core/SkPicture.h" | 17 #include "third_party/skia/include/core/SkPicture.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 class DisplayItemList; | 20 class DisplayItemList; |
| 21 | 21 |
| 22 class CC_EXPORT DisplayListRasterSource : public RasterSource { | 22 class CC_EXPORT DisplayListRasterSource |
| 23 : public base::RefCountedThreadSafe<DisplayListRasterSource> { |
| 23 public: | 24 public: |
| 25 struct CC_EXPORT SolidColorAnalysis { |
| 26 SolidColorAnalysis() |
| 27 : is_solid_color(false), solid_color(SK_ColorTRANSPARENT) {} |
| 28 ~SolidColorAnalysis() {} |
| 29 |
| 30 bool is_solid_color; |
| 31 SkColor solid_color; |
| 32 }; |
| 33 |
| 24 static scoped_refptr<DisplayListRasterSource> | 34 static scoped_refptr<DisplayListRasterSource> |
| 25 CreateFromDisplayListRecordingSource(const DisplayListRecordingSource* other, | 35 CreateFromDisplayListRecordingSource(const DisplayListRecordingSource* other, |
| 26 bool can_use_lcd_text); | 36 bool can_use_lcd_text); |
| 27 | 37 |
| 28 // RasterSource overrides. | 38 // Raster a subrect of this RasterSource into the given canvas. It is |
| 29 void PlaybackToCanvas(SkCanvas* canvas, | 39 // assumed that contents_scale has already been applied to this canvas. |
| 30 const gfx::Rect& canvas_bitmap_rect, | 40 // Writes the total number of pixels rasterized and the time spent |
| 31 const gfx::Rect& canvas_playback_rect, | 41 // rasterizing to the stats if the respective pointer is not nullptr. |
| 32 float contents_scale) const override; | 42 // It is assumed that the canvas passed here will only be rasterized by |
| 43 // this raster source via this call. |
| 44 // virtual for testing. |
| 45 virtual void PlaybackToCanvas(SkCanvas* canvas, |
| 46 const gfx::Rect& canvas_bitmap_rect, |
| 47 const gfx::Rect& canvas_playback_rect, |
| 48 float contents_scale) const; |
| 49 |
| 50 // Similar to above, except that the canvas passed here can (or was already) |
| 51 // rasterized into by another raster source. That is, it is not safe to clear |
| 52 // the canvas or discard its underlying memory. |
| 33 void PlaybackToSharedCanvas(SkCanvas* canvas, | 53 void PlaybackToSharedCanvas(SkCanvas* canvas, |
| 34 const gfx::Rect& canvas_rect, | 54 const gfx::Rect& canvas_rect, |
| 35 float contents_scale) const override; | 55 float contents_scale) const; |
| 36 void PerformSolidColorAnalysis( | 56 |
| 37 const gfx::Rect& content_rect, | 57 // Analyze to determine if the given rect at given scale is of solid color in |
| 38 float contents_scale, | 58 // this raster source. |
| 39 RasterSource::SolidColorAnalysis* analysis) const override; | 59 void PerformSolidColorAnalysis(const gfx::Rect& content_rect, |
| 40 bool IsSolidColor() const override; | 60 float contents_scale, |
| 41 SkColor GetSolidColor() const override; | 61 SolidColorAnalysis* analysis) const; |
| 42 gfx::Size GetSize() const override; | 62 |
| 43 void GetDiscardableImagesInRect( | 63 // Returns true iff the whole raster source is of solid color. |
| 44 const gfx::Rect& layer_rect, | 64 bool IsSolidColor() const; |
| 45 std::vector<PositionImage>* images) const override; | 65 |
| 46 bool CoversRect(const gfx::Rect& layer_rect) const override; | 66 // Returns the color of the raster source if it is solid color. The results |
| 47 bool HasRecordings() const override; | 67 // are unspecified if IsSolidColor returns false. |
| 48 gfx::Rect RecordedViewport() const override; | 68 SkColor GetSolidColor() const; |
| 49 void SetShouldAttemptToUseDistanceFieldText() override; | 69 |
| 50 bool ShouldAttemptToUseDistanceFieldText() const override; | 70 // Returns the size of this raster source. |
| 51 void DidBeginTracing() override; | 71 gfx::Size GetSize() const; |
| 52 void AsValueInto(base::trace_event::TracedValue* array) const override; | 72 |
| 53 skia::RefPtr<SkPicture> GetFlattenedPicture() override; | 73 // Populate the given list with all images that may overlap the given |
| 54 size_t GetPictureMemoryUsage() const override; | 74 // rect in layer space. |
| 55 bool CanUseLCDText() const override; | 75 void GetDiscardableImagesInRect(const gfx::Rect& layer_rect, |
| 56 scoped_refptr<RasterSource> CreateCloneWithoutLCDText() const override; | 76 std::vector<PositionImage>* images) const; |
| 77 |
| 78 // Return true iff this raster source can raster the given rect in layer |
| 79 // space. |
| 80 bool CoversRect(const gfx::Rect& layer_rect) const; |
| 81 |
| 82 // Returns true if this raster source has anything to rasterize. |
| 83 virtual bool HasRecordings() const; |
| 84 |
| 85 // Valid rectangle in which everything is recorded and can be rastered from. |
| 86 virtual gfx::Rect RecordedViewport() const; |
| 87 |
| 88 // Informs the raster source that it should attempt to use distance field text |
| 89 // during rasterization. |
| 90 virtual void SetShouldAttemptToUseDistanceFieldText(); |
| 91 |
| 92 // Return true iff this raster source would benefit from using distance |
| 93 // field text. |
| 94 virtual bool ShouldAttemptToUseDistanceFieldText() const; |
| 95 |
| 96 // Tracing functionality. |
| 97 virtual void DidBeginTracing(); |
| 98 virtual void AsValueInto(base::trace_event::TracedValue* array) const; |
| 99 virtual skia::RefPtr<SkPicture> GetFlattenedPicture(); |
| 100 virtual size_t GetPictureMemoryUsage() const; |
| 101 |
| 102 // Return true if LCD anti-aliasing may be used when rastering text. |
| 103 virtual bool CanUseLCDText() const; |
| 104 |
| 105 scoped_refptr<DisplayListRasterSource> CreateCloneWithoutLCDText() const; |
| 57 | 106 |
| 58 protected: | 107 protected: |
| 108 friend class base::RefCountedThreadSafe<DisplayListRasterSource>; |
| 109 |
| 59 DisplayListRasterSource(const DisplayListRecordingSource* other, | 110 DisplayListRasterSource(const DisplayListRecordingSource* other, |
| 60 bool can_use_lcd_text); | 111 bool can_use_lcd_text); |
| 61 DisplayListRasterSource(const DisplayListRasterSource* other, | 112 DisplayListRasterSource(const DisplayListRasterSource* other, |
| 62 bool can_use_lcd_text); | 113 bool can_use_lcd_text); |
| 63 ~DisplayListRasterSource() override; | 114 virtual ~DisplayListRasterSource(); |
| 64 | 115 |
| 65 // These members are const as this raster source may be in use on another | 116 // These members are const as this raster source may be in use on another |
| 66 // thread and so should not be touched after construction. | 117 // thread and so should not be touched after construction. |
| 67 const scoped_refptr<DisplayItemList> display_list_; | 118 const scoped_refptr<DisplayItemList> display_list_; |
| 68 const size_t painter_reported_memory_usage_; | 119 const size_t painter_reported_memory_usage_; |
| 69 const SkColor background_color_; | 120 const SkColor background_color_; |
| 70 const bool requires_clear_; | 121 const bool requires_clear_; |
| 71 const bool can_use_lcd_text_; | 122 const bool can_use_lcd_text_; |
| 72 const bool is_solid_color_; | 123 const bool is_solid_color_; |
| 73 const SkColor solid_color_; | 124 const SkColor solid_color_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 const gfx::Rect& canvas_bitmap_rect, | 142 const gfx::Rect& canvas_bitmap_rect, |
| 92 const gfx::Rect& canvas_playback_rect, | 143 const gfx::Rect& canvas_playback_rect, |
| 93 float contents_scale) const; | 144 float contents_scale) const; |
| 94 | 145 |
| 95 DISALLOW_COPY_AND_ASSIGN(DisplayListRasterSource); | 146 DISALLOW_COPY_AND_ASSIGN(DisplayListRasterSource); |
| 96 }; | 147 }; |
| 97 | 148 |
| 98 } // namespace cc | 149 } // namespace cc |
| 99 | 150 |
| 100 #endif // CC_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ | 151 #endif // CC_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ |
| OLD | NEW |