| 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/resources/clip_display_item.h" | 7 #include "cc/resources/clip_display_item.h" |
| 8 #include "cc/resources/drawing_display_item.h" | 8 #include "cc/resources/drawing_display_item.h" |
| 9 #include "cc/resources/transform_display_item.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkPictureRecorder.h" | 11 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 11 #include "ui/gfx/skia_util.h" | 12 #include "ui/gfx/skia_util.h" |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 14 | 15 |
| 16 FakeContentLayerClient::BitmapData::BitmapData(const SkBitmap& bitmap, |
| 17 const gfx::Point& point, |
| 18 const SkPaint& paint) |
| 19 : bitmap(bitmap), point(point), paint(paint) { |
| 20 } |
| 21 |
| 22 FakeContentLayerClient::BitmapData::BitmapData(const SkBitmap& bitmap, |
| 23 const gfx::Transform& transform, |
| 24 const SkPaint& paint) |
| 25 : bitmap(bitmap), transform(transform), paint(paint) { |
| 26 } |
| 27 |
| 28 FakeContentLayerClient::BitmapData::~BitmapData() { |
| 29 } |
| 30 |
| 15 FakeContentLayerClient::FakeContentLayerClient() | 31 FakeContentLayerClient::FakeContentLayerClient() |
| 16 : fill_with_nonsolid_color_(false), last_canvas_(NULL) { | 32 : fill_with_nonsolid_color_(false), last_canvas_(NULL) { |
| 17 } | 33 } |
| 18 | 34 |
| 19 FakeContentLayerClient::~FakeContentLayerClient() { | 35 FakeContentLayerClient::~FakeContentLayerClient() { |
| 20 } | 36 } |
| 21 | 37 |
| 22 void FakeContentLayerClient::PaintContents( | 38 void FakeContentLayerClient::PaintContents( |
| 23 SkCanvas* canvas, | 39 SkCanvas* canvas, |
| 24 const gfx::Rect& paint_rect, | 40 const gfx::Rect& paint_rect, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 canvas = | 88 canvas = |
| 73 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | 89 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
| 74 canvas->drawRectCoords(draw_rect.x(), draw_rect.y(), draw_rect.width(), | 90 canvas->drawRectCoords(draw_rect.x(), draw_rect.y(), draw_rect.width(), |
| 75 draw_rect.height(), paint); | 91 draw_rect.height(), paint); |
| 76 picture = skia::AdoptRef(recorder.endRecording()); | 92 picture = skia::AdoptRef(recorder.endRecording()); |
| 77 list->AppendItem(DrawingDisplayItem::Create(picture)); | 93 list->AppendItem(DrawingDisplayItem::Create(picture)); |
| 78 } | 94 } |
| 79 | 95 |
| 80 for (BitmapVector::const_iterator it = draw_bitmaps_.begin(); | 96 for (BitmapVector::const_iterator it = draw_bitmaps_.begin(); |
| 81 it != draw_bitmaps_.end(); ++it) { | 97 it != draw_bitmaps_.end(); ++it) { |
| 98 if (!it->transform.IsIdentity()) { |
| 99 list->AppendItem(TransformDisplayItem::Create(it->transform)); |
| 100 } |
| 82 canvas = skia::SharePtr( | 101 canvas = skia::SharePtr( |
| 83 recorder.beginRecording(it->bitmap.width(), it->bitmap.height())); | 102 recorder.beginRecording(it->bitmap.width(), it->bitmap.height())); |
| 84 canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint); | 103 canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint); |
| 85 picture = skia::AdoptRef(recorder.endRecording()); | 104 picture = skia::AdoptRef(recorder.endRecording()); |
| 86 list->AppendItem(DrawingDisplayItem::Create(picture)); | 105 list->AppendItem(DrawingDisplayItem::Create(picture)); |
| 106 if (!it->transform.IsIdentity()) { |
| 107 list->AppendItem(EndTransformDisplayItem::Create()); |
| 108 } |
| 87 } | 109 } |
| 88 | 110 |
| 89 if (fill_with_nonsolid_color_) { | 111 if (fill_with_nonsolid_color_) { |
| 90 gfx::RectF draw_rect = clip; | 112 gfx::RectF draw_rect = clip; |
| 91 bool red = true; | 113 bool red = true; |
| 92 while (!draw_rect.IsEmpty()) { | 114 while (!draw_rect.IsEmpty()) { |
| 93 SkPaint paint; | 115 SkPaint paint; |
| 94 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); | 116 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); |
| 95 canvas = skia::SharePtr( | 117 canvas = skia::SharePtr( |
| 96 recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | 118 recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
| 97 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); | 119 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); |
| 98 picture = skia::AdoptRef(recorder.endRecording()); | 120 picture = skia::AdoptRef(recorder.endRecording()); |
| 99 list->AppendItem(DrawingDisplayItem::Create(picture)); | 121 list->AppendItem(DrawingDisplayItem::Create(picture)); |
| 100 draw_rect.Inset(1, 1); | 122 draw_rect.Inset(1, 1); |
| 101 } | 123 } |
| 102 } | 124 } |
| 103 | 125 |
| 104 list->AppendItem(EndClipDisplayItem::Create()); | 126 list->AppendItem(EndClipDisplayItem::Create()); |
| 105 return list; | 127 return list; |
| 106 } | 128 } |
| 107 | 129 |
| 108 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } | 130 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } |
| 109 | 131 |
| 110 } // namespace cc | 132 } // namespace cc |
| OLD | NEW |