| 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 #if SK_SUPPORT_GPU | 8 #if SK_SUPPORT_GPU |
| 9 | 9 |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 pic.reset(recorder.endRecording()); | 46 pic.reset(recorder.endRecording()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 SkRecord rerecord; | 49 SkRecord rerecord; |
| 50 SkRecorder canvas(&rerecord, kWidth, kHeight); | 50 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 51 | 51 |
| 52 JustOneDraw callback; | 52 JustOneDraw callback; |
| 53 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), &callback); | 53 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), &callback); |
| 54 | 54 |
| 55 switch (rerecord.count()) { | 55 REPORTER_ASSERT(r, 3 == rerecord.count()); |
| 56 case 3: | 56 assert_type<SkRecords::Save>(r, rerecord, 0); |
| 57 assert_type<SkRecords::Save>(r, rerecord, 0); | 57 assert_type<SkRecords::DrawRect>(r, rerecord, 1); |
| 58 assert_type<SkRecords::DrawRect>(r, rerecord, 1); | 58 assert_type<SkRecords::Restore>(r, rerecord, 2); |
| 59 assert_type<SkRecords::Restore>(r, rerecord, 2); | |
| 60 break; | |
| 61 case 1: | |
| 62 assert_type<SkRecords::DrawRect>(r, rerecord, 0); | |
| 63 break; | |
| 64 default: | |
| 65 REPORTER_ASSERT(r, false); | |
| 66 } | |
| 67 } | 59 } |
| 68 | 60 |
| 69 // Make sure GrRecordReplaceDraw balances unbalanced saves | 61 // Make sure GrRecordReplaceDraw balances unbalanced saves |
| 70 DEF_TEST(RecordReplaceDraw_Unbalanced, r) { | 62 DEF_TEST(RecordReplaceDraw_Unbalanced, r) { |
| 71 SkAutoTUnref<const SkPicture> pic; | 63 SkAutoTUnref<const SkPicture> pic; |
| 72 | 64 |
| 73 { | 65 { |
| 74 SkPictureRecorder recorder; | 66 SkPictureRecorder recorder; |
| 75 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight)); | 67 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight)); |
| 76 | 68 |
| 77 // We won't balance this, but GrRecordReplaceDraw will for us. | 69 // We won't balance this, but GrRecordReplaceDraw will for us. |
| 78 canvas->save(); | 70 canvas->save(); |
| 79 canvas->scale(2, 2); | 71 |
| 80 pic.reset(recorder.endRecording()); | 72 pic.reset(recorder.endRecording()); |
| 81 } | 73 } |
| 82 | 74 |
| 83 SkRecord rerecord; | 75 SkRecord rerecord; |
| 84 SkRecorder canvas(&rerecord, kWidth, kHeight); | 76 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 85 | 77 |
| 86 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), NULL/*callback*/); | 78 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), NULL/*callback*/); |
| 87 | 79 |
| 88 // ensure rerecord is balanced (in this case by checking that the count is e
ven) | 80 REPORTER_ASSERT(r, 4 == rerecord.count()); |
| 89 REPORTER_ASSERT(r, (rerecord.count() & 1) == 0); | 81 assert_type<SkRecords::Save>(r, rerecord, 0); |
| 82 assert_type<SkRecords::Save>(r, rerecord, 1); |
| 83 assert_type<SkRecords::Restore>(r, rerecord, 2); |
| 84 assert_type<SkRecords::Restore>(r, rerecord, 3); |
| 90 } | 85 } |
| 91 | 86 |
| 92 // Test out the layer replacement functionality with and w/o a BBH | 87 // Test out the layer replacement functionality with and w/o a BBH |
| 93 void test_replacements(skiatest::Reporter* r, GrContext* context, bool useBBH) { | 88 void test_replacements(skiatest::Reporter* r, GrContext* context, bool useBBH) { |
| 94 SkAutoTUnref<const SkPicture> pic; | 89 SkAutoTUnref<const SkPicture> pic; |
| 95 | 90 |
| 96 { | 91 { |
| 97 SkRTreeFactory bbhFactory; | 92 SkRTreeFactory bbhFactory; |
| 98 SkPictureRecorder recorder; | 93 SkPictureRecorder recorder; |
| 99 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight), | 94 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 125 | 120 |
| 126 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0
)); | 121 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0
)); |
| 127 layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight)); | 122 layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight)); |
| 128 | 123 |
| 129 SkAutoTUnref<SkBBoxHierarchy> bbh; | 124 SkAutoTUnref<SkBBoxHierarchy> bbh; |
| 130 | 125 |
| 131 SkRecord rerecord; | 126 SkRecord rerecord; |
| 132 SkRecorder canvas(&rerecord, kWidth, kHeight); | 127 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 133 GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), NULL/*callback*
/); | 128 GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), NULL/*callback*
/); |
| 134 | 129 |
| 135 int recount = rerecord.count(); | 130 REPORTER_ASSERT(r, 7 == rerecord.count()); |
| 136 REPORTER_ASSERT(r, 5 == recount || 7 == recount); | 131 assert_type<SkRecords::Save>(r, rerecord, 0); |
| 137 | 132 assert_type<SkRecords::Save>(r, rerecord, 1); |
| 138 int index = 0; | 133 assert_type<SkRecords::SetMatrix>(r, rerecord, 2); |
| 139 if (7 == recount) { | 134 assert_type<SkRecords::DrawBitmapRectToRect>(r, rerecord, 3); |
| 140 assert_type<SkRecords::Save>(r, rerecord, 0); | 135 assert_type<SkRecords::Restore>(r, rerecord, 4); |
| 141 index += 1; | 136 assert_type<SkRecords::DrawRect>(r, rerecord, 5); |
| 142 } | 137 assert_type<SkRecords::Restore>(r, rerecord, 6); |
| 143 assert_type<SkRecords::Save>(r, rerecord, index + 0); | |
| 144 assert_type<SkRecords::SetMatrix>(r, rerecord, index + 1); | |
| 145 assert_type<SkRecords::DrawBitmapRectToRect>(r, rerecord, index + 2); | |
| 146 assert_type<SkRecords::Restore>(r, rerecord, index + 3); | |
| 147 assert_type<SkRecords::DrawRect>(r, rerecord, index + 4); | |
| 148 if (7 == recount) { | |
| 149 assert_type<SkRecords::Restore>(r, rerecord, 6); | |
| 150 } | |
| 151 } | 138 } |
| 152 | 139 |
| 153 DEF_GPUTEST(RecordReplaceDraw, r, factory) { | 140 DEF_GPUTEST(RecordReplaceDraw, r, factory) { |
| 154 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 141 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 155 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 142 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
| 156 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 143 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
| 157 continue; | 144 continue; |
| 158 } | 145 } |
| 159 GrContext* context = factory->get(glType); | 146 GrContext* context = factory->get(glType); |
| 160 if (NULL == context) { | 147 if (NULL == context) { |
| 161 continue; | 148 continue; |
| 162 } | 149 } |
| 163 | 150 |
| 164 test_replacements(r, context, true); | 151 test_replacements(r, context, true); |
| 165 test_replacements(r, context, false); | 152 test_replacements(r, context, false); |
| 166 } | 153 } |
| 167 } | 154 } |
| 168 | 155 |
| 169 #endif | 156 #endif |
| OLD | NEW |