| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 <functional> | 8 #include <functional> |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| 11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
| 12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
| 13 #include "SkPath.h" | 13 #include "SkPath.h" |
| 14 #include "SkRRect.h" | 14 #include "SkRRect.h" |
| 15 #include "SkSurface.h" | 15 #include "SkSurface.h" |
| 16 #include "SkUtils.h" | 16 #include "SkUtils.h" |
| 17 #include "Test.h" | 17 #include "Test.h" |
| 18 | 18 |
| 19 #if SK_SUPPORT_GPU | 19 #if SK_SUPPORT_GPU |
| 20 #include "GrContext.h" | 20 #include "GrContext.h" |
| 21 #include "GrGpu.h" | 21 #include "GrGpu.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 #include <initializer_list> | 24 #include <initializer_list> |
| 25 | 25 |
| 26 static void release_direct_surface_storage(void* pixels, void* context) { | 26 static void release_direct_surface_storage(void* pixels, void* context) { |
| 27 SkASSERT(pixels == context); | 27 SkASSERT(pixels == context); |
| 28 sk_free(pixels); | 28 sk_free(pixels); |
| 29 } | 29 } |
| 30 static SkSurface* create_surface(SkAlphaType at = kPremul_SkAlphaType, | 30 static sk_sp<SkSurface> create_surface(SkAlphaType at = kPremul_SkAlphaType, |
| 31 SkImageInfo* requestedInfo = nullptr) { | 31 SkImageInfo* requestedInfo = nullptr) { |
| 32 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); | 32 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
| 33 if (requestedInfo) { | 33 if (requestedInfo) { |
| 34 *requestedInfo = info; | 34 *requestedInfo = info; |
| 35 } | 35 } |
| 36 return SkSurface::NewRaster(info); | 36 return SkSurface::MakeRaster(info); |
| 37 } | 37 } |
| 38 static SkSurface* create_direct_surface(SkAlphaType at = kPremul_SkAlphaType, | 38 static sk_sp<SkSurface> create_direct_surface(SkAlphaType at = kPremul_SkAlphaTy
pe, |
| 39 SkImageInfo* requestedInfo = nullptr) { | 39 SkImageInfo* requestedInfo = nullp
tr) { |
| 40 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); | 40 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
| 41 if (requestedInfo) { | 41 if (requestedInfo) { |
| 42 *requestedInfo = info; | 42 *requestedInfo = info; |
| 43 } | 43 } |
| 44 const size_t rowBytes = info.minRowBytes(); | 44 const size_t rowBytes = info.minRowBytes(); |
| 45 void* storage = sk_malloc_throw(info.getSafeSize(rowBytes)); | 45 void* storage = sk_malloc_throw(info.getSafeSize(rowBytes)); |
| 46 return SkSurface::NewRasterDirectReleaseProc(info, storage, rowBytes, | 46 return SkSurface::MakeRasterDirectReleaseProc(info, storage, rowBytes, |
| 47 release_direct_surface_storage, | 47 release_direct_surface_storage
, |
| 48 storage); | 48 storage); |
| 49 } | 49 } |
| 50 #if SK_SUPPORT_GPU | 50 #if SK_SUPPORT_GPU |
| 51 static SkSurface* create_gpu_surface(GrContext* context, SkAlphaType at = kPremu
l_SkAlphaType, | 51 static sk_sp<SkSurface> create_gpu_surface(GrContext* context, SkAlphaType at =
kPremul_SkAlphaType, |
| 52 SkImageInfo* requestedInfo = nullptr) { | 52 SkImageInfo* requestedInfo = nullptr)
{ |
| 53 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); | 53 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
| 54 if (requestedInfo) { | 54 if (requestedInfo) { |
| 55 *requestedInfo = info; | 55 *requestedInfo = info; |
| 56 } | 56 } |
| 57 return SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr
); | 57 return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullpt
r); |
| 58 } | 58 } |
| 59 static SkSurface* create_gpu_scratch_surface(GrContext* context, | 59 static sk_sp<SkSurface> create_gpu_scratch_surface(GrContext* context, |
| 60 SkAlphaType at = kPremul_SkAlphaTyp
e, | 60 SkAlphaType at = kPremul_SkAl
phaType, |
| 61 SkImageInfo* requestedInfo = nullpt
r) { | 61 SkImageInfo* requestedInfo =
nullptr) { |
| 62 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); | 62 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
| 63 if (requestedInfo) { | 63 if (requestedInfo) { |
| 64 *requestedInfo = info; | 64 *requestedInfo = info; |
| 65 } | 65 } |
| 66 return SkSurface::NewRenderTarget(context, SkBudgeted::kYes, info, 0, nullpt
r); | 66 return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0, nullp
tr); |
| 67 } | 67 } |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 DEF_TEST(SurfaceEmpty, reporter) { | 70 DEF_TEST(SurfaceEmpty, reporter) { |
| 71 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 71 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 72 REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRaster(info)); | 72 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); |
| 73 REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRasterDirect(info, nullpt
r, 0)); | 73 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp
tr, 0)); |
| 74 | 74 |
| 75 } | 75 } |
| 76 #if SK_SUPPORT_GPU | 76 #if SK_SUPPORT_GPU |
| 77 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) { | 77 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) { |
| 78 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 78 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 79 REPORTER_ASSERT(reporter, nullptr == | 79 REPORTER_ASSERT(reporter, nullptr == |
| 80 SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0
, nullptr)); | 80 SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info,
0, nullptr)); |
| 81 } | 81 } |
| 82 #endif | 82 #endif |
| 83 | 83 |
| 84 #if SK_SUPPORT_GPU | 84 #if SK_SUPPORT_GPU |
| 85 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { | 85 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { |
| 86 GrGpu* gpu = context->getGpu(); | 86 GrGpu* gpu = context->getGpu(); |
| 87 if (!gpu) { | 87 if (!gpu) { |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Test the wrapped factory for SkSurface by creating a backend texture and
then wrap it in | 91 // Test the wrapped factory for SkSurface by creating a backend texture and
then wrap it in |
| 92 // a SkSurface. | 92 // a SkSurface. |
| 93 static const int kW = 100; | 93 static const int kW = 100; |
| 94 static const int kH = 100; | 94 static const int kH = 100; |
| 95 static const uint32_t kOrigColor = 0xFFAABBCC; | 95 static const uint32_t kOrigColor = 0xFFAABBCC; |
| 96 SkAutoTArray<uint32_t> pixels(kW * kH); | 96 SkAutoTArray<uint32_t> pixels(kW * kH); |
| 97 sk_memset32(pixels.get(), kOrigColor, kW * kH); | 97 sk_memset32(pixels.get(), kOrigColor, kW * kH); |
| 98 GrBackendObject texHandle = gpu->createTestingOnlyBackendTexture(pixels.get(
), kW, kH, | 98 GrBackendObject texHandle = gpu->createTestingOnlyBackendTexture(pixels.get(
), kW, kH, |
| 99 kRGBA_8888_
GrPixelConfig); | 99 kRGBA_8888_
GrPixelConfig); |
| 100 | 100 |
| 101 GrBackendTextureDesc wrappedDesc; | 101 GrBackendTextureDesc wrappedDesc; |
| 102 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; | 102 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 103 wrappedDesc.fWidth = kW; | 103 wrappedDesc.fWidth = kW; |
| 104 wrappedDesc.fHeight = kH; | 104 wrappedDesc.fHeight = kH; |
| 105 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 105 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 106 wrappedDesc.fSampleCnt = 0; | 106 wrappedDesc.fSampleCnt = 0; |
| 107 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; | 107 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 108 wrappedDesc.fTextureHandle = texHandle; | 108 wrappedDesc.fTextureHandle = texHandle; |
| 109 | 109 |
| 110 SkAutoTUnref<SkSurface> surface( | 110 auto surface(SkSurface::MakeFromBackendTexture(context, wrappedDesc, nullptr
)); |
| 111 SkSurface::NewWrappedRenderTarget(context, wrappedDesc, nullptr)); | |
| 112 REPORTER_ASSERT(reporter, surface); | 111 REPORTER_ASSERT(reporter, surface); |
| 113 if (surface) { | 112 if (surface) { |
| 114 // Validate that we can draw to the canvas and that the original texture
color is preserved | 113 // Validate that we can draw to the canvas and that the original texture
color is preserved |
| 115 // in pixels that aren't rendered to via the surface. | 114 // in pixels that aren't rendered to via the surface. |
| 116 SkPaint paint; | 115 SkPaint paint; |
| 117 static const SkColor kRectColor = ~kOrigColor | 0xFF000000; | 116 static const SkColor kRectColor = ~kOrigColor | 0xFF000000; |
| 118 paint.setColor(kRectColor); | 117 paint.setColor(kRectColor); |
| 119 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntTo
Scalar(kH)/2), | 118 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntTo
Scalar(kH)/2), |
| 120 paint); | 119 paint); |
| 121 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH); | 120 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 145 stop = true; | 144 stop = true; |
| 146 } | 145 } |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 } | 148 } |
| 150 gpu->deleteTestingOnlyBackendTexture(texHandle); | 149 gpu->deleteTestingOnlyBackendTexture(texHandle); |
| 151 } | 150 } |
| 152 #endif | 151 #endif |
| 153 | 152 |
| 154 static void test_canvas_peek(skiatest::Reporter* reporter, | 153 static void test_canvas_peek(skiatest::Reporter* reporter, |
| 155 SkSurface* surface, | 154 sk_sp<SkSurface>& surface, |
| 156 const SkImageInfo& requestInfo, | 155 const SkImageInfo& requestInfo, |
| 157 bool expectPeekSuccess) { | 156 bool expectPeekSuccess) { |
| 158 const SkColor color = SK_ColorRED; | 157 const SkColor color = SK_ColorRED; |
| 159 const SkPMColor pmcolor = SkPreMultiplyColor(color); | 158 const SkPMColor pmcolor = SkPreMultiplyColor(color); |
| 160 surface->getCanvas()->clear(color); | 159 surface->getCanvas()->clear(color); |
| 161 | 160 |
| 162 SkPixmap pmap; | 161 SkPixmap pmap; |
| 163 bool success = surface->getCanvas()->peekPixels(&pmap); | 162 bool success = surface->getCanvas()->peekPixels(&pmap); |
| 164 REPORTER_ASSERT(reporter, expectPeekSuccess == success); | 163 REPORTER_ASSERT(reporter, expectPeekSuccess == success); |
| 165 | 164 |
| 166 SkPixmap pmap2; | 165 SkPixmap pmap2; |
| 167 const void* addr2 = surface->peekPixels(&pmap2) ? pmap2.addr() : nullptr; | 166 const void* addr2 = surface->peekPixels(&pmap2) ? pmap2.addr() : nullptr; |
| 168 | 167 |
| 169 if (success) { | 168 if (success) { |
| 170 REPORTER_ASSERT(reporter, requestInfo == pmap.info()); | 169 REPORTER_ASSERT(reporter, requestInfo == pmap.info()); |
| 171 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= pmap.rowBytes()); | 170 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= pmap.rowBytes()); |
| 172 REPORTER_ASSERT(reporter, pmcolor == *pmap.addr32()); | 171 REPORTER_ASSERT(reporter, pmcolor == *pmap.addr32()); |
| 173 | 172 |
| 174 REPORTER_ASSERT(reporter, pmap.addr() == pmap2.addr()); | 173 REPORTER_ASSERT(reporter, pmap.addr() == pmap2.addr()); |
| 175 REPORTER_ASSERT(reporter, pmap.info() == pmap2.info()); | 174 REPORTER_ASSERT(reporter, pmap.info() == pmap2.info()); |
| 176 REPORTER_ASSERT(reporter, pmap.rowBytes() == pmap2.rowBytes()); | 175 REPORTER_ASSERT(reporter, pmap.rowBytes() == pmap2.rowBytes()); |
| 177 } else { | 176 } else { |
| 178 REPORTER_ASSERT(reporter, nullptr == addr2); | 177 REPORTER_ASSERT(reporter, nullptr == addr2); |
| 179 } | 178 } |
| 180 } | 179 } |
| 181 DEF_TEST(SurfaceCanvasPeek, reporter) { | 180 DEF_TEST(SurfaceCanvasPeek, reporter) { |
| 182 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 181 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 183 SkImageInfo requestInfo; | 182 SkImageInfo requestInfo; |
| 184 SkAutoTUnref<SkSurface> surface(surface_func(kPremul_SkAlphaType, &reque
stInfo)); | 183 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo)); |
| 185 test_canvas_peek(reporter, surface, requestInfo, true); | 184 test_canvas_peek(reporter, surface, requestInfo, true); |
| 186 } | 185 } |
| 187 } | 186 } |
| 188 #if SK_SUPPORT_GPU | 187 #if SK_SUPPORT_GPU |
| 189 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, context) { | 188 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, context) { |
| 190 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 189 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 191 SkImageInfo requestInfo; | 190 SkImageInfo requestInfo; |
| 192 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaTyp
e, &requestInfo)); | 191 auto surface(surface_func(context, kPremul_SkAlphaType, &requestInfo)); |
| 193 test_canvas_peek(reporter, surface, requestInfo, false); | 192 test_canvas_peek(reporter, surface, requestInfo, false); |
| 194 } | 193 } |
| 195 } | 194 } |
| 196 #endif | 195 #endif |
| 197 | 196 |
| 198 // For compatibility with clients that still call accessBitmap(), we need to ens
ure that we bump | 197 // For compatibility with clients that still call accessBitmap(), we need to ens
ure that we bump |
| 199 // the bitmap's genID when we draw to it, else they won't know it has new values
. When they are | 198 // the bitmap's genID when we draw to it, else they won't know it has new values
. When they are |
| 200 // exclusively using surface/image, and we can hide accessBitmap from device, we
can remove this | 199 // exclusively using surface/image, and we can hide accessBitmap from device, we
can remove this |
| 201 // test. | 200 // test. |
| 202 void test_access_pixels(skiatest::Reporter* reporter, SkSurface* surface) { | 201 void test_access_pixels(skiatest::Reporter* reporter, const sk_sp<SkSurface>& su
rface) { |
| 203 SkCanvas* canvas = surface->getCanvas(); | 202 SkCanvas* canvas = surface->getCanvas(); |
| 204 canvas->clear(0); | 203 canvas->clear(0); |
| 205 | 204 |
| 206 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_t
esting(); | 205 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_t
esting(); |
| 207 SkBitmap bm = device->accessBitmap(false); | 206 SkBitmap bm = device->accessBitmap(false); |
| 208 uint32_t genID0 = bm.getGenerationID(); | 207 uint32_t genID0 = bm.getGenerationID(); |
| 209 // Now we draw something, which needs to "dirty" the genID (sorta like copy-
on-write) | 208 // Now we draw something, which needs to "dirty" the genID (sorta like copy-
on-write) |
| 210 canvas->drawColor(SK_ColorBLUE); | 209 canvas->drawColor(SK_ColorBLUE); |
| 211 // Now check that we get a different genID | 210 // Now check that we get a different genID |
| 212 uint32_t genID1 = bm.getGenerationID(); | 211 uint32_t genID1 = bm.getGenerationID(); |
| 213 REPORTER_ASSERT(reporter, genID0 != genID1); | 212 REPORTER_ASSERT(reporter, genID0 != genID1); |
| 214 } | 213 } |
| 215 DEF_TEST(SurfaceAccessPixels, reporter) { | 214 DEF_TEST(SurfaceAccessPixels, reporter) { |
| 216 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 215 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 217 SkAutoTUnref<SkSurface> surface(surface_func(kPremul_SkAlphaType, nullpt
r)); | 216 auto surface(surface_func(kPremul_SkAlphaType, nullptr)); |
| 218 test_access_pixels(reporter, surface); | 217 test_access_pixels(reporter, surface); |
| 219 } | 218 } |
| 220 } | 219 } |
| 221 #if SK_SUPPORT_GPU | 220 #if SK_SUPPORT_GPU |
| 222 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, context) { | 221 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, context) { |
| 223 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 222 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 224 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaTyp
e, nullptr)); | 223 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 225 test_access_pixels(reporter, surface); | 224 test_access_pixels(reporter, surface); |
| 226 } | 225 } |
| 227 } | 226 } |
| 228 #endif | 227 #endif |
| 229 | 228 |
| 230 static void test_snapshot_alphatype(skiatest::Reporter* reporter, SkSurface* sur
face, | 229 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk
Surface>& surface, |
| 231 bool expectOpaque) { | 230 bool expectOpaque) { |
| 232 REPORTER_ASSERT(reporter, surface); | 231 REPORTER_ASSERT(reporter, surface); |
| 233 if (surface) { | 232 if (surface) { |
| 234 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 233 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 235 REPORTER_ASSERT(reporter, image); | 234 REPORTER_ASSERT(reporter, image); |
| 236 if (image) { | 235 if (image) { |
| 237 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque
)); | 236 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque
)); |
| 238 } | 237 } |
| 239 } | 238 } |
| 240 } | 239 } |
| 241 DEF_TEST(SurfaceSnapshotAlphaType, reporter) { | 240 DEF_TEST(SurfaceSnapshotAlphaType, reporter) { |
| 242 for (auto& surface_func : { &create_surface, &create_direct_surface }) { | 241 for (auto& surface_func : { &create_surface, &create_direct_surface }) { |
| 243 for (auto& isOpaque : { true, false }) { | 242 for (auto& isOpaque : { true, false }) { |
| 244 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; | 243 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; |
| 245 SkAutoTUnref<SkSurface> surface(surface_func(alphaType, nullptr)); | 244 auto surface(surface_func(alphaType, nullptr)); |
| 246 test_snapshot_alphatype(reporter, surface, isOpaque); | 245 test_snapshot_alphatype(reporter, surface, isOpaque); |
| 247 } | 246 } |
| 248 } | 247 } |
| 249 } | 248 } |
| 250 #if SK_SUPPORT_GPU | 249 #if SK_SUPPORT_GPU |
| 251 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, conte
xt) { | 250 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, conte
xt) { |
| 252 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 251 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 253 for (auto& isOpaque : { true, false }) { | 252 for (auto& isOpaque : { true, false }) { |
| 254 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; | 253 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA
lphaType; |
| 255 SkAutoTUnref<SkSurface> surface(surface_func(context, alphaType, nul
lptr)); | 254 auto surface(surface_func(context, alphaType, nullptr)); |
| 256 test_snapshot_alphatype(reporter, surface, isOpaque); | 255 test_snapshot_alphatype(reporter, surface, isOpaque); |
| 257 } | 256 } |
| 258 } | 257 } |
| 259 } | 258 } |
| 260 #endif | 259 #endif |
| 261 | 260 |
| 262 static GrBackendObject get_surface_backend_texture_handle( | 261 static GrBackendObject get_surface_backend_texture_handle( |
| 263 SkSurface* s, SkSurface::BackendHandleAccess a) { | 262 SkSurface* s, SkSurface::BackendHandleAccess a) { |
| 264 return s->getTextureHandle(a); | 263 return s->getTextureHandle(a); |
| 265 } | 264 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 286 } | 285 } |
| 287 DEF_TEST(SurfaceBackendHandleAccessCopyOnWrite, reporter) { | 286 DEF_TEST(SurfaceBackendHandleAccessCopyOnWrite, reporter) { |
| 288 const SkSurface::BackendHandleAccess accessModes[] = { | 287 const SkSurface::BackendHandleAccess accessModes[] = { |
| 289 SkSurface::kFlushRead_BackendHandleAccess, | 288 SkSurface::kFlushRead_BackendHandleAccess, |
| 290 SkSurface::kFlushWrite_BackendHandleAccess, | 289 SkSurface::kFlushWrite_BackendHandleAccess, |
| 291 SkSurface::kDiscardWrite_BackendHandleAccess, | 290 SkSurface::kDiscardWrite_BackendHandleAccess, |
| 292 }; | 291 }; |
| 293 for (auto& handle_access_func : | 292 for (auto& handle_access_func : |
| 294 { &get_surface_backend_texture_handle, &get_surface_backend_render_t
arget_handle }) { | 293 { &get_surface_backend_texture_handle, &get_surface_backend_render_t
arget_handle }) { |
| 295 for (auto& accessMode : accessModes) { | 294 for (auto& accessMode : accessModes) { |
| 296 SkAutoTUnref<SkSurface> surface(create_surface()); | 295 auto surface(create_surface()); |
| 297 test_backend_handle_access_copy_on_write(reporter, surface, accessMo
de, | 296 test_backend_handle_access_copy_on_write(reporter, surface.get(), ac
cessMode, |
| 298 handle_access_func); | 297 handle_access_func); |
| 299 } | 298 } |
| 300 } | 299 } |
| 301 } | 300 } |
| 302 #if SK_SUPPORT_GPU | 301 #if SK_SUPPORT_GPU |
| 303 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re
porter, context) { | 302 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re
porter, context) { |
| 304 const SkSurface::BackendHandleAccess accessModes[] = { | 303 const SkSurface::BackendHandleAccess accessModes[] = { |
| 305 SkSurface::kFlushRead_BackendHandleAccess, | 304 SkSurface::kFlushRead_BackendHandleAccess, |
| 306 SkSurface::kFlushWrite_BackendHandleAccess, | 305 SkSurface::kFlushWrite_BackendHandleAccess, |
| 307 SkSurface::kDiscardWrite_BackendHandleAccess, | 306 SkSurface::kDiscardWrite_BackendHandleAccess, |
| 308 }; | 307 }; |
| 309 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 308 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 310 for (auto& handle_access_func : | 309 for (auto& handle_access_func : |
| 311 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle }) { | 310 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle }) { |
| 312 for (auto& accessMode : accessModes) { | 311 for (auto& accessMode : accessModes) { |
| 313 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_Sk
AlphaType, | 312 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)
); |
| 314 nullptr)); | 313 test_backend_handle_access_copy_on_write(reporter, surface.get()
, accessMode, |
| 315 test_backend_handle_access_copy_on_write(reporter, surface, acce
ssMode, | |
| 316 handle_access_func); | 314 handle_access_func); |
| 317 } | 315 } |
| 318 } | 316 } |
| 319 } | 317 } |
| 320 } | 318 } |
| 321 #endif | 319 #endif |
| 322 | 320 |
| 323 static bool same_image(SkImage* a, SkImage* b, | 321 static bool same_image(SkImage* a, SkImage* b, |
| 324 std::function<intptr_t(SkImage*)> getImageBackingStore) { | 322 std::function<intptr_t(SkImage*)> getImageBackingStore) { |
| 325 return getImageBackingStore(a) == getImageBackingStore(b); | 323 return getImageBackingStore(a) == getImageBackingStore(b); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 REPORTER_ASSERT(reporter, success); | 381 REPORTER_ASSERT(reporter, success); |
| 384 return reinterpret_cast<intptr_t>(pm.addr()); | 382 return reinterpret_cast<intptr_t>(pm.addr()); |
| 385 }; | 383 }; |
| 386 auto getSufaceBackingStore = [reporter](SkSurface* surface) { | 384 auto getSufaceBackingStore = [reporter](SkSurface* surface) { |
| 387 SkPixmap pmap; | 385 SkPixmap pmap; |
| 388 const void* pixels = surface->getCanvas()->peekPixels(&pmap) ? pmap.addr
() : nullptr; | 386 const void* pixels = surface->getCanvas()->peekPixels(&pmap) ? pmap.addr
() : nullptr; |
| 389 REPORTER_ASSERT(reporter, pixels); | 387 REPORTER_ASSERT(reporter, pixels); |
| 390 return reinterpret_cast<intptr_t>(pixels); | 388 return reinterpret_cast<intptr_t>(pixels); |
| 391 }; | 389 }; |
| 392 | 390 |
| 393 SkAutoTUnref<SkSurface> surface(create_surface()); | 391 auto surface(create_surface()); |
| 394 test_unique_image_snap(reporter, surface, false, getImageBackingStore, getSu
faceBackingStore); | 392 test_unique_image_snap(reporter, surface.get(), false, getImageBackingStore, |
| 395 surface.reset(create_direct_surface()); | 393 getSufaceBackingStore); |
| 396 test_unique_image_snap(reporter, surface, true, getImageBackingStore, getSuf
aceBackingStore); | 394 surface = create_direct_surface(); |
| 395 test_unique_image_snap(reporter, surface.get(), true, getImageBackingStore, |
| 396 getSufaceBackingStore); |
| 397 } | 397 } |
| 398 | 398 |
| 399 #if SK_SUPPORT_GPU | 399 #if SK_SUPPORT_GPU |
| 400 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, context) { | 400 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, context) { |
| 401 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 401 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 402 SkAutoTUnref<SkSurface> surface(surface_func(context, kOpaque_SkAlphaTyp
e, nullptr)); | 402 auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); |
| 403 | 403 |
| 404 auto imageBackingStore = [reporter](SkImage* image) { | 404 auto imageBackingStore = [reporter](SkImage* image) { |
| 405 GrTexture* texture = as_IB(image)->peekTexture(); | 405 GrTexture* texture = as_IB(image)->peekTexture(); |
| 406 if (!texture) { | 406 if (!texture) { |
| 407 ERRORF(reporter, "Not texture backed."); | 407 ERRORF(reporter, "Not texture backed."); |
| 408 return static_cast<intptr_t>(0); | 408 return static_cast<intptr_t>(0); |
| 409 } | 409 } |
| 410 return static_cast<intptr_t>(texture->getUniqueID()); | 410 return static_cast<intptr_t>(texture->getUniqueID()); |
| 411 }; | 411 }; |
| 412 | 412 |
| 413 auto surfaceBackingStore = [reporter](SkSurface* surface) { | 413 auto surfaceBackingStore = [reporter](SkSurface* surface) { |
| 414 GrRenderTarget* rt = | 414 GrRenderTarget* rt = |
| 415 surface->getCanvas()->internal_private_accessTopLayerRenderTarge
t(); | 415 surface->getCanvas()->internal_private_accessTopLayerRenderTarge
t(); |
| 416 if (!rt) { | 416 if (!rt) { |
| 417 ERRORF(reporter, "Not render target backed."); | 417 ERRORF(reporter, "Not render target backed."); |
| 418 return static_cast<intptr_t>(0); | 418 return static_cast<intptr_t>(0); |
| 419 } | 419 } |
| 420 return static_cast<intptr_t>(rt->getUniqueID()); | 420 return static_cast<intptr_t>(rt->getUniqueID()); |
| 421 }; | 421 }; |
| 422 | 422 |
| 423 test_unique_image_snap(reporter, surface, false, imageBackingStore, surf
aceBackingStore); | 423 test_unique_image_snap(reporter, surface.get(), false, imageBackingStore
, |
| 424 surfaceBackingStore); |
| 424 | 425 |
| 425 // Test again with a "direct" render target; | 426 // Test again with a "direct" render target; |
| 426 GrBackendObject textureObject = context->getGpu()->createTestingOnlyBack
endTexture(nullptr, | 427 GrBackendObject textureObject = context->getGpu()->createTestingOnlyBack
endTexture(nullptr, |
| 427 10, 10, kRGBA_8888_GrPixelConfig); | 428 10, 10, kRGBA_8888_GrPixelConfig); |
| 428 GrBackendTextureDesc desc; | 429 GrBackendTextureDesc desc; |
| 429 desc.fConfig = kRGBA_8888_GrPixelConfig; | 430 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 430 desc.fWidth = 10; | 431 desc.fWidth = 10; |
| 431 desc.fHeight = 10; | 432 desc.fHeight = 10; |
| 432 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 433 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 433 desc.fTextureHandle = textureObject; | 434 desc.fTextureHandle = textureObject; |
| 434 GrTexture* texture = context->textureProvider()->wrapBackendTexture(desc
); | 435 GrTexture* texture = context->textureProvider()->wrapBackendTexture(desc
); |
| 435 { | 436 { |
| 436 SkAutoTUnref<SkSurface> surface( | 437 auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarg
et())); |
| 437 SkSurface::NewRenderTargetDirect(texture->asRenderTarget())); | 438 test_unique_image_snap(reporter, surface.get(), true, imageBackingSt
ore, |
| 438 test_unique_image_snap(reporter, surface, true, imageBackingStore, | |
| 439 surfaceBackingStore); | 439 surfaceBackingStore); |
| 440 } | 440 } |
| 441 texture->unref(); | 441 texture->unref(); |
| 442 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); | 442 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 #endif | 445 #endif |
| 446 | 446 |
| 447 #if SK_SUPPORT_GPU | 447 #if SK_SUPPORT_GPU |
| 448 // May we (soon) eliminate the need to keep testing this, by hiding the bloody d
evice! | 448 // May we (soon) eliminate the need to keep testing this, by hiding the bloody d
evice! |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 // expect a new(er) image, since we claimed we would write | 497 // expect a new(er) image, since we claimed we would write |
| 498 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); | 498 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); |
| 499 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); | 499 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); |
| 500 } | 500 } |
| 501 // No CPU test. | 501 // No CPU test. |
| 502 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter,
context) { | 502 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter,
context) { |
| 503 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 503 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 504 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_h
andle_gen_id }) { | 504 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_h
andle_gen_id }) { |
| 505 for (auto& handle_access_func : | 505 for (auto& handle_access_func : |
| 506 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle}) { | 506 { &get_surface_backend_texture_handle, &get_surface_backend_rend
er_target_handle}) { |
| 507 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_Sk
AlphaType, | 507 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)
); |
| 508 nullptr)); | 508 test_func(reporter, surface.get(), handle_access_func); |
| 509 test_func(reporter, surface, handle_access_func); | |
| 510 } | 509 } |
| 511 } | 510 } |
| 512 } | 511 } |
| 513 } | 512 } |
| 514 #endif | 513 #endif |
| 515 | 514 |
| 516 // Verify that the right canvas commands trigger a copy on write. | 515 // Verify that the right canvas commands trigger a copy on write. |
| 517 static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface)
{ | 516 static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface)
{ |
| 518 SkCanvas* canvas = surface->getCanvas(); | 517 SkCanvas* canvas = surface->getCanvas(); |
| 519 | 518 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0)) | 581 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0)) |
| 583 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr)) | 582 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect, nullptr)) |
| 584 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, nullptr
)) | 583 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, nullptr
)) |
| 585 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP
aint)) | 584 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP
aint)) |
| 586 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin
ts2, \ | 585 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin
ts2, \ |
| 587 testPaint)) | 586 testPaint)) |
| 588 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
ath, nullptr, \ | 587 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
ath, nullptr, \ |
| 589 testPaint)) | 588 testPaint)) |
| 590 } | 589 } |
| 591 DEF_TEST(SurfaceCopyOnWrite, reporter) { | 590 DEF_TEST(SurfaceCopyOnWrite, reporter) { |
| 592 SkAutoTUnref<SkSurface> surface(create_surface()); | 591 test_copy_on_write(reporter, create_surface().get()); |
| 593 test_copy_on_write(reporter, surface); | |
| 594 } | 592 } |
| 595 #if SK_SUPPORT_GPU | 593 #if SK_SUPPORT_GPU |
| 596 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, context) { | 594 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, context) { |
| 597 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 595 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 598 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaTyp
e, nullptr)); | 596 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 599 test_copy_on_write(reporter, surface); | 597 test_copy_on_write(reporter, surface.get()); |
| 600 } | 598 } |
| 601 } | 599 } |
| 602 #endif | 600 #endif |
| 603 | 601 |
| 604 static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, | 602 static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, |
| 605 SkSurface* surface) { | 603 SkSurface* surface) { |
| 606 // This test succeeds by not triggering an assertion. | 604 // This test succeeds by not triggering an assertion. |
| 607 // The test verifies that the surface remains writable (usable) after | 605 // The test verifies that the surface remains writable (usable) after |
| 608 // acquiring and releasing a snapshot without triggering a copy on write. | 606 // acquiring and releasing a snapshot without triggering a copy on write. |
| 609 SkCanvas* canvas = surface->getCanvas(); | 607 SkCanvas* canvas = surface->getCanvas(); |
| 610 canvas->clear(1); | 608 canvas->clear(1); |
| 611 surface->makeImageSnapshot(); // Create and destroy SkImage | 609 surface->makeImageSnapshot(); // Create and destroy SkImage |
| 612 canvas->clear(2); // Must not assert internally | 610 canvas->clear(2); // Must not assert internally |
| 613 } | 611 } |
| 614 DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { | 612 DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { |
| 615 SkAutoTUnref<SkSurface> surface(create_surface()); | 613 test_writable_after_snapshot_release(reporter, create_surface().get()); |
| 616 test_writable_after_snapshot_release(reporter, surface); | |
| 617 } | 614 } |
| 618 #if SK_SUPPORT_GPU | 615 #if SK_SUPPORT_GPU |
| 619 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, rep
orter, context) { | 616 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, rep
orter, context) { |
| 620 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 617 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 621 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaTyp
e, nullptr)); | 618 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 622 test_writable_after_snapshot_release(reporter, surface); | 619 test_writable_after_snapshot_release(reporter, surface.get()); |
| 623 } | 620 } |
| 624 } | 621 } |
| 625 #endif | 622 #endif |
| 626 | 623 |
| 627 #if SK_SUPPORT_GPU | 624 #if SK_SUPPORT_GPU |
| 628 static void test_crbug263329(skiatest::Reporter* reporter, | 625 static void test_crbug263329(skiatest::Reporter* reporter, |
| 629 SkSurface* surface1, | 626 SkSurface* surface1, |
| 630 SkSurface* surface2) { | 627 SkSurface* surface2) { |
| 631 // This is a regression test for crbug.com/263329 | 628 // This is a regression test for crbug.com/263329 |
| 632 // Bug was caused by onCopyOnWrite releasing the old surface texture | 629 // Bug was caused by onCopyOnWrite releasing the old surface texture |
| (...skipping 19 matching lines...) Expand all Loading... |
| 652 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee
kTexture()); | 649 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee
kTexture()); |
| 653 // The following assertion checks crbug.com/263329 | 650 // The following assertion checks crbug.com/263329 |
| 654 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee
kTexture()); | 651 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee
kTexture()); |
| 655 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee
kTexture()); | 652 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 656 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee
kTexture()); | 653 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee
kTexture()); |
| 657 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee
kTexture()); | 654 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 658 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee
kTexture()); | 655 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee
kTexture()); |
| 659 } | 656 } |
| 660 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) { | 657 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) { |
| 661 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 658 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 662 SkAutoTUnref<SkSurface> surface1(surface_func(context, kPremul_SkAlphaTy
pe, nullptr)); | 659 auto surface1(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 663 SkAutoTUnref<SkSurface> surface2(surface_func(context, kPremul_SkAlphaTy
pe, nullptr)); | 660 auto surface2(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 664 test_crbug263329(reporter, surface1, surface2); | 661 test_crbug263329(reporter, surface1.get(), surface2.get()); |
| 665 } | 662 } |
| 666 } | 663 } |
| 667 #endif | 664 #endif |
| 668 | 665 |
| 669 DEF_TEST(SurfaceGetTexture, reporter) { | 666 DEF_TEST(SurfaceGetTexture, reporter) { |
| 670 SkAutoTUnref<SkSurface> surface(create_surface()); | 667 auto surface(create_surface()); |
| 671 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 668 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 672 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); | 669 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
| 673 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 670 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 674 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); | 671 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); |
| 675 } | 672 } |
| 676 #if SK_SUPPORT_GPU | 673 #if SK_SUPPORT_GPU |
| 677 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, context) { | 674 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, context) { |
| 678 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 675 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 679 SkAutoTUnref<SkSurface> surface(surface_func(context, kPremul_SkAlphaTyp
e, nullptr)); | 676 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); |
| 680 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 677 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 681 GrTexture* texture = as_IB(image)->peekTexture(); | 678 GrTexture* texture = as_IB(image)->peekTexture(); |
| 682 REPORTER_ASSERT(reporter, texture); | 679 REPORTER_ASSERT(reporter, texture); |
| 683 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); | 680 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |
| 684 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 681 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |
| 685 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); | 682 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); |
| 686 } | 683 } |
| 687 } | 684 } |
| 688 #endif | 685 #endif |
| 689 | 686 |
| 690 #if SK_SUPPORT_GPU | 687 #if SK_SUPPORT_GPU |
| 691 #include "GrGpuResourcePriv.h" | 688 #include "GrGpuResourcePriv.h" |
| 692 #include "SkGpuDevice.h" | 689 #include "SkGpuDevice.h" |
| 693 #include "SkImage_Gpu.h" | 690 #include "SkImage_Gpu.h" |
| 694 #include "SkSurface_Gpu.h" | 691 #include "SkSurface_Gpu.h" |
| 695 | 692 |
| 696 static SkBudgeted is_budgeted(SkSurface* surf) { | 693 static SkBudgeted is_budgeted(const sk_sp<SkSurface>& surf) { |
| 697 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePr
iv().isBudgeted(); | 694 SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get(); |
| 695 return gsurf->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted()
; |
| 698 } | 696 } |
| 699 | 697 |
| 700 static SkBudgeted is_budgeted(SkImage* image) { | 698 static SkBudgeted is_budgeted(SkImage* image) { |
| 701 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); | 699 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); |
| 702 } | 700 } |
| 703 | 701 |
| 704 static SkBudgeted is_budgeted(const sk_sp<SkImage> image) { | 702 static SkBudgeted is_budgeted(const sk_sp<SkImage> image) { |
| 705 return is_budgeted(image.get()); | 703 return is_budgeted(image.get()); |
| 706 } | 704 } |
| 707 | 705 |
| 708 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { | 706 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { |
| 709 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); | 707 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); |
| 710 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | 708 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
| 711 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { | 709 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { |
| 712 SkAutoTUnref<SkSurface> | 710 auto surface(SkSurface::MakeRenderTarget(context, sbudgeted, info)); |
| 713 surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0))
; | |
| 714 SkASSERT(surface); | 711 SkASSERT(surface); |
| 715 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 712 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| 716 | 713 |
| 717 sk_sp<SkImage> image(surface->makeImageSnapshot(ibudgeted)); | 714 sk_sp<SkImage> image(surface->makeImageSnapshot(ibudgeted)); |
| 718 | 715 |
| 719 // Initially the image shares a texture with the surface, and the su
rface decides | 716 // Initially the image shares a texture with the surface, and the su
rface decides |
| 720 // whether it is budgeted or not. | 717 // whether it is budgeted or not. |
| 721 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 718 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
| 722 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image)); | 719 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image)); |
| 723 | 720 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 sk_sp<SkImage> aur_image2(image2); | 753 sk_sp<SkImage> aur_image2(image2); |
| 757 SkDEBUGCODE(image2->validate();) | 754 SkDEBUGCODE(image2->validate();) |
| 758 SkDEBUGCODE(surface->validate();) | 755 SkDEBUGCODE(surface->validate();) |
| 759 REPORTER_ASSERT(reporter, image1 != image2); | 756 REPORTER_ASSERT(reporter, image1 != image2); |
| 760 } | 757 } |
| 761 DEF_TEST(SurfaceNoCanvas, reporter) { | 758 DEF_TEST(SurfaceNoCanvas, reporter) { |
| 762 SkSurface::ContentChangeMode modes[] = | 759 SkSurface::ContentChangeMode modes[] = |
| 763 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; | 760 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; |
| 764 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { | 761 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 765 for (auto& mode : modes) { | 762 for (auto& mode : modes) { |
| 766 SkAutoTUnref<SkSurface> surface(create_surface()); | 763 test_func(reporter, create_surface().get(), mode); |
| 767 test_func(reporter, surface, mode); | |
| 768 } | 764 } |
| 769 } | 765 } |
| 770 } | 766 } |
| 771 #if SK_SUPPORT_GPU | 767 #if SK_SUPPORT_GPU |
| 772 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) { | 768 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) { |
| 773 SkSurface::ContentChangeMode modes[] = | 769 SkSurface::ContentChangeMode modes[] = |
| 774 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; | 770 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC
hangeMode}; |
| 775 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { | 771 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface
}) { |
| 776 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { | 772 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { |
| 777 for (auto& mode : modes) { | 773 for (auto& mode : modes) { |
| 778 SkAutoTUnref<SkSurface> surface( | 774 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)
); |
| 779 surface_func(context, kPremul_SkAlphaType, nullptr)); | 775 test_func(reporter, surface.get(), mode); |
| 780 test_func(reporter, surface, mode); | |
| 781 } | 776 } |
| 782 } | 777 } |
| 783 } | 778 } |
| 784 } | 779 } |
| 785 #endif | 780 #endif |
| 786 | 781 |
| 787 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor
ter* reporter) { | 782 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor
ter* reporter) { |
| 788 SkPixmap surfacePM; | 783 SkPixmap surfacePM; |
| 789 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM)); | 784 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM)); |
| 790 | 785 |
| 791 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 786 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
| 792 SkPixmap pm; | 787 SkPixmap pm; |
| 793 REPORTER_ASSERT(reporter, image->peekPixels(&pm)); | 788 REPORTER_ASSERT(reporter, image->peekPixels(&pm)); |
| 794 | 789 |
| 795 REPORTER_ASSERT(reporter, surfacePM.rowBytes() == pm.rowBytes()); | 790 REPORTER_ASSERT(reporter, surfacePM.rowBytes() == pm.rowBytes()); |
| 796 | 791 |
| 797 // trigger a copy-on-write | 792 // trigger a copy-on-write |
| 798 surface->getCanvas()->drawPaint(SkPaint()); | 793 surface->getCanvas()->drawPaint(SkPaint()); |
| 799 sk_sp<SkImage> image2(surface->makeImageSnapshot()); | 794 sk_sp<SkImage> image2(surface->makeImageSnapshot()); |
| 800 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID()); | 795 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID()); |
| 801 | 796 |
| 802 SkPixmap pm2; | 797 SkPixmap pm2; |
| 803 REPORTER_ASSERT(reporter, image2->peekPixels(&pm2)); | 798 REPORTER_ASSERT(reporter, image2->peekPixels(&pm2)); |
| 804 REPORTER_ASSERT(reporter, pm2.rowBytes() == pm.rowBytes()); | 799 REPORTER_ASSERT(reporter, pm2.rowBytes() == pm.rowBytes()); |
| 805 } | 800 } |
| 806 | 801 |
| 807 DEF_TEST(surface_rowbytes, reporter) { | 802 DEF_TEST(surface_rowbytes, reporter) { |
| 808 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 803 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 809 | 804 |
| 810 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRaster(info)); | 805 auto surf0(SkSurface::MakeRaster(info)); |
| 811 check_rowbytes_remain_consistent(surf0, reporter); | 806 check_rowbytes_remain_consistent(surf0.get(), reporter); |
| 812 | 807 |
| 813 // specify a larger rowbytes | 808 // specify a larger rowbytes |
| 814 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr)); | 809 auto surf1(SkSurface::MakeRaster(info, 500, nullptr)); |
| 815 check_rowbytes_remain_consistent(surf1, reporter); | 810 check_rowbytes_remain_consistent(surf1.get(), reporter); |
| 816 | 811 |
| 817 // Try some illegal rowByte values | 812 // Try some illegal rowByte values |
| 818 SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be a
t least 400 | 813 auto s = SkSurface::MakeRaster(info, 396, nullptr); // needs to be at lea
st 400 |
| 819 REPORTER_ASSERT(reporter, nullptr == s); | 814 REPORTER_ASSERT(reporter, nullptr == s); |
| 820 s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large | 815 s = SkSurface::MakeRaster(info, 1 << 30, nullptr); // allocation to large |
| 821 REPORTER_ASSERT(reporter, nullptr == s); | 816 REPORTER_ASSERT(reporter, nullptr == s); |
| 822 } | 817 } |
| 823 | 818 |
| 824 #if SK_SUPPORT_GPU | 819 #if SK_SUPPORT_GPU |
| 825 | 820 |
| 826 void test_surface_clear(skiatest::Reporter* reporter, SkSurface* surfacePtr, | 821 void test_surface_clear(skiatest::Reporter* reporter, sk_sp<SkSurface> surface, |
| 827 std::function<GrSurface*(SkSurface*)> grSurfaceGetter, | 822 std::function<GrSurface*(SkSurface*)> grSurfaceGetter, |
| 828 uint32_t expectedValue) { | 823 uint32_t expectedValue) { |
| 829 SkAutoTUnref<SkSurface> surface(surfacePtr); | |
| 830 if (!surface) { | 824 if (!surface) { |
| 831 ERRORF(reporter, "Could not create GPU SkSurface."); | 825 ERRORF(reporter, "Could not create GPU SkSurface."); |
| 832 return; | 826 return; |
| 833 } | 827 } |
| 834 int w = surface->width(); | 828 int w = surface->width(); |
| 835 int h = surface->height(); | 829 int h = surface->height(); |
| 836 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]); | 830 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]); |
| 837 memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h); | 831 memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h); |
| 838 | 832 |
| 839 SkAutoTUnref<GrSurface> grSurface(SkSafeRef(grSurfaceGetter(surface))); | 833 SkAutoTUnref<GrSurface> grSurface(SkSafeRef(grSurfaceGetter(surface.get())))
; |
| 840 if (!grSurface) { | 834 if (!grSurface) { |
| 841 ERRORF(reporter, "Could access render target of GPU SkSurface."); | 835 ERRORF(reporter, "Could access render target of GPU SkSurface."); |
| 842 return; | 836 return; |
| 843 } | 837 } |
| 844 SkASSERT(surface->unique()); | |
| 845 surface.reset(); | 838 surface.reset(); |
| 846 grSurface->readPixels(0, 0, w, h, kRGBA_8888_GrPixelConfig, pixels.get()); | 839 grSurface->readPixels(0, 0, w, h, kRGBA_8888_GrPixelConfig, pixels.get()); |
| 847 for (int y = 0; y < h; ++y) { | 840 for (int y = 0; y < h; ++y) { |
| 848 for (int x = 0; x < w; ++x) { | 841 for (int x = 0; x < w; ++x) { |
| 849 uint32_t pixel = pixels.get()[y * w + x]; | 842 uint32_t pixel = pixels.get()[y * w + x]; |
| 850 if (pixel != expectedValue) { | 843 if (pixel != expectedValue) { |
| 851 SkString msg; | 844 SkString msg; |
| 852 if (expectedValue) { | 845 if (expectedValue) { |
| 853 msg = "SkSurface should have left render target unmodified"; | 846 msg = "SkSurface should have left render target unmodified"; |
| 854 } else { | 847 } else { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 868 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye
rRenderTarget(); }, | 861 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye
rRenderTarget(); }, |
| 869 [] (SkSurface* s){ | 862 [] (SkSurface* s){ |
| 870 SkBaseDevice* d = | 863 SkBaseDevice* d = |
| 871 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); | 864 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test
ing(); |
| 872 return d->accessRenderTarget(); }, | 865 return d->accessRenderTarget(); }, |
| 873 [] (SkSurface* s){ sk_sp<SkImage> i(s->makeImageSnapshot()); | 866 [] (SkSurface* s){ sk_sp<SkImage> i(s->makeImageSnapshot()); |
| 874 return as_IB(i)->peekTexture(); }, | 867 return as_IB(i)->peekTexture(); }, |
| 875 }; | 868 }; |
| 876 for (auto grSurfaceGetter : grSurfaceGetters) { | 869 for (auto grSurfaceGetter : grSurfaceGetters) { |
| 877 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surf
ace}) { | 870 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surf
ace}) { |
| 878 SkSurface* surface = surface_func(context, kPremul_SkAlphaType, null
ptr); | 871 auto surface = surface_func(context, kPremul_SkAlphaType, nullptr); |
| 879 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0); | 872 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0); |
| 880 } | 873 } |
| 881 // Wrapped RTs are *not* supposed to clear (to allow client to partially
update a surface). | 874 // Wrapped RTs are *not* supposed to clear (to allow client to partially
update a surface). |
| 882 static const int kWidth = 10; | 875 static const int kWidth = 10; |
| 883 static const int kHeight = 10; | 876 static const int kHeight = 10; |
| 884 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[kWidth * kHeight]); | 877 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[kWidth * kHeight]); |
| 885 memset(pixels.get(), 0xAB, sizeof(uint32_t) * kWidth * kHeight); | 878 memset(pixels.get(), 0xAB, sizeof(uint32_t) * kWidth * kHeight); |
| 886 | 879 |
| 887 GrBackendObject textureObject = | 880 GrBackendObject textureObject = |
| 888 context->getGpu()->createTestingOnlyBackendTexture(pixels.get(),
kWidth, kHeight, | 881 context->getGpu()->createTestingOnlyBackendTexture(pixels.get(),
kWidth, kHeight, |
| 889 kRGBA_8888_Gr
PixelConfig); | 882 kRGBA_8888_Gr
PixelConfig); |
| 890 | 883 |
| 891 GrBackendTextureDesc desc; | 884 GrBackendTextureDesc desc; |
| 892 desc.fConfig = kRGBA_8888_GrPixelConfig; | 885 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 893 desc.fWidth = kWidth; | 886 desc.fWidth = kWidth; |
| 894 desc.fHeight = kHeight; | 887 desc.fHeight = kHeight; |
| 895 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 888 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 896 desc.fTextureHandle = textureObject; | 889 desc.fTextureHandle = textureObject; |
| 897 | 890 |
| 898 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul
lptr); | 891 auto surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr)
; |
| 899 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); | 892 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); |
| 900 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); | 893 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
| 901 } | 894 } |
| 902 } | 895 } |
| 903 #endif | 896 #endif |
| OLD | NEW |