| 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 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHe
ight)), SkPaint()); | 43 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHe
ight)), SkPaint()); |
| 44 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHe
ight))); | 44 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHe
ight))); |
| 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, nullptr, SkMatrix::I(), &callback); |
| 54 | 54 |
| 55 switch (rerecord.count()) { | 55 switch (rerecord.count()) { |
| 56 case 3: | 56 case 3: |
| 57 assert_type<SkRecords::Save>(r, rerecord, 0); | 57 assert_type<SkRecords::Save>(r, rerecord, 0); |
| 58 assert_type<SkRecords::DrawRect>(r, rerecord, 1); | 58 assert_type<SkRecords::DrawRect>(r, rerecord, 1); |
| 59 assert_type<SkRecords::Restore>(r, rerecord, 2); | 59 assert_type<SkRecords::Restore>(r, rerecord, 2); |
| 60 break; | 60 break; |
| 61 case 1: | 61 case 1: |
| 62 assert_type<SkRecords::DrawRect>(r, rerecord, 0); | 62 assert_type<SkRecords::DrawRect>(r, rerecord, 0); |
| 63 break; | 63 break; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 | 76 |
| 77 // We won't balance this, but GrRecordReplaceDraw will for us. | 77 // We won't balance this, but GrRecordReplaceDraw will for us. |
| 78 canvas->save(); | 78 canvas->save(); |
| 79 canvas->scale(2, 2); | 79 canvas->scale(2, 2); |
| 80 pic.reset(recorder.endRecording()); | 80 pic.reset(recorder.endRecording()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 SkRecord rerecord; | 83 SkRecord rerecord; |
| 84 SkRecorder canvas(&rerecord, kWidth, kHeight); | 84 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 85 | 85 |
| 86 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), NULL/*callback*/); | 86 GrRecordReplaceDraw(pic, &canvas, nullptr, SkMatrix::I(), nullptr/*callback*
/); |
| 87 | 87 |
| 88 // ensure rerecord is balanced (in this case by checking that the count is o
dd) | 88 // ensure rerecord is balanced (in this case by checking that the count is o
dd) |
| 89 REPORTER_ASSERT(r, (rerecord.count() & 1) == 1); | 89 REPORTER_ASSERT(r, (rerecord.count() & 1) == 1); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Test out the layer replacement functionality with and w/o a BBH | 92 // Test out the layer replacement functionality with and w/o a BBH |
| 93 void test_replacements(skiatest::Reporter* r, GrContext* context, bool useBBH) { | 93 void test_replacements(skiatest::Reporter* r, GrContext* context, bool useBBH) { |
| 94 SkAutoTUnref<const SkPicture> pic; | 94 SkAutoTUnref<const SkPicture> pic; |
| 95 | 95 |
| 96 { | 96 { |
| 97 SkRTreeFactory bbhFactory; | 97 SkRTreeFactory bbhFactory; |
| 98 SkPictureRecorder recorder; | 98 SkPictureRecorder recorder; |
| 99 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight), | 99 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight), |
| 100 useBBH ? &bbhFactory : NULL); | 100 useBBH ? &bbhFactory : nullpt
r); |
| 101 | 101 |
| 102 SkPaint paint; | 102 SkPaint paint; |
| 103 canvas->saveLayer(NULL, &paint); | 103 canvas->saveLayer(nullptr, &paint); |
| 104 canvas->clear(SK_ColorRED); | 104 canvas->clear(SK_ColorRED); |
| 105 canvas->restore(); | 105 canvas->restore(); |
| 106 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar
(kHeight / 2)), | 106 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar
(kHeight / 2)), |
| 107 SkPaint()); | 107 SkPaint()); |
| 108 pic.reset(recorder.endRecording()); | 108 pic.reset(recorder.endRecording()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 int key[1] = { 0 }; | 111 int key[1] = { 0 }; |
| 112 | 112 |
| 113 SkPaint paint; | 113 SkPaint paint; |
| 114 GrLayerCache* layerCache = context->getLayerCache(); | 114 GrLayerCache* layerCache = context->getLayerCache(); |
| 115 GrCachedLayer* layer = layerCache->findLayerOrCreate(pic->uniqueID(), 0, 2, | 115 GrCachedLayer* layer = layerCache->findLayerOrCreate(pic->uniqueID(), 0, 2, |
| 116 SkIRect::MakeWH(kWidth,
kHeight), | 116 SkIRect::MakeWH(kWidth,
kHeight), |
| 117 SkIRect::MakeWH(kWidth,
kHeight), | 117 SkIRect::MakeWH(kWidth,
kHeight), |
| 118 SkMatrix::I(), key, 1,
&paint); | 118 SkMatrix::I(), key, 1,
&paint); |
| 119 | 119 |
| 120 GrSurfaceDesc desc; | 120 GrSurfaceDesc desc; |
| 121 desc.fConfig = kSkia8888_GrPixelConfig; | 121 desc.fConfig = kSkia8888_GrPixelConfig; |
| 122 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 122 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 123 desc.fWidth = kWidth; | 123 desc.fWidth = kWidth; |
| 124 desc.fHeight = kHeight; | 124 desc.fHeight = kHeight; |
| 125 desc.fSampleCnt = 0; | 125 desc.fSampleCnt = 0; |
| 126 | 126 |
| 127 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, | 127 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de
sc, |
| 128 false, NULL, 0)); | 128 false, nullptr, 0)); |
| 129 layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight)); | 129 layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight)); |
| 130 | 130 |
| 131 SkAutoTUnref<SkBBoxHierarchy> bbh; | 131 SkAutoTUnref<SkBBoxHierarchy> bbh; |
| 132 | 132 |
| 133 SkRecord rerecord; | 133 SkRecord rerecord; |
| 134 SkRecorder canvas(&rerecord, kWidth, kHeight); | 134 SkRecorder canvas(&rerecord, kWidth, kHeight); |
| 135 GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), NULL/*callback*
/); | 135 GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), nullptr/*callba
ck*/); |
| 136 | 136 |
| 137 int recount = rerecord.count(); | 137 int recount = rerecord.count(); |
| 138 REPORTER_ASSERT(r, 2 == recount || 4 == recount); | 138 REPORTER_ASSERT(r, 2 == recount || 4 == recount); |
| 139 | 139 |
| 140 int index = 0; | 140 int index = 0; |
| 141 if (4 == recount) { | 141 if (4 == recount) { |
| 142 assert_type<SkRecords::Save>(r, rerecord, 0); | 142 assert_type<SkRecords::Save>(r, rerecord, 0); |
| 143 index += 1; | 143 index += 1; |
| 144 } | 144 } |
| 145 assert_type<SkRecords::DrawSprite>(r, rerecord, index + 0); | 145 assert_type<SkRecords::DrawSprite>(r, rerecord, index + 0); |
| 146 assert_type<SkRecords::DrawRect>(r, rerecord, index + 1); | 146 assert_type<SkRecords::DrawRect>(r, rerecord, index + 1); |
| 147 if (4 == recount) { | 147 if (4 == recount) { |
| 148 assert_type<SkRecords::Restore>(r, rerecord, 3); | 148 assert_type<SkRecords::Restore>(r, rerecord, 3); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 DEF_GPUTEST(RecordReplaceDraw, r, factory) { | 152 DEF_GPUTEST(RecordReplaceDraw, r, factory) { |
| 153 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | 153 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { |
| 154 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); | 154 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G
LContextType>(type); |
| 155 if (!GrContextFactory::IsRenderingGLContext(glType)) { | 155 if (!GrContextFactory::IsRenderingGLContext(glType)) { |
| 156 continue; | 156 continue; |
| 157 } | 157 } |
| 158 GrContext* context = factory->get(glType); | 158 GrContext* context = factory->get(glType); |
| 159 if (NULL == context) { | 159 if (nullptr == context) { |
| 160 continue; | 160 continue; |
| 161 } | 161 } |
| 162 | 162 |
| 163 test_replacements(r, context, true); | 163 test_replacements(r, context, true); |
| 164 test_replacements(r, context, false); | 164 test_replacements(r, context, false); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 #endif | 168 #endif |
| OLD | NEW |