Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkDashPathEffect.h" | |
|
reed1
2014/08/18 18:44:04
can remove these adds...
| |
| 11 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
| 12 #include "SkShader.h" | 13 #include "SkShader.h" |
| 14 #include "SkPicture.h" | |
| 13 #include "SkRecord.h" | 15 #include "SkRecord.h" |
| 14 #include "SkRecordAnalysis.h" | |
| 15 #include "SkRecords.h" | 16 #include "SkRecords.h" |
| 16 | 17 |
| 17 // Sums the area of any DrawRect command it sees. | 18 // Sums the area of any DrawRect command it sees. |
| 18 class AreaSummer { | 19 class AreaSummer { |
| 19 public: | 20 public: |
| 20 AreaSummer() : fArea(0) {} | 21 AreaSummer() : fArea(0) {} |
| 21 | 22 |
| 22 template <typename T> void operator()(const T&) { } | 23 template <typename T> void operator()(const T&) { } |
| 23 | 24 |
| 24 void operator()(const SkRecords::DrawRect& draw) { | 25 void operator()(const SkRecords::DrawRect& draw) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 71 |
| 71 // Scale 2x. | 72 // Scale 2x. |
| 72 Stretch stretch; | 73 Stretch stretch; |
| 73 stretch.apply(&record); | 74 stretch.apply(&record); |
| 74 | 75 |
| 75 // Now its area should be 100 + 400. | 76 // Now its area should be 100 + 400. |
| 76 summer.apply(record); | 77 summer.apply(record); |
| 77 REPORTER_ASSERT(r, summer.area() == 500); | 78 REPORTER_ASSERT(r, summer.area() == 500); |
| 78 } | 79 } |
| 79 | 80 |
| 80 DEF_TEST(RecordAnalysis, r) { | |
| 81 SkRecord record; | |
| 82 | |
| 83 SkRect rect = SkRect::MakeWH(10, 10); | |
| 84 SkPaint paint; | |
| 85 APPEND(record, SkRecords::DrawRect, paint, rect); | |
| 86 REPORTER_ASSERT(r, !SkRecordWillPlaybackBitmaps(record)); | |
| 87 | |
| 88 SkBitmap bitmap; | |
| 89 APPEND(record, SkRecords::DrawBitmap, &paint, bitmap, 0.0f, 0.0f); | |
| 90 REPORTER_ASSERT(r, SkRecordWillPlaybackBitmaps(record)); | |
| 91 | |
| 92 SkNEW_PLACEMENT_ARGS(record.replace<SkRecords::DrawRect>(1), | |
| 93 SkRecords::DrawRect, (paint, rect)); | |
| 94 REPORTER_ASSERT(r, !SkRecordWillPlaybackBitmaps(record)); | |
| 95 | |
| 96 SkPaint paint2; | |
| 97 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shader | |
| 98 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here. | |
| 99 SkBitmap bitmap2; | |
| 100 bitmap2.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); | |
| 101 bitmap2.eraseColor(SK_ColorBLUE); | |
| 102 *(bitmap2.getAddr32(0, 0)) = SK_ColorGREEN; | |
| 103 SkShader* shader = SkShader::CreateBitmapShader(bitmap2, SkShader::kClamp_Ti leMode, | |
| 104 SkShader::kClamp_TileMode); | |
| 105 paint2.setShader(shader)->unref(); | |
| 106 REPORTER_ASSERT(r, shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault _BitmapType); | |
| 107 | |
| 108 APPEND(record, SkRecords::DrawRect, paint2, rect); | |
| 109 REPORTER_ASSERT(r, SkRecordWillPlaybackBitmaps(record)); | |
| 110 } | |
| 111 | |
| 112 #undef APPEND | 81 #undef APPEND |
| 113 | 82 |
| OLD | NEW |