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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 939093002: Recycle stencil buffers across render targets. (Closed) Base URL: https://skia.googlesource.com/skia.git@keychange
Patch Set: Address comments Created 5 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 | « src/gpu/gl/GrGLStencilBuffer.h ('k') | no next file » | 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 #if SK_SUPPORT_GPU 8 #if SK_SUPPORT_GPU
9 9
10 #include "GrContext.h" 10 #include "GrContext.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 size_t curCacheSize; 56 size_t curCacheSize;
57 context->getResourceCacheUsage(NULL, &curCacheSize); 57 context->getResourceCacheUsage(NULL, &curCacheSize);
58 58
59 // we should never go over the size limit 59 // we should never go over the size limit
60 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize); 60 REPORTER_ASSERT(reporter, curCacheSize <= maxCacheSize);
61 } 61 }
62 62
63 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); 63 context->setResourceCacheLimits(oldMaxNum, oldMaxBytes);
64 } 64 }
65 65
66 static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex t) {
67 GrSurfaceDesc smallDesc;
68 smallDesc.fFlags = kRenderTarget_GrSurfaceFlag;
69 smallDesc.fConfig = kSkia8888_GrPixelConfig;
70 smallDesc.fWidth = 4;
71 smallDesc.fHeight = 4;
72 smallDesc.fSampleCnt = 0;
73
74 // Test that two budgeted RTs with the same desc share a stencil buffer.
75 SkAutoTUnref<GrTexture> smallRT0(context->createTexture(smallDesc, true));
76 SkAutoTUnref<GrTexture> smallRT1(context->createTexture(smallDesc, true));
77 REPORTER_ASSERT(reporter, smallRT0 && smallRT1 &&
78 smallRT0->asRenderTarget() && smallRT1->asRenderTa rget() &&
79 smallRT0->asRenderTarget()->getStencilBuffer() ==
80 smallRT1->asRenderTarget()->getStencilBuffer());
81
82 // An unbudgeted RT with the same desc should also share.
83 SkAutoTUnref<GrTexture> smallRT2(context->createTexture(smallDesc, false));
84 REPORTER_ASSERT(reporter, smallRT0 && smallRT2 &&
85 smallRT0->asRenderTarget() && smallRT2->asRenderTa rget() &&
86 smallRT0->asRenderTarget()->getStencilBuffer() ==
87 smallRT2->asRenderTarget()->getStencilBuffer());
88
89 // An RT with a much larger size should not share.
90 GrSurfaceDesc bigDesc;
91 bigDesc.fFlags = kRenderTarget_GrSurfaceFlag;
92 bigDesc.fConfig = kSkia8888_GrPixelConfig;
93 bigDesc.fWidth = 400;
94 bigDesc.fHeight = 200;
95 bigDesc.fSampleCnt = 0;
96 SkAutoTUnref<GrTexture> bigRT(context->createTexture(bigDesc, false));
97 REPORTER_ASSERT(reporter, smallRT0 && bigRT &&
98 smallRT0->asRenderTarget() && bigRT->asRenderTarge t() &&
99 smallRT0->asRenderTarget()->getStencilBuffer() !=
100 bigRT->asRenderTarget()->getStencilBuffer());
101
102 if (context->getMaxSampleCount() >= 4) {
103 // An RT with a different sample count should not share.
104 GrSurfaceDesc smallMSAADesc = smallDesc;
105 smallMSAADesc.fSampleCnt = 4;
106 SkAutoTUnref<GrTexture> smallMSAART0(context->createTexture(smallMSAADes c, false));
107 REPORTER_ASSERT(reporter, smallRT0 && smallMSAART0 &&
108 smallRT0->asRenderTarget() && smallMSAART0->as RenderTarget() &&
109 smallRT0->asRenderTarget()->getStencilBuffer() !=
110 smallMSAART0->asRenderTarget()->getStencilBuff er());
111 // A second MSAA RT should share with the first MSAA RT.
112 SkAutoTUnref<GrTexture> smallMSAART1(context->createTexture(smallMSAADes c, false));
113 REPORTER_ASSERT(reporter, smallMSAART0 && smallMSAART1 &&
114 smallMSAART0->asRenderTarget() &&
115 smallMSAART1->asRenderTarget() &&
116 smallMSAART0->asRenderTarget()->getStencilBuff er() ==
117 smallMSAART1->asRenderTarget()->getStencilBuff er());
118 // But not one with a larger sample count should not. (Also check that t he request for 4
119 // samples didn't get rounded up to >= 8 or else they could share.).
120 if (context->getMaxSampleCount() >= 8 && smallMSAART0 && smallMSAART0->a sRenderTarget() &&
121 smallMSAART0->asRenderTarget()->numSamples() < 8) {
122 smallMSAADesc.fSampleCnt = 8;
123 smallMSAART1.reset(context->createTexture(smallMSAADesc, false));
124 REPORTER_ASSERT(reporter, smallMSAART0 && smallMSAART1 &&
125 smallMSAART0->asRenderTarget() &&
126 smallMSAART1->asRenderTarget() &&
127 smallMSAART0->asRenderTarget()->getStencil Buffer() !=
128 smallMSAART1->asRenderTarget()->getStencil Buffer());
129 }
130 }
131 }
132
66 class TestResource : public GrGpuResource { 133 class TestResource : public GrGpuResource {
67 static const size_t kDefaultSize = 100; 134 static const size_t kDefaultSize = 100;
68 enum ScratchConstructor { kScratchConstructor }; 135 enum ScratchConstructor { kScratchConstructor };
69 public: 136 public:
70 SK_DECLARE_INST_COUNT(TestResource); 137 SK_DECLARE_INST_COUNT(TestResource);
71 /** Property that distinctly categorizes the resource. 138 /** Property that distinctly categorizes the resource.
72 * For example, textures have width, height, ... */ 139 * For example, textures have width, height, ... */
73 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; 140 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty };
74 141
75 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle) 142 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle)
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 } 996 }
930 GrSurfaceDesc desc; 997 GrSurfaceDesc desc;
931 desc.fConfig = kSkia8888_GrPixelConfig; 998 desc.fConfig = kSkia8888_GrPixelConfig;
932 desc.fFlags = kRenderTarget_GrSurfaceFlag; 999 desc.fFlags = kRenderTarget_GrSurfaceFlag;
933 desc.fWidth = gWidth; 1000 desc.fWidth = gWidth;
934 desc.fHeight = gHeight; 1001 desc.fHeight = gHeight;
935 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); 1002 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
936 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, 1003 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context,
937 SkSurface::kN o_Budgeted, info)); 1004 SkSurface::kN o_Budgeted, info));
938 test_cache(reporter, context, surface->getCanvas()); 1005 test_cache(reporter, context, surface->getCanvas());
1006 test_stencil_buffers(reporter, context);
939 } 1007 }
940 1008
941 // The below tests create their own mock contexts. 1009 // The below tests create their own mock contexts.
942 test_no_key(reporter); 1010 test_no_key(reporter);
943 test_budgeting(reporter); 1011 test_budgeting(reporter);
944 test_unbudgeted(reporter); 1012 test_unbudgeted(reporter);
945 test_unbudgeted_to_scratch(reporter); 1013 test_unbudgeted_to_scratch(reporter);
946 test_duplicate_unique_key(reporter); 1014 test_duplicate_unique_key(reporter);
947 test_duplicate_scratch_key(reporter); 1015 test_duplicate_scratch_key(reporter);
948 test_remove_scratch_key(reporter); 1016 test_remove_scratch_key(reporter);
949 test_scratch_key_consistency(reporter); 1017 test_scratch_key_consistency(reporter);
950 test_purge_invalidated(reporter); 1018 test_purge_invalidated(reporter);
951 test_cache_chained_purge(reporter); 1019 test_cache_chained_purge(reporter);
952 test_resource_size_changed(reporter); 1020 test_resource_size_changed(reporter);
953 test_large_resource_count(reporter); 1021 test_large_resource_count(reporter);
954 } 1022 }
955 1023
956 #endif 1024 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLStencilBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698