Chromium Code Reviews| 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, | 32 const gfx::Rect& recorded_viewport, |
|
Menglin
2016/07/26 17:49:42
Do I still need to care about the recorded_viewpor
vmpstr
2016/07/27 18:18:37
Where do we call SetRecordedViewport aside from te
Menglin
2016/07/27 19:17:48
the only place it is called besides in this file i
vmpstr
2016/07/28 18:19:58
If that's only called in test, then maybe we can j
Menglin
2016/07/29 21:32:55
These two functions are called by FakeRasterSource
| |
| 33 const gfx::Size& layer_bounds) { | 33 const gfx::Size& layer_bounds) { |
| 34 std::unique_ptr<FakeRecordingSource> recording_source( | 34 std::unique_ptr<FakeRecordingSource> recording_source( |
| 35 new FakeRecordingSource); | 35 new FakeRecordingSource); |
| 36 recording_source->SetRecordedViewport(recorded_viewport); | 36 recording_source->SetRecordedViewport(recorded_viewport); |
| 37 recording_source->SetLayerBounds(layer_bounds); | 37 recording_source->SetLayerBounds(layer_bounds); |
| 38 return recording_source; | 38 return recording_source; |
| 39 } | 39 } |
| 40 | 40 |
| 41 static std::unique_ptr<FakeRecordingSource> CreateFilledRecordingSource( | 41 static std::unique_ptr<FakeRecordingSource> CreateFilledRecordingSource( |
| 42 const gfx::Size& layer_bounds) { | 42 const gfx::Size& layer_bounds) { |
| 43 std::unique_ptr<FakeRecordingSource> recording_source( | 43 std::unique_ptr<FakeRecordingSource> recording_source( |
| 44 new FakeRecordingSource); | 44 new FakeRecordingSource); |
| 45 recording_source->SetRecordedViewport(gfx::Rect(layer_bounds)); | 45 recording_source->SetRecordedViewport(gfx::Rect(layer_bounds)); |
|
Menglin
2016/07/26 17:49:42
same here
| |
| 46 recording_source->SetLayerBounds(layer_bounds); | 46 recording_source->SetLayerBounds(layer_bounds); |
| 47 return recording_source; | 47 return recording_source; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // RecordingSource overrides. | 50 // RecordingSource overrides. |
| 51 scoped_refptr<RasterSource> CreateRasterSource( | 51 scoped_refptr<RasterSource> CreateRasterSource( |
| 52 bool can_use_lcd) const override; | 52 bool can_use_lcd) const override; |
| 53 bool IsSuitableForGpuRasterization() 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) { | 58 void SetRecordedViewport(const gfx::Rect& recorded_viewport) { |
| 60 recorded_viewport_ = recorded_viewport; | 59 recorded_viewport_ = recorded_viewport; |
| 61 } | 60 } |
| 62 | 61 |
| 63 void SetLayerBounds(const gfx::Size& layer_bounds) { | 62 void SetLayerBounds(const gfx::Size& layer_bounds) { |
| 64 size_ = layer_bounds; | 63 size_ = layer_bounds; |
| 65 client_.set_bounds(layer_bounds); | 64 client_.set_bounds(layer_bounds); |
| 66 } | 65 } |
| 67 | 66 |
| 68 void SetClearCanvasWithDebugColor(bool clear) { | 67 void SetClearCanvasWithDebugColor(bool clear) { |
| 69 clear_canvas_with_debug_color_ = clear; | 68 clear_canvas_with_debug_color_ = clear; |
| 70 } | 69 } |
| 71 | 70 |
| 72 void Rerecord() { | 71 void Rerecord() { |
| 73 SetNeedsDisplayRect(recorded_viewport_); | 72 SetNeedsDisplayRect(recorded_viewport_); |
| 74 Region invalidation; | 73 Region invalidation; |
| 75 UpdateAndExpandInvalidation(&client_, &invalidation, size_, 0, | 74 gfx::Rect new_recorded_viewport = client_.PaintableRegion(); |
| 76 RECORD_NORMALLY); | 75 scoped_refptr<DisplayItemList> display_list = |
| 76 client_.PaintContentsToDisplayList( | |
| 77 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | |
| 78 size_t painter_reported_memory_usage = | |
| 79 client_.GetApproximateUnsharedMemoryUsage(); | |
| 80 UpdateAndExpandInvalidation(&client_, &invalidation, size_, | |
| 81 new_recorded_viewport, display_list, | |
| 82 painter_reported_memory_usage); | |
| 77 } | 83 } |
| 78 | 84 |
| 79 void add_draw_rect(const gfx::Rect& rect) { | 85 void add_draw_rect(const gfx::Rect& rect) { |
| 80 client_.add_draw_rect(rect, default_paint_); | 86 client_.add_draw_rect(rect, default_paint_); |
| 81 } | 87 } |
| 82 | 88 |
| 83 void add_draw_rect_with_paint(const gfx::Rect& rect, const SkPaint& paint) { | 89 void add_draw_rect_with_paint(const gfx::Rect& rect, const SkPaint& paint) { |
| 84 client_.add_draw_rect(rect, paint); | 90 client_.add_draw_rect(rect, paint); |
| 85 } | 91 } |
| 86 | 92 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 112 | 118 |
| 113 void set_reported_memory_usage(size_t reported_memory_usage) { | 119 void set_reported_memory_usage(size_t reported_memory_usage) { |
| 114 client_.set_reported_memory_usage(reported_memory_usage); | 120 client_.set_reported_memory_usage(reported_memory_usage); |
| 115 } | 121 } |
| 116 | 122 |
| 117 void reset_draws() { | 123 void reset_draws() { |
| 118 client_ = FakeContentLayerClient(); | 124 client_ = FakeContentLayerClient(); |
| 119 client_.set_bounds(size_); | 125 client_.set_bounds(size_); |
| 120 } | 126 } |
| 121 | 127 |
| 122 void SetForceUnsuitableForGpuRasterization(bool flag) { | |
| 123 force_unsuitable_for_gpu_rasterization_ = flag; | |
| 124 } | |
| 125 | |
| 126 void SetPlaybackAllowedEvent(base::WaitableEvent* event) { | 128 void SetPlaybackAllowedEvent(base::WaitableEvent* event) { |
| 127 playback_allowed_event_ = event; | 129 playback_allowed_event_ = event; |
| 128 } | 130 } |
| 129 | 131 |
| 130 DisplayItemList* display_list() const { return display_list_.get(); } | |
| 131 | |
| 132 // Checks that the basic properties of the |other| match |this|. For the | 132 // Checks that the basic properties of the |other| match |this|. For the |
| 133 // DisplayItemList, it checks that the painted result matches the painted | 133 // DisplayItemList, it checks that the painted result matches the painted |
| 134 // result of |other|. | 134 // result of |other|. |
| 135 bool EqualsTo(const FakeRecordingSource& other); | 135 bool EqualsTo(const FakeRecordingSource& other); |
| 136 | 136 |
| 137 private: | 137 private: |
| 138 FakeContentLayerClient client_; | 138 FakeContentLayerClient client_; |
| 139 SkPaint default_paint_; | 139 SkPaint default_paint_; |
| 140 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 |