| 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" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "third_party/skia/include/core/SkPictureRecorder.h" | 12 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 13 #include "ui/gfx/geometry/rect_conversions.h" |
| 13 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 | 17 |
| 17 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, | 18 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, |
| 18 const gfx::Point& point, | 19 const gfx::Point& point, |
| 19 const SkPaint& paint) | 20 const SkPaint& paint) |
| 20 : image(skia::SharePtr(img)), point(point), paint(paint) {} | 21 : image(skia::SharePtr(img)), point(point), paint(paint) {} |
| 21 | 22 |
| 22 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, | 23 FakeContentLayerClient::ImageData::ImageData(const SkImage* img, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 41 PaintingControlSetting painting_control) { | 42 PaintingControlSetting painting_control) { |
| 42 // Cached picture is used because unit tests expect to be able to | 43 // Cached picture is used because unit tests expect to be able to |
| 43 // use GatherPixelRefs. | 44 // use GatherPixelRefs. |
| 44 DisplayItemListSettings settings; | 45 DisplayItemListSettings settings; |
| 45 settings.use_cached_picture = true; | 46 settings.use_cached_picture = true; |
| 46 scoped_refptr<DisplayItemList> display_list = | 47 scoped_refptr<DisplayItemList> display_list = |
| 47 DisplayItemList::Create(clip, settings); | 48 DisplayItemList::Create(clip, settings); |
| 48 SkPictureRecorder recorder; | 49 SkPictureRecorder recorder; |
| 49 skia::RefPtr<SkCanvas> canvas; | 50 skia::RefPtr<SkCanvas> canvas; |
| 50 skia::RefPtr<SkPicture> picture; | 51 skia::RefPtr<SkPicture> picture; |
| 51 auto* item = display_list->CreateAndAppendItem<ClipDisplayItem>(); | 52 auto* item = display_list->CreateAndAppendItem<ClipDisplayItem>(clip); |
| 52 item->SetNew(clip, std::vector<SkRRect>()); | 53 item->SetNew(clip, std::vector<SkRRect>()); |
| 53 | 54 |
| 54 for (RectPaintVector::const_iterator it = draw_rects_.begin(); | 55 for (RectPaintVector::const_iterator it = draw_rects_.begin(); |
| 55 it != draw_rects_.end(); ++it) { | 56 it != draw_rects_.end(); ++it) { |
| 56 const gfx::RectF& draw_rect = it->first; | 57 const gfx::RectF& draw_rect = it->first; |
| 57 const SkPaint& paint = it->second; | 58 const SkPaint& paint = it->second; |
| 58 canvas = | 59 canvas = |
| 59 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | 60 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
| 60 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); | 61 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); |
| 61 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 62 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 62 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 63 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>( |
| 64 ToEnclosingRect(draw_rect)); |
| 63 item->SetNew(picture.Pass()); | 65 item->SetNew(picture.Pass()); |
| 64 } | 66 } |
| 65 | 67 |
| 66 for (ImageVector::const_iterator it = draw_images_.begin(); | 68 for (ImageVector::const_iterator it = draw_images_.begin(); |
| 67 it != draw_images_.end(); ++it) { | 69 it != draw_images_.end(); ++it) { |
| 68 if (!it->transform.IsIdentity()) { | 70 if (!it->transform.IsIdentity()) { |
| 69 auto* item = display_list->CreateAndAppendItem<TransformDisplayItem>(); | 71 auto* item = |
| 72 display_list->CreateAndAppendItem<TransformDisplayItem>(clip); |
| 70 item->SetNew(it->transform); | 73 item->SetNew(it->transform); |
| 71 } | 74 } |
| 72 canvas = skia::SharePtr( | 75 canvas = skia::SharePtr( |
| 73 recorder.beginRecording(it->image->width(), it->image->height())); | 76 recorder.beginRecording(it->image->width(), it->image->height())); |
| 74 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), | 77 canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), |
| 75 &it->paint); | 78 &it->paint); |
| 76 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 79 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 77 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 80 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(clip); |
| 78 item->SetNew(picture.Pass()); | 81 item->SetNew(picture.Pass()); |
| 79 if (!it->transform.IsIdentity()) { | 82 if (!it->transform.IsIdentity()) { |
| 80 display_list->CreateAndAppendItem<EndTransformDisplayItem>(); | 83 display_list->CreateAndAppendItem<EndTransformDisplayItem>(clip); |
| 81 } | 84 } |
| 82 } | 85 } |
| 83 | 86 |
| 84 if (fill_with_nonsolid_color_) { | 87 if (fill_with_nonsolid_color_) { |
| 85 gfx::Rect draw_rect = clip; | 88 gfx::Rect draw_rect = clip; |
| 86 bool red = true; | 89 bool red = true; |
| 87 while (!draw_rect.IsEmpty()) { | 90 while (!draw_rect.IsEmpty()) { |
| 88 SkPaint paint; | 91 SkPaint paint; |
| 89 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); | 92 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); |
| 90 canvas = | 93 canvas = |
| 91 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); | 94 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(draw_rect))); |
| 92 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); | 95 canvas->drawIRect(gfx::RectToSkIRect(draw_rect), paint); |
| 93 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); | 96 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 94 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); | 97 auto* item = |
| 98 display_list->CreateAndAppendItem<DrawingDisplayItem>(draw_rect); |
| 95 item->SetNew(picture.Pass()); | 99 item->SetNew(picture.Pass()); |
| 96 draw_rect.Inset(1, 1); | 100 draw_rect.Inset(1, 1); |
| 97 } | 101 } |
| 98 } | 102 } |
| 99 | 103 |
| 100 display_list->CreateAndAppendItem<EndClipDisplayItem>(); | 104 display_list->CreateAndAppendItem<EndClipDisplayItem>(clip); |
| 101 | 105 |
| 102 display_list->Finalize(); | 106 display_list->Finalize(); |
| 103 return display_list; | 107 return display_list; |
| 104 } | 108 } |
| 105 | 109 |
| 106 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } | 110 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } |
| 107 | 111 |
| 108 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { | 112 size_t FakeContentLayerClient::GetApproximateUnsharedMemoryUsage() const { |
| 109 return reported_memory_usage_; | 113 return reported_memory_usage_; |
| 110 } | 114 } |
| 111 | 115 |
| 112 } // namespace cc | 116 } // namespace cc |
| OLD | NEW |