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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return SkImage::NewRasterCopy(info, addr.get(), rowBytes); | 96 return SkImage::NewRasterCopy(info, addr.get(), rowBytes); |
97 } | 97 } |
98 | 98 |
99 // Test out the layer replacement functionality with and w/o a BBH | 99 // Test out the layer replacement functionality with and w/o a BBH |
100 void test_replacements(skiatest::Reporter* r, bool useBBH) { | 100 void test_replacements(skiatest::Reporter* r, bool useBBH) { |
101 SkAutoTUnref<const SkPicture> pic; | 101 SkAutoTUnref<const SkPicture> pic; |
102 | 102 |
103 { | 103 { |
104 SkRTreeFactory bbhFactory; | 104 SkRTreeFactory bbhFactory; |
105 SkPictureRecorder recorder; | 105 SkPictureRecorder recorder; |
106 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight), | 106 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT
oScalar(kHeight), |
107 useBBH ? &bbhFactory : NULL); | 107 useBBH ? &bbhFactory : NULL); |
108 | 108 |
109 SkAutoTDelete<SkPaint> paint(SkNEW(SkPaint)); | 109 SkAutoTDelete<SkPaint> paint(SkNEW(SkPaint)); |
110 canvas->saveLayer(NULL, paint); | 110 canvas->saveLayer(NULL, paint); |
111 canvas->clear(SK_ColorRED); | 111 canvas->clear(SK_ColorRED); |
112 canvas->restore(); | 112 canvas->restore(); |
113 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar
(kHeight / 2)), | 113 canvas->drawRect(SkRect::MakeWH(SkIntToScalar(kWidth / 2), SkIntToScalar
(kHeight / 2)), |
114 SkPaint()); | 114 SkPaint()); |
115 pic.reset(recorder.endRecording()); | 115 pic.reset(recorder.endRecording()); |
116 } | 116 } |
117 | 117 |
118 GrReplacements replacements; | 118 GrReplacements replacements; |
119 GrReplacements::ReplacementInfo* ri = replacements.newReplacement(pic->uniqu
eID(), | 119 GrReplacements::ReplacementInfo* ri = replacements.newReplacement(pic->uniqu
eID(), |
120 0, SkMatri
x::I()); | 120 0, SkMatri
x::I()); |
121 ri->fStop = 2; | 121 ri->fStop = 2; |
122 ri->fPos.set(0, 0); | 122 ri->fPos.set(0, 0); |
123 ri->fImage = make_image(SK_ColorRED); | 123 ri->fImage = make_image(SK_ColorRED); |
124 ri->fPaint = SkNEW(SkPaint); | 124 ri->fPaint = SkNEW(SkPaint); |
125 ri->fSrcRect = SkIRect::MakeWH(kWidth, kHeight); | 125 ri->fSrcRect = SkIRect::MakeWH(kWidth, kHeight); |
126 | 126 |
127 SkAutoTUnref<SkBBoxHierarchy> bbh; | 127 SkAutoTUnref<SkBBoxHierarchy> bbh; |
128 | 128 |
129 SkRecord rerecord; | 129 SkRecord rerecord; |
130 SkRecorder canvas(&rerecord, kWidth, kHeight); | 130 SkRecorder canvas(&rerecord, kWidth, kHeight); |
131 GrRecordReplaceDraw(pic, &canvas, &replacements, SkMatrix::I(), NULL/*callba
ck*/); | 131 GrRecordReplaceDraw(pic, &canvas, &replacements, SkMatrix::I(), NULL/*callba
ck*/); |
132 | 132 |
133 REPORTER_ASSERT(r, 7 == rerecord.count()); | 133 REPORTER_ASSERT(r, 7 == rerecord.count()); |
134 assert_type<SkRecords::Save>(r, rerecord, 0); | 134 assert_type<SkRecords::Save>(r, rerecord, 0); |
135 assert_type<SkRecords::Save>(r, rerecord, 1); | 135 assert_type<SkRecords::Save>(r, rerecord, 1); |
136 assert_type<SkRecords::SetMatrix>(r, rerecord, 2); | 136 assert_type<SkRecords::SetMatrix>(r, rerecord, 2); |
137 assert_type<SkRecords::DrawImageRect>(r, rerecord, 3); | 137 assert_type<SkRecords::DrawImageRect>(r, rerecord, 3); |
138 assert_type<SkRecords::Restore>(r, rerecord, 4); | 138 assert_type<SkRecords::Restore>(r, rerecord, 4); |
139 assert_type<SkRecords::DrawRect>(r, rerecord, 5); | 139 assert_type<SkRecords::DrawRect>(r, rerecord, 5); |
140 assert_type<SkRecords::Restore>(r, rerecord, 6); | 140 assert_type<SkRecords::Restore>(r, rerecord, 6); |
141 } | 141 } |
142 | 142 |
143 DEF_TEST(RecordReplaceDraw_Replace, r) { test_replacements(r, false); } | 143 DEF_TEST(RecordReplaceDraw_Replace, r) { test_replacements(r, false); } |
144 DEF_TEST(RecordReplaceDraw_ReplaceWithBBH, r) { test_replacements(r, true); } | 144 DEF_TEST(RecordReplaceDraw_ReplaceWithBBH, r) { test_replacements(r, true); } |
145 | 145 |
146 #endif | 146 #endif |
OLD | NEW |