| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 <initializer_list> | 9 #include <initializer_list> |
| 10 #include "DMGpuSupport.h" | 10 #include "DMGpuSupport.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 #include "SkBitmapCache.h" | 362 #include "SkBitmapCache.h" |
| 363 | 363 |
| 364 /* | 364 /* |
| 365 * This tests the caching (and preemptive purge) of the raster equivalent of a
gpu-image. | 365 * This tests the caching (and preemptive purge) of the raster equivalent of a
gpu-image. |
| 366 * We cache it for performance when drawing into a raster surface. | 366 * We cache it for performance when drawing into a raster surface. |
| 367 * | 367 * |
| 368 * A cleaner test would know if each drawImage call triggered a read-back from
the gpu, | 368 * A cleaner test would know if each drawImage call triggered a read-back from
the gpu, |
| 369 * but we don't have that facility (at the moment) so we use a little internal
knowledge | 369 * but we don't have that facility (at the moment) so we use a little internal
knowledge |
| 370 * of *how* the raster version is cached, and look for that. | 370 * of *how* the raster version is cached, and look for that. |
| 371 */ | 371 */ |
| 372 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_Gpu2Cpu, reporter, context) { | 372 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_Gpu2Cpu, reporter, context) { |
| 373 SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 373 SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
| 374 sk_sp<SkImage> image(create_gpu_image(context)); | 374 sk_sp<SkImage> image(create_gpu_image(context)); |
| 375 const uint32_t uniqueID = image->uniqueID(); | 375 const uint32_t uniqueID = image->uniqueID(); |
| 376 | 376 |
| 377 auto surface(SkSurface::MakeRaster(info)); | 377 auto surface(SkSurface::MakeRaster(info)); |
| 378 | 378 |
| 379 // now we can test drawing a gpu-backed image into a cpu-backed surface | 379 // now we can test drawing a gpu-backed image into a cpu-backed surface |
| 380 | 380 |
| 381 { | 381 { |
| 382 SkBitmap cachedBitmap; | 382 SkBitmap cachedBitmap; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 | 399 |
| 400 image.reset(nullptr); | 400 image.reset(nullptr); |
| 401 { | 401 { |
| 402 SkBitmap cachedBitmap; | 402 SkBitmap cachedBitmap; |
| 403 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; | 403 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; |
| 404 } | 404 } |
| 405 } | 405 } |
| 406 | 406 |
| 407 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_newTextureImage, reporter, context, glCon
text) { | 407 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_newTextureImage, reporter, context, g
lContext) { |
| 408 GrContextFactory otherFactory; | 408 GrContextFactory otherFactory; |
| 409 GrContextFactory::ContextInfo otherContextInfo = | 409 GrContextFactory::ContextInfo otherContextInfo = |
| 410 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); | 410 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); |
| 411 glContext->makeCurrent(); | 411 glContext->makeCurrent(); |
| 412 | 412 |
| 413 std::function<sk_sp<SkImage>()> imageFactories[] = { | 413 std::function<sk_sp<SkImage>()> imageFactories[] = { |
| 414 create_image, | 414 create_image, |
| 415 create_codec_image, | 415 create_codec_image, |
| 416 create_data_image, | 416 create_data_image, |
| 417 // Create an image from a picture. | 417 // Create an image from a picture. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 static void Release(void* self) { | 694 static void Release(void* self) { |
| 695 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; | 695 static_cast<TextureReleaseChecker*>(self)->fReleaseCount++; |
| 696 } | 696 } |
| 697 }; | 697 }; |
| 698 static void check_image_color(skiatest::Reporter* reporter, SkImage* image, SkPM
Color expected) { | 698 static void check_image_color(skiatest::Reporter* reporter, SkImage* image, SkPM
Color expected) { |
| 699 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 699 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 700 SkPMColor pixel; | 700 SkPMColor pixel; |
| 701 REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0,
0)); | 701 REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0,
0)); |
| 702 REPORTER_ASSERT(reporter, pixel == expected); | 702 REPORTER_ASSERT(reporter, pixel == expected); |
| 703 } | 703 } |
| 704 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_NewFromTexture, reporter, context) { | 704 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_NewFromTexture, reporter, context) { |
| 705 GrTextureProvider* provider = context->textureProvider(); | 705 GrTextureProvider* provider = context->textureProvider(); |
| 706 const int w = 10; | 706 const int w = 10; |
| 707 const int h = 10; | 707 const int h = 10; |
| 708 SkPMColor storage[w * h]; | 708 SkPMColor storage[w * h]; |
| 709 const SkPMColor expected0 = SkPreMultiplyColor(SK_ColorRED); | 709 const SkPMColor expected0 = SkPreMultiplyColor(SK_ColorRED); |
| 710 sk_memset32(storage, expected0, w * h); | 710 sk_memset32(storage, expected0, w * h); |
| 711 GrSurfaceDesc desc; | 711 GrSurfaceDesc desc; |
| 712 desc.fFlags = kRenderTarget_GrSurfaceFlag; // needs to be a rendertarget fo
r readpixels(); | 712 desc.fFlags = kRenderTarget_GrSurfaceFlag; // needs to be a rendertarget fo
r readpixels(); |
| 713 desc.fOrigin = kDefault_GrSurfaceOrigin; | 713 desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 714 desc.fWidth = w; | 714 desc.fWidth = w; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 SkBudgeted::k
No)); | 813 SkBudgeted::k
No)); |
| 814 if (!texImage) { | 814 if (!texImage) { |
| 815 ERRORF(reporter, "NewTextureFromPixmap failed."); | 815 ERRORF(reporter, "NewTextureFromPixmap failed."); |
| 816 } else { | 816 } else { |
| 817 check_images_same(reporter, image.get(), texImage.get()); | 817 check_images_same(reporter, image.get(), texImage.get()); |
| 818 } | 818 } |
| 819 } | 819 } |
| 820 } | 820 } |
| 821 } | 821 } |
| 822 | 822 |
| 823 DEF_GPUTEST_FOR_NATIVE_CONTEXT(DeferredTextureImage, reporter, context, glContex
t) { | 823 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredTextureImage, reporter, context, glCo
ntext) { |
| 824 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); | 824 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy()); |
| 825 | 825 |
| 826 GrContextFactory otherFactory; | 826 GrContextFactory otherFactory; |
| 827 GrContextFactory::ContextInfo otherContextInfo = | 827 GrContextFactory::ContextInfo otherContextInfo = |
| 828 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); | 828 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); |
| 829 | 829 |
| 830 glContext->makeCurrent(); | 830 glContext->makeCurrent(); |
| 831 REPORTER_ASSERT(reporter, proxy); | 831 REPORTER_ASSERT(reporter, proxy); |
| 832 struct { | 832 struct { |
| 833 std::function<sk_sp<SkImage> ()> fImageFactory; | 833 std::function<sk_sp<SkImage> ()> fImageFactory; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 otherContextInfo.fGrContext, buffer, budgeted)); | 885 otherContextInfo.fGrContext, buffer, budgeted)); |
| 886 REPORTER_ASSERT(reporter, !newImage2); | 886 REPORTER_ASSERT(reporter, !newImage2); |
| 887 glContext->makeCurrent(); | 887 glContext->makeCurrent(); |
| 888 } | 888 } |
| 889 } | 889 } |
| 890 sk_free(buffer); | 890 sk_free(buffer); |
| 891 } | 891 } |
| 892 } | 892 } |
| 893 } | 893 } |
| 894 #endif | 894 #endif |
| OLD | NEW |