| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "cc/test/fake_content_layer_client.h" | 5 #include "cc/test/fake_content_layer_client.h" |
| 6 | 6 |
| 7 #include "cc/playback/clip_display_item.h" | 7 #include "cc/playback/clip_display_item.h" |
| 8 #include "cc/playback/display_item_list_settings.h" | 8 #include "cc/playback/display_item_list_settings.h" |
| 9 #include "cc/playback/drawing_display_item.h" | 9 #include "cc/playback/drawing_display_item.h" |
| 10 #include "cc/playback/transform_display_item.h" | 10 #include "cc/playback/transform_display_item.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 : fill_with_nonsolid_color_(false), | 30 : fill_with_nonsolid_color_(false), |
| 31 last_canvas_(nullptr), | 31 last_canvas_(nullptr), |
| 32 last_painting_control_(PAINTING_BEHAVIOR_NORMAL), | 32 last_painting_control_(PAINTING_BEHAVIOR_NORMAL), |
| 33 reported_memory_usage_(0) {} | 33 reported_memory_usage_(0) {} |
| 34 | 34 |
| 35 FakeContentLayerClient::~FakeContentLayerClient() { | 35 FakeContentLayerClient::~FakeContentLayerClient() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 scoped_refptr<DisplayItemList> | 38 scoped_refptr<DisplayItemList> |
| 39 FakeContentLayerClient::PaintContentsToDisplayList( | 39 FakeContentLayerClient::PaintContentsToDisplayList( |
| 40 const gfx::Rect& clip, | 40 PaintingControlSetting painting_control, |
| 41 PaintingControlSetting painting_control) { | 41 gfx::Rect* recording_viewport) { |
| 42 // Cached picture is used because unit tests expect to be able to | 42 // Cached picture is used because unit tests expect to be able to |
| 43 // use GatherPixelRefs. | 43 // use GatherPixelRefs. |
| 44 DisplayItemListSettings settings; | 44 DisplayItemListSettings settings; |
| 45 settings.use_cached_picture = true; | 45 settings.use_cached_picture = true; |
| 46 scoped_refptr<DisplayItemList> display_list = | 46 scoped_refptr<DisplayItemList> display_list = |
| 47 DisplayItemList::Create(clip, settings); | 47 DisplayItemList::Create(*recording_viewport, settings); |
| 48 SkPictureRecorder recorder; | 48 SkPictureRecorder recorder; |
| 49 skia::RefPtr<SkCanvas> canvas; | 49 skia::RefPtr<SkCanvas> canvas; |
| 50 skia::RefPtr<SkPicture> picture; | 50 skia::RefPtr<SkPicture> picture; |
| 51 auto* item = display_list->CreateAndAppendItem<ClipDisplayItem>(); | 51 auto* item = display_list->CreateAndAppendItem<ClipDisplayItem>(); |
| 52 item->SetNew(clip, std::vector<SkRRect>()); | 52 item->SetNew(*recording_viewport, std::vector<SkRRect>()); |
| 53 | 53 |
| 54 for (RectPaintVector::const_iterator it = draw_rects_.begin(); | 54 for (RectPaintVector::const_iterator it = draw_rects_.begin(); |
| 55 it != draw_rects_.end(); ++it) { | 55 it != draw_rects_.end(); ++it) { |
| 56 const gfx::RectF& draw_rect = it->first; | 56 const gfx::RectF& draw_rect = it->first; |
| 57 const SkPaint& paint = it->second; | 57 const SkPaint& paint = it->second; |
| 58 canvas = | 58 canvas = |
| 59 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | 59 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
| 60 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); | 60 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); |
| 61 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 61 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 62 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 62 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 75 &it->paint); | 75 &it->paint); |
| 76 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 76 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 77 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 77 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); |
| 78 item->SetNew(picture.Pass()); | 78 item->SetNew(picture.Pass()); |
| 79 if (!it->transform.IsIdentity()) { | 79 if (!it->transform.IsIdentity()) { |
| 80 display_list->CreateAndAppendItem<EndTransformDisplayItem>(); | 80 display_list->CreateAndAppendItem<EndTransformDisplayItem>(); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (fill_with_nonsolid_color_) { | 84 if (fill_with_nonsolid_color_) { |
| 85 gfx::Rect draw_rect = clip; | 85 gfx::Rect draw_rect = *recording_viewport; |
| 86 bool red = true; | 86 bool red = true; |
| 87 while (!draw_rect.IsEmpty()) { | 87 while (!draw_rect.IsEmpty()) { |
| 88 SkPaint paint; | 88 SkPaint paint; |
| 89 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); | 89 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); |
| 90 canvas = | 90 canvas = |
| 91 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); | 91 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); |
| 92 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); | 92 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); |
| 93 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 93 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 94 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 94 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); |
| 95 item->SetNew(picture.Pass()); | 95 item->SetNew(picture.Pass()); |
| 96 draw_rect.Inset(1, 1); | 96 draw_rect.Inset(1, 1); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 display_list->CreateAndAppendItem<EndClipDisplayItem>(); | 100 display_list->CreateAndAppendItem<EndClipDisplayItem>(); |
| 101 | 101 |
| 102 display_list->Finalize(); | 102 display_list->Finalize(); |
| 103 return display_list; | 103 return display_list; |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } | 106 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } |
| 107 | 107 |
| 108 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { | 108 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { |
| 109 return reported_memory_usage_; | 109 return reported_memory_usage_; |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace cc | 112 } // namespace cc |
| OLD | NEW |