| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CC_PLAYBACK_RASTER_SOURCE_H_ | |
| 6 #define CC_PLAYBACK_RASTER_SOURCE_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "cc/base/cc_export.h" | |
| 15 #include "cc/debug/rendering_stats_instrumentation.h" | |
| 16 #include "cc/playback/image_id.h" | |
| 17 #include "cc/playback/recording_source.h" | |
| 18 #include "skia/ext/analysis_canvas.h" | |
| 19 #include "third_party/skia/include/core/SkPicture.h" | |
| 20 | |
| 21 namespace cc { | |
| 22 class DisplayItemList; | |
| 23 class DrawImage; | |
| 24 class ImageDecodeCache; | |
| 25 | |
| 26 class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> { | |
| 27 public: | |
| 28 struct CC_EXPORT PlaybackSettings { | |
| 29 PlaybackSettings(); | |
| 30 PlaybackSettings(const PlaybackSettings&); | |
| 31 PlaybackSettings(PlaybackSettings&&); | |
| 32 ~PlaybackSettings(); | |
| 33 | |
| 34 // If set to true, this indicates that the canvas has already been | |
| 35 // rasterized into. This means that the canvas cannot be cleared safely. | |
| 36 bool playback_to_shared_canvas; | |
| 37 | |
| 38 // If set to true, none of the images will be rasterized. | |
| 39 bool skip_images; | |
| 40 | |
| 41 // If set to true, we will use an image hijack canvas, which enables | |
| 42 // compositor image caching. | |
| 43 bool use_image_hijack_canvas; | |
| 44 | |
| 45 // If non-empty, an image hijack canvas will be used to skip these images | |
| 46 // during raster. | |
| 47 // TODO(khushalsagar): Consolidate more settings for playback here? See | |
| 48 // crbug.com/691076. | |
| 49 ImageIdFlatSet images_to_skip; | |
| 50 }; | |
| 51 | |
| 52 static scoped_refptr<RasterSource> CreateFromRecordingSource( | |
| 53 const RecordingSource* other, | |
| 54 bool can_use_lcd_text); | |
| 55 | |
| 56 // TODO(trchen): Deprecated. | |
| 57 void PlaybackToCanvas(SkCanvas* canvas, | |
| 58 const gfx::Rect& canvas_bitmap_rect, | |
| 59 const gfx::Rect& canvas_playback_rect, | |
| 60 float contents_scale, | |
| 61 const PlaybackSettings& settings) const; | |
| 62 | |
| 63 // Raster this RasterSource into the given canvas. Canvas states such as | |
| 64 // CTM and clip region will be respected. This function will replace pixels | |
| 65 // in the clip region without blending. It is assumed that existing pixels | |
| 66 // may be uninitialized and will be cleared before playback. | |
| 67 // | |
| 68 // Virtual for testing. | |
| 69 // | |
| 70 // Note that this should only be called after the image decode controller has | |
| 71 // been set, which happens during commit. | |
| 72 virtual void PlaybackToCanvas(SkCanvas* canvas, | |
| 73 const PlaybackSettings& settings) const; | |
| 74 | |
| 75 // Returns whether the given rect at given scale is of solid color in | |
| 76 // this raster source, as well as the solid color value. | |
| 77 bool PerformSolidColorAnalysis(const gfx::Rect& content_rect, | |
| 78 float contents_scale, | |
| 79 SkColor* color) const; | |
| 80 | |
| 81 // Returns true iff the whole raster source is of solid color. | |
| 82 bool IsSolidColor() const; | |
| 83 | |
| 84 // Returns the color of the raster source if it is solid color. The results | |
| 85 // are unspecified if IsSolidColor returns false. | |
| 86 SkColor GetSolidColor() const; | |
| 87 | |
| 88 // Returns the size of this raster source. | |
| 89 gfx::Size GetSize() const; | |
| 90 | |
| 91 // Populate the given list with all images that may overlap the given | |
| 92 // rect in layer space. The returned draw images' matrices are modified as if | |
| 93 // they were being using during raster at scale |raster_scale|. | |
| 94 void GetDiscardableImagesInRect(const gfx::Rect& layer_rect, | |
| 95 float contents_scale, | |
| 96 std::vector<DrawImage>* images) const; | |
| 97 | |
| 98 // Return true iff this raster source can raster the given rect in layer | |
| 99 // space. | |
| 100 bool CoversRect(const gfx::Rect& layer_rect) const; | |
| 101 | |
| 102 // Returns true if this raster source has anything to rasterize. | |
| 103 virtual bool HasRecordings() const; | |
| 104 | |
| 105 // Valid rectangle in which everything is recorded and can be rastered from. | |
| 106 virtual gfx::Rect RecordedViewport() const; | |
| 107 | |
| 108 gfx::Rect GetRectForImage(ImageId image_id) const; | |
| 109 | |
| 110 // Tracing functionality. | |
| 111 virtual void DidBeginTracing(); | |
| 112 virtual void AsValueInto(base::trace_event::TracedValue* array) const; | |
| 113 virtual sk_sp<SkPicture> GetFlattenedPicture(); | |
| 114 virtual size_t GetMemoryUsage() const; | |
| 115 | |
| 116 // Return true if LCD anti-aliasing may be used when rastering text. | |
| 117 virtual bool CanUseLCDText() const; | |
| 118 | |
| 119 scoped_refptr<RasterSource> CreateCloneWithoutLCDText() const; | |
| 120 | |
| 121 // Image decode controller should be set once. Its lifetime has to exceed that | |
| 122 // of the raster source, since the raster source will access it during raster. | |
| 123 void set_image_decode_cache(ImageDecodeCache* image_decode_cache) { | |
| 124 DCHECK(image_decode_cache); | |
| 125 image_decode_cache_ = image_decode_cache; | |
| 126 } | |
| 127 | |
| 128 protected: | |
| 129 friend class base::RefCountedThreadSafe<RasterSource>; | |
| 130 | |
| 131 RasterSource(const RecordingSource* other, bool can_use_lcd_text); | |
| 132 RasterSource(const RasterSource* other, bool can_use_lcd_text); | |
| 133 virtual ~RasterSource(); | |
| 134 | |
| 135 // These members are const as this raster source may be in use on another | |
| 136 // thread and so should not be touched after construction. | |
| 137 const scoped_refptr<DisplayItemList> display_list_; | |
| 138 const size_t painter_reported_memory_usage_; | |
| 139 const SkColor background_color_; | |
| 140 const bool requires_clear_; | |
| 141 const bool can_use_lcd_text_; | |
| 142 const bool is_solid_color_; | |
| 143 const SkColor solid_color_; | |
| 144 const gfx::Rect recorded_viewport_; | |
| 145 const gfx::Size size_; | |
| 146 const bool clear_canvas_with_debug_color_; | |
| 147 const int slow_down_raster_scale_factor_for_debug_; | |
| 148 | |
| 149 // In practice, this is only set once before raster begins, so it's ok with | |
| 150 // respect to threading. | |
| 151 ImageDecodeCache* image_decode_cache_; | |
| 152 | |
| 153 private: | |
| 154 void RasterCommon(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; | |
| 155 | |
| 156 void PrepareForPlaybackToCanvas(SkCanvas* canvas) const; | |
| 157 | |
| 158 DISALLOW_COPY_AND_ASSIGN(RasterSource); | |
| 159 }; | |
| 160 | |
| 161 } // namespace cc | |
| 162 | |
| 163 #endif // CC_PLAYBACK_RASTER_SOURCE_H_ | |
| OLD | NEW |