OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkAutoPixmapStorage.h" | 8 #include "SkAutoPixmapStorage.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkImage.h" | 11 #include "SkImage.h" |
12 #include "SkPixmap.h" | 12 #include "SkPixmap.h" |
13 #include "SkSpecialImage.h" | 13 #include "SkSpecialImage.h" |
14 #include "SkSpecialSurface.h" | 14 #include "SkSpecialSurface.h" |
| 15 #include "SkSurface.h" |
15 #include "Test.h" | 16 #include "Test.h" |
16 #include "TestingSpecialImageAccess.h" | 17 #include "TestingSpecialImageAccess.h" |
17 | 18 |
18 #if SK_SUPPORT_GPU | 19 #if SK_SUPPORT_GPU |
19 #include "GrContext.h" | 20 #include "GrContext.h" |
20 #endif | 21 #endif |
21 | 22 |
22 | 23 |
23 // This test creates backing resources exactly sized to [kFullSize x kFullSize]. | 24 // This test creates backing resources exactly sized to [kFullSize x kFullSize]. |
24 // It then wraps them in an SkSpecialImage with only the center (red) region bei
ng active. | 25 // It then wraps them in an SkSpecialImage with only the center (red) region bei
ng active. |
(...skipping 27 matching lines...) Expand all Loading... |
52 static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
orter, | 53 static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
orter, |
53 bool peekPixelsSucceeds, bool peekTextureSucceeds, | 54 bool peekPixelsSucceeds, bool peekTextureSucceeds, |
54 int offset, int size) { | 55 int offset, int size) { |
55 const SkIRect subset = TestingSpecialImageAccess::Subset(img.get()); | 56 const SkIRect subset = TestingSpecialImageAccess::Subset(img.get()); |
56 REPORTER_ASSERT(reporter, offset == subset.left()); | 57 REPORTER_ASSERT(reporter, offset == subset.left()); |
57 REPORTER_ASSERT(reporter, offset == subset.top()); | 58 REPORTER_ASSERT(reporter, offset == subset.top()); |
58 REPORTER_ASSERT(reporter, kSmallerSize == subset.width()); | 59 REPORTER_ASSERT(reporter, kSmallerSize == subset.width()); |
59 REPORTER_ASSERT(reporter, kSmallerSize == subset.height()); | 60 REPORTER_ASSERT(reporter, kSmallerSize == subset.height()); |
60 | 61 |
61 //-------------- | 62 //-------------- |
| 63 // Test that peekTexture reports the correct backing type |
62 REPORTER_ASSERT(reporter, peekTextureSucceeds == | 64 REPORTER_ASSERT(reporter, peekTextureSucceeds == |
63 !!TestingSpecialImageAccess::PeekTexture
(img.get())); | 65 !!TestingSpecialImageAccess::PeekTexture
(img.get())); |
64 | 66 |
65 //-------------- | 67 //-------------- |
| 68 // Test that peekPixels reports the correct backing type |
66 SkPixmap pixmap; | 69 SkPixmap pixmap; |
67 REPORTER_ASSERT(reporter, peekPixelsSucceeds == | 70 REPORTER_ASSERT(reporter, peekPixelsSucceeds == |
68 !!TestingSpecialImageAccess::PeekPixels(img.get(),
&pixmap)); | 71 !!TestingSpecialImageAccess::PeekPixels(img.get(),
&pixmap)); |
69 if (peekPixelsSucceeds) { | 72 if (peekPixelsSucceeds) { |
70 REPORTER_ASSERT(reporter, size == pixmap.width()); | 73 REPORTER_ASSERT(reporter, size == pixmap.width()); |
71 REPORTER_ASSERT(reporter, size == pixmap.height()); | 74 REPORTER_ASSERT(reporter, size == pixmap.height()); |
72 } | 75 } |
73 | 76 |
74 //-------------- | 77 //-------------- |
| 78 // Test that draw restricts itself to the subset |
75 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph
aType); | 79 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph
aType); |
76 | 80 |
77 sk_sp<SkSpecialSurface> surf(img->makeSurface(info)); | 81 sk_sp<SkSpecialSurface> surf(img->makeSurface(info)); |
78 | 82 |
79 SkCanvas* canvas = surf->getCanvas(); | 83 SkCanvas* canvas = surf->getCanvas(); |
80 | 84 |
81 canvas->clear(SK_ColorBLUE); | 85 canvas->clear(SK_ColorBLUE); |
82 img->draw(canvas, SkIntToScalar(kPad), SkIntToScalar(kPad), nullptr); | 86 img->draw(canvas, SkIntToScalar(kPad), SkIntToScalar(kPad), nullptr); |
83 | 87 |
84 SkBitmap bm; | 88 SkBitmap bm; |
85 bm.allocN32Pixels(kFullSize, kFullSize, true); | 89 bm.allocN32Pixels(kFullSize, kFullSize, true); |
86 | 90 |
87 bool result = canvas->readPixels(bm.info(), bm.getPixels(), bm.rowBytes(), 0
, 0); | 91 bool result = canvas->readPixels(bm.info(), bm.getPixels(), bm.rowBytes(), 0
, 0); |
88 SkASSERT_RELEASE(result); | 92 SkASSERT_RELEASE(result); |
89 | 93 |
90 // Only the center (red) portion should've been drawn into the canvas | 94 // Only the center (red) portion should've been drawn into the canvas |
91 REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kPad-1, kPad-1)); | 95 REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kPad-1, kPad-1)); |
92 REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kPad, kPad)); | 96 REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kPad, kPad)); |
93 REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kSmallerSize+kPad-1, | 97 REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kSmallerSize+kPad-1, |
94 kSmallerSize+kPad-1)); | 98 kSmallerSize+kPad-1)); |
95 REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kSmallerSize+kPad, | 99 REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kSmallerSize+kPad, |
96 kSmallerSize+kPad)); | 100 kSmallerSize+kPad)); |
| 101 |
| 102 //-------------- |
| 103 // Test that makeTightSubset & makeTightSurface return appropriately sized o
bjects |
| 104 // of the correct backing type |
| 105 SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height()); |
| 106 { |
| 107 sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset)); |
| 108 |
| 109 REPORTER_ASSERT(reporter, tightImg->width() == subset.width()); |
| 110 REPORTER_ASSERT(reporter, tightImg->height() == subset.height()); |
| 111 REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture(
)); |
| 112 SkPixmap tmpPixmap; |
| 113 REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightImg->peekPixels(&
tmpPixmap)); |
| 114 } |
| 115 { |
| 116 SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), |
| 117 kPremul_SkAlphaType); |
| 118 sk_sp<SkSurface> tightSurf(img->makeTightSurface(info)); |
| 119 |
| 120 REPORTER_ASSERT(reporter, tightSurf->width() == subset.width()); |
| 121 REPORTER_ASSERT(reporter, tightSurf->height() == subset.height()); |
| 122 REPORTER_ASSERT(reporter, peekTextureSucceeds == |
| 123 !!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_Back
endHandleAccess)); |
| 124 SkPixmap tmpPixmap; |
| 125 REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightSurf->peekPixels(
&tmpPixmap)); |
| 126 } |
97 } | 127 } |
98 | 128 |
99 DEF_TEST(SpecialImage_Raster, reporter) { | 129 DEF_TEST(SpecialImage_Raster, reporter) { |
100 SkBitmap bm = create_bm(); | 130 SkBitmap bm = create_bm(); |
101 | 131 |
102 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromRaster( | 132 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromRaster( |
103 nullptr, | 133 nullptr, |
104 SkIRect::MakeWH(kFul
lSize, kFullSize), | 134 SkIRect::MakeWH(kFul
lSize, kFullSize), |
105 bm)); | 135 bm)); |
106 | 136 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 test_image(subSImg1, reporter, false, true, kPad, kFullSize); | 311 test_image(subSImg1, reporter, false, true, kPad, kFullSize); |
282 } | 312 } |
283 | 313 |
284 { | 314 { |
285 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); | 315 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
286 test_image(subSImg2, reporter, false, true, kPad, kFullSize); | 316 test_image(subSImg2, reporter, false, true, kPad, kFullSize); |
287 } | 317 } |
288 } | 318 } |
289 | 319 |
290 #endif | 320 #endif |
OLD | NEW |