| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 release_direct_surface_storage
, | 49 release_direct_surface_storage
, |
| 50 storage); | 50 storage); |
| 51 } | 51 } |
| 52 #if SK_SUPPORT_GPU | 52 #if SK_SUPPORT_GPU |
| 53 static sk_sp<SkSurface> create_gpu_surface(GrContext* context, SkAlphaType at =
kPremul_SkAlphaType, | 53 static sk_sp<SkSurface> create_gpu_surface(GrContext* context, SkAlphaType at =
kPremul_SkAlphaType, |
| 54 SkImageInfo* requestedInfo = nullptr)
{ | 54 SkImageInfo* requestedInfo = nullptr)
{ |
| 55 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); | 55 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
| 56 if (requestedInfo) { | 56 if (requestedInfo) { |
| 57 *requestedInfo = info; | 57 *requestedInfo = info; |
| 58 } | 58 } |
| 59 return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullpt
r); | 59 return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); |
| 60 } | 60 } |
| 61 static sk_sp<SkSurface> create_gpu_scratch_surface(GrContext* context, | 61 static sk_sp<SkSurface> create_gpu_scratch_surface(GrContext* context, |
| 62 SkAlphaType at = kPremul_SkAl
phaType, | 62 SkAlphaType at = kPremul_SkAl
phaType, |
| 63 SkImageInfo* requestedInfo =
nullptr) { | 63 SkImageInfo* requestedInfo =
nullptr) { |
| 64 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); | 64 const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); |
| 65 if (requestedInfo) { | 65 if (requestedInfo) { |
| 66 *requestedInfo = info; | 66 *requestedInfo = info; |
| 67 } | 67 } |
| 68 return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0, nullp
tr); | 68 return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info); |
| 69 } | 69 } |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 DEF_TEST(SurfaceEmpty, reporter) { | 72 DEF_TEST(SurfaceEmpty, reporter) { |
| 73 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 73 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 74 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); | 74 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); |
| 75 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp
tr, 0)); | 75 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp
tr, 0)); |
| 76 | 76 |
| 77 } | 77 } |
| 78 #if SK_SUPPORT_GPU | 78 #if SK_SUPPORT_GPU |
| 79 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { | 79 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { |
| 80 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); | 80 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S
kAlphaType); |
| 81 REPORTER_ASSERT(reporter, nullptr == | 81 REPORTER_ASSERT(reporter, nullptr == |
| 82 SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted:
:kNo, info, 0, | 82 SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted:
:kNo, info)); |
| 83 nullptr)); | |
| 84 } | 83 } |
| 85 #endif | 84 #endif |
| 86 | 85 |
| 87 static void test_canvas_peek(skiatest::Reporter* reporter, | 86 static void test_canvas_peek(skiatest::Reporter* reporter, |
| 88 sk_sp<SkSurface>& surface, | 87 sk_sp<SkSurface>& surface, |
| 89 const SkImageInfo& requestInfo, | 88 const SkImageInfo& requestInfo, |
| 90 bool expectPeekSuccess) { | 89 bool expectPeekSuccess) { |
| 91 const SkColor color = SK_ColorRED; | 90 const SkColor color = SK_ColorRED; |
| 92 const SkPMColor pmcolor = SkPreMultiplyColor(color); | 91 const SkPMColor pmcolor = SkPreMultiplyColor(color); |
| 93 surface->getCanvas()->clear(color); | 92 surface->getCanvas()->clear(color); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 327 |
| 329 // Test again with a "direct" render target; | 328 // Test again with a "direct" render target; |
| 330 GrBackendObject textureObject = context->getGpu()->createTestingOnlyBack
endTexture(nullptr, | 329 GrBackendObject textureObject = context->getGpu()->createTestingOnlyBack
endTexture(nullptr, |
| 331 10, 10, kRGBA_8888_GrPixelConfig, true); | 330 10, 10, kRGBA_8888_GrPixelConfig, true); |
| 332 GrBackendTextureDesc desc; | 331 GrBackendTextureDesc desc; |
| 333 desc.fConfig = kRGBA_8888_GrPixelConfig; | 332 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 334 desc.fWidth = 10; | 333 desc.fWidth = 10; |
| 335 desc.fHeight = 10; | 334 desc.fHeight = 10; |
| 336 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 335 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 337 desc.fTextureHandle = textureObject; | 336 desc.fTextureHandle = textureObject; |
| 338 GrTexture* texture = context->textureProvider()->wrapBackendTexture(desc
); | 337 |
| 339 { | 338 { |
| 340 auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarg
et(), nullptr)); | 339 sk_sp<SkSurface> surface(SkSurface::MakeFromBackendTexture(context,
desc, nullptr)); |
| 341 test_unique_image_snap(reporter, surface.get(), true, imageBackingSt
ore, | 340 test_unique_image_snap(reporter, surface.get(), true, imageBackingSt
ore, |
| 342 surfaceBackingStore); | 341 surfaceBackingStore); |
| 343 } | 342 } |
| 344 texture->unref(); | 343 |
| 345 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); | 344 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); |
| 346 } | 345 } |
| 347 } | 346 } |
| 348 #endif | 347 #endif |
| 349 | 348 |
| 350 #if SK_SUPPORT_GPU | 349 #if SK_SUPPORT_GPU |
| 351 | 350 |
| 352 static void test_backend_handle_unique_id( | 351 static void test_backend_handle_unique_id( |
| 353 skiatest::Reporter* reporter, SkSurface* surface, | 352 skiatest::Reporter* reporter, SkSurface* surface, |
| 354 GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) { | 353 GrBackendObject (*func)(SkSurface*, SkSurface::BackendHandleAccess)) { |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 // our surface functions. | 904 // our surface functions. |
| 906 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo
pLayerDrawContext() | 905 GrRenderTarget* rt = surface->getCanvas()->internal_private_accessTo
pLayerDrawContext() |
| 907 ->accessRenderTarget(); | 906 ->accessRenderTarget(); |
| 908 REPORTER_ASSERT(reporter, | 907 REPORTER_ASSERT(reporter, |
| 909 ctxInfo.grContext()->resourceProvider()->attachStenc
ilAttachment(rt)); | 908 ctxInfo.grContext()->resourceProvider()->attachStenc
ilAttachment(rt)); |
| 910 gpu->deleteTestingOnlyBackendTexture(textureObject); | 909 gpu->deleteTestingOnlyBackendTexture(textureObject); |
| 911 } | 910 } |
| 912 } | 911 } |
| 913 } | 912 } |
| 914 #endif | 913 #endif |
| OLD | NEW |