| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_TEST_FAKE_RECORDING_SOURCE_H_ | 5 #ifndef CC_TEST_FAKE_RECORDING_SOURCE_H_ |
| 6 #define CC_TEST_FAKE_RECORDING_SOURCE_H_ | 6 #define CC_TEST_FAKE_RECORDING_SOURCE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "cc/base/region.h" | 10 #include "cc/base/region.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // This class provides method for test to add bitmap and draw rect to content | 23 // This class provides method for test to add bitmap and draw rect to content |
| 24 // layer client. This class also provides function to rerecord to generate a new | 24 // layer client. This class also provides function to rerecord to generate a new |
| 25 // display list. | 25 // display list. |
| 26 class FakeRecordingSource : public RecordingSource { | 26 class FakeRecordingSource : public RecordingSource { |
| 27 public: | 27 public: |
| 28 FakeRecordingSource(); | 28 FakeRecordingSource(); |
| 29 ~FakeRecordingSource() override {} | 29 ~FakeRecordingSource() override {} |
| 30 | 30 |
| 31 static std::unique_ptr<FakeRecordingSource> CreateRecordingSource( | 31 static std::unique_ptr<FakeRecordingSource> CreateRecordingSource( |
| 32 const gfx::Rect& recorded_viewport, | |
| 33 const gfx::Size& layer_bounds) { | 32 const gfx::Size& layer_bounds) { |
| 34 std::unique_ptr<FakeRecordingSource> recording_source( | 33 std::unique_ptr<FakeRecordingSource> recording_source( |
| 35 new FakeRecordingSource); | 34 new FakeRecordingSource); |
| 36 recording_source->SetRecordedViewport(recorded_viewport); | |
| 37 recording_source->SetLayerBounds(layer_bounds); | 35 recording_source->SetLayerBounds(layer_bounds); |
| 38 return recording_source; | 36 return recording_source; |
| 39 } | 37 } |
| 40 | 38 |
| 41 static std::unique_ptr<FakeRecordingSource> CreateFilledRecordingSource( | 39 static std::unique_ptr<FakeRecordingSource> CreateFilledRecordingSource( |
| 42 const gfx::Size& layer_bounds) { | 40 const gfx::Size& layer_bounds) { |
| 43 std::unique_ptr<FakeRecordingSource> recording_source( | 41 std::unique_ptr<FakeRecordingSource> recording_source( |
| 44 new FakeRecordingSource); | 42 new FakeRecordingSource); |
| 45 recording_source->SetRecordedViewport(gfx::Rect(layer_bounds)); | |
| 46 recording_source->SetLayerBounds(layer_bounds); | 43 recording_source->SetLayerBounds(layer_bounds); |
| 47 return recording_source; | 44 return recording_source; |
| 48 } | 45 } |
| 49 | 46 |
| 50 // RecordingSource overrides. | 47 // RecordingSource overrides. |
| 51 scoped_refptr<RasterSource> CreateRasterSource( | 48 scoped_refptr<RasterSource> CreateRasterSource( |
| 52 bool can_use_lcd) const override; | 49 bool can_use_lcd, |
| 53 bool IsSuitableForGpuRasterization() const override; | 50 gfx::Rect& recorded_viewport, |
| 51 scoped_refptr<DisplayItemList>& display_list, |
| 52 size_t& painter_reported_memory_usage) const override; |
| 54 | 53 |
| 55 void SetDisplayListUsesCachedPicture(bool use_cached_picture) { | 54 void SetDisplayListUsesCachedPicture(bool use_cached_picture) { |
| 56 client_.set_display_list_use_cached_picture(use_cached_picture); | 55 client_.set_display_list_use_cached_picture(use_cached_picture); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void SetRecordedViewport(const gfx::Rect& recorded_viewport) { | |
| 60 recorded_viewport_ = recorded_viewport; | |
| 61 } | |
| 62 | |
| 63 void SetLayerBounds(const gfx::Size& layer_bounds) { | 58 void SetLayerBounds(const gfx::Size& layer_bounds) { |
| 64 size_ = layer_bounds; | 59 size_ = layer_bounds; |
| 65 client_.set_bounds(layer_bounds); | 60 client_.set_bounds(layer_bounds); |
| 66 } | 61 } |
| 67 | 62 |
| 68 void SetClearCanvasWithDebugColor(bool clear) { | 63 void SetClearCanvasWithDebugColor(bool clear) { |
| 69 clear_canvas_with_debug_color_ = clear; | 64 clear_canvas_with_debug_color_ = clear; |
| 70 } | 65 } |
| 71 | 66 |
| 72 void Rerecord() { | 67 void Rerecord(const gfx::Rect& recorded_viewport) { |
| 73 SetNeedsDisplayRect(recorded_viewport_); | 68 SetNeedsDisplayRect(recorded_viewport); |
| 74 Region invalidation; | 69 Region invalidation; |
| 75 UpdateAndExpandInvalidation(&client_, &invalidation, size_, 0, | 70 gfx::Rect old_recorded_viewport = recorded_viewport; |
| 76 RECORD_NORMALLY); | 71 gfx::Rect new_recorded_viewport = client_.PaintableRegion(); |
| 72 scoped_refptr<DisplayItemList> display_list = |
| 73 client_.PaintContentsToDisplayList( |
| 74 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 75 UpdateAndExpandInvalidation(&client_, &invalidation, size_, |
| 76 old_recorded_viewport, new_recorded_viewport, |
| 77 display_list); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void add_draw_rect(const gfx::Rect& rect) { | 80 void add_draw_rect(const gfx::Rect& rect) { |
| 80 client_.add_draw_rect(rect, default_paint_); | 81 client_.add_draw_rect(rect, default_paint_); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void add_draw_rect_with_paint(const gfx::Rect& rect, const SkPaint& paint) { | 84 void add_draw_rect_with_paint(const gfx::Rect& rect, const SkPaint& paint) { |
| 84 client_.add_draw_rect(rect, paint); | 85 client_.add_draw_rect(rect, paint); |
| 85 } | 86 } |
| 86 | 87 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 121 } |
| 121 | 122 |
| 122 void SetUnsuitableForGpuRasterization() { | 123 void SetUnsuitableForGpuRasterization() { |
| 123 force_unsuitable_for_gpu_rasterization_ = true; | 124 force_unsuitable_for_gpu_rasterization_ = true; |
| 124 } | 125 } |
| 125 | 126 |
| 126 void SetPlaybackAllowedEvent(base::WaitableEvent* event) { | 127 void SetPlaybackAllowedEvent(base::WaitableEvent* event) { |
| 127 playback_allowed_event_ = event; | 128 playback_allowed_event_ = event; |
| 128 } | 129 } |
| 129 | 130 |
| 130 DisplayItemList* display_list() const { return display_list_.get(); } | |
| 131 | |
| 132 // Checks that the basic properties of the |other| match |this|. For the | 131 // Checks that the basic properties of the |other| match |this|. For the |
| 133 // DisplayItemList, it checks that the painted result matches the painted | 132 // DisplayItemList, it checks that the painted result matches the painted |
| 134 // result of |other|. | 133 // result of |other|. |
| 135 bool EqualsTo(const FakeRecordingSource& other); | 134 bool EqualsTo(const FakeRecordingSource& other); |
| 136 | 135 |
| 137 private: | 136 private: |
| 138 FakeContentLayerClient client_; | 137 FakeContentLayerClient client_; |
| 139 SkPaint default_paint_; | 138 SkPaint default_paint_; |
| 140 bool force_unsuitable_for_gpu_rasterization_; | 139 bool force_unsuitable_for_gpu_rasterization_; |
| 141 base::WaitableEvent* playback_allowed_event_; | 140 base::WaitableEvent* playback_allowed_event_; |
| 142 }; | 141 }; |
| 143 | 142 |
| 144 } // namespace cc | 143 } // namespace cc |
| 145 | 144 |
| 146 #endif // CC_TEST_FAKE_RECORDING_SOURCE_H_ | 145 #endif // CC_TEST_FAKE_RECORDING_SOURCE_H_ |
| OLD | NEW |