Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1734043002: Revert of Move Budgeted enum out of SkSurface, use in GrTextureProvider (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/SpecialImageTest.cpp ('k') | tests/TextBlobCacheTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SkSurface* create_gpu_surface(GrContext* context, SkAlphaType at = kPremu l_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::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr);
58 } 58 }
59 static SkSurface* create_gpu_scratch_surface(GrContext* context, 59 static SkSurface* create_gpu_scratch_surface(GrContext* context,
60 SkAlphaType at = kPremul_SkAlphaTyp e, 60 SkAlphaType at = kPremul_SkAlphaTyp e,
61 SkImageInfo* requestedInfo = nullpt r) { 61 SkImageInfo* requestedInfo = nullpt r) {
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::NewRenderTarget(context, SkSurface::kYes_Budgeted, info, 0 , nullptr);
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::NewRaster(info));
73 REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRasterDirect(info, nullpt r, 0)); 73 REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRasterDirect(info, nullpt r, 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::NewRenderTarget(context, SkSurface::kNo_Budgeted, 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
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 std::function<intptr_t(SkSurface*)> getSurfaceBackin gStore) { 333 std::function<intptr_t(SkSurface*)> getSurfaceBackin gStore) {
334 return getImageBackingStore(a) == getSurfaceBackingStore(b); 334 return getImageBackingStore(a) == getSurfaceBackingStore(b);
335 } 335 }
336 336
337 static void test_unique_image_snap(skiatest::Reporter* reporter, SkSurface* surf ace, 337 static void test_unique_image_snap(skiatest::Reporter* reporter, SkSurface* surf ace,
338 bool surfaceIsDirect, 338 bool surfaceIsDirect,
339 std::function<intptr_t(SkImage*)> imageBackin gStore, 339 std::function<intptr_t(SkImage*)> imageBackin gStore,
340 std::function<intptr_t(SkSurface*)> surfaceBa ckingStore) { 340 std::function<intptr_t(SkSurface*)> surfaceBa ckingStore) {
341 std::function<intptr_t(SkImage*)> ibs = imageBackingStore; 341 std::function<intptr_t(SkImage*)> ibs = imageBackingStore;
342 std::function<intptr_t(SkSurface*)> sbs = surfaceBackingStore; 342 std::function<intptr_t(SkSurface*)> sbs = surfaceBackingStore;
343 static const SkBudgeted kB = SkBudgeted::kNo; 343 static const SkSurface::Budgeted kB = SkSurface::kNo_Budgeted;
344 { 344 {
345 SkAutoTUnref<SkImage> image(surface->newImageSnapshot(kB, SkSurface::kYe s_ForceUnique)); 345 SkAutoTUnref<SkImage> image(surface->newImageSnapshot(kB, SkSurface::kYe s_ForceUnique));
346 REPORTER_ASSERT(reporter, !same_image_surf(image, surface, ibs, sbs)); 346 REPORTER_ASSERT(reporter, !same_image_surf(image, surface, ibs, sbs));
347 REPORTER_ASSERT(reporter, image->unique()); 347 REPORTER_ASSERT(reporter, image->unique());
348 } 348 }
349 { 349 {
350 SkAutoTUnref<SkImage> image1(surface->newImageSnapshot(kB, SkSurface::kY es_ForceUnique)); 350 SkAutoTUnref<SkImage> image1(surface->newImageSnapshot(kB, SkSurface::kY es_ForceUnique));
351 REPORTER_ASSERT(reporter, !same_image_surf(image1, surface, ibs, sbs)); 351 REPORTER_ASSERT(reporter, !same_image_surf(image1, surface, ibs, sbs));
352 REPORTER_ASSERT(reporter, image1->unique()); 352 REPORTER_ASSERT(reporter, image1->unique());
353 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot(kB, SkSurface::kY es_ForceUnique)); 353 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot(kB, SkSurface::kY es_ForceUnique));
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 } 692 }
693 } 693 }
694 #endif 694 #endif
695 695
696 #if SK_SUPPORT_GPU 696 #if SK_SUPPORT_GPU
697 #include "GrGpuResourcePriv.h" 697 #include "GrGpuResourcePriv.h"
698 #include "SkGpuDevice.h" 698 #include "SkGpuDevice.h"
699 #include "SkImage_Gpu.h" 699 #include "SkImage_Gpu.h"
700 #include "SkSurface_Gpu.h" 700 #include "SkSurface_Gpu.h"
701 701
702 static SkBudgeted is_budgeted(SkSurface* surf) { 702 static SkSurface::Budgeted is_budgeted(SkSurface* surf) {
703 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePr iv().isBudgeted(); 703 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePr iv().isBudgeted() ?
704 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
704 } 705 }
705 706
706 static SkBudgeted is_budgeted(SkImage* image) { 707 static SkSurface::Budgeted is_budgeted(SkImage* image) {
707 return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted(); 708 return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted() ?
709 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
708 } 710 }
709 711
710 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { 712 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) {
711 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); 713 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8);
712 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { 714 for (int i = 0; i < 2; ++i) {
713 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { 715 SkSurface::Budgeted sbudgeted = i ? SkSurface::kYes_Budgeted : SkSurface ::kNo_Budgeted;
716 for (int j = 0; j < 2; ++j) {
717 SkSurface::Budgeted ibudgeted = j ? SkSurface::kYes_Budgeted : SkSur face::kNo_Budgeted;
714 SkAutoTUnref<SkSurface> 718 SkAutoTUnref<SkSurface>
715 surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0)) ; 719 surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0)) ;
716 SkASSERT(surface); 720 SkASSERT(surface);
717 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); 721 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
718 722
719 SkAutoTUnref<SkImage> image(surface->newImageSnapshot(ibudgeted)); 723 SkAutoTUnref<SkImage> image(surface->newImageSnapshot(ibudgeted));
720 724
721 // Initially the image shares a texture with the surface, and the su rface decides 725 // Initially the image shares a texture with the surface, and the su rface decides
722 // whether it is budgeted or not. 726 // whether it is budgeted or not.
723 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); 727 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 desc.fHeight = kHeight; 906 desc.fHeight = kHeight;
903 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 907 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
904 desc.fTextureHandle = textureObject; 908 desc.fTextureHandle = textureObject;
905 909
906 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul lptr); 910 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul lptr);
907 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); 911 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB);
908 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); 912 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject);
909 } 913 }
910 } 914 }
911 #endif 915 #endif
OLDNEW
« no previous file with comments | « tests/SpecialImageTest.cpp ('k') | tests/TextBlobCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698