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

Side by Side Diff: tests/ResourceCacheTest.cpp

Issue 938383004: Dynamically create stencil buffer when needed. (Closed) Base URL: https://skia.googlesource.com/skia.git@bigstencil
Patch Set: Actually save file before uploading 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 | « tests/ReadPixelsTest.cpp ('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"
11 #include "GrContextFactory.h" 11 #include "GrContextFactory.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 #include "GrGpuResourceCacheAccess.h" 13 #include "GrGpuResourceCacheAccess.h"
14 #include "GrGpuResourcePriv.h" 14 #include "GrGpuResourcePriv.h"
15 #include "GrRenderTarget.h"
16 #include "GrRenderTargetPriv.h"
15 #include "GrResourceCache.h" 17 #include "GrResourceCache.h"
16 #include "SkCanvas.h" 18 #include "SkCanvas.h"
17 #include "SkGr.h" 19 #include "SkGr.h"
18 #include "SkMessageBus.h" 20 #include "SkMessageBus.h"
19 #include "SkSurface.h" 21 #include "SkSurface.h"
20 #include "Test.h" 22 #include "Test.h"
21 23
22 static const int gWidth = 640; 24 static const int gWidth = 640;
23 static const int gHeight = 480; 25 static const int gHeight = 480;
24 26
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex t) { 68 static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex t) {
67 GrSurfaceDesc smallDesc; 69 GrSurfaceDesc smallDesc;
68 smallDesc.fFlags = kRenderTarget_GrSurfaceFlag; 70 smallDesc.fFlags = kRenderTarget_GrSurfaceFlag;
69 smallDesc.fConfig = kSkia8888_GrPixelConfig; 71 smallDesc.fConfig = kSkia8888_GrPixelConfig;
70 smallDesc.fWidth = 4; 72 smallDesc.fWidth = 4;
71 smallDesc.fHeight = 4; 73 smallDesc.fHeight = 4;
72 smallDesc.fSampleCnt = 0; 74 smallDesc.fSampleCnt = 0;
73 75
74 // Test that two budgeted RTs with the same desc share a stencil buffer. 76 // Test that two budgeted RTs with the same desc share a stencil buffer.
75 SkAutoTUnref<GrTexture> smallRT0(context->createTexture(smallDesc, true)); 77 SkAutoTUnref<GrTexture> smallRT0(context->createTexture(smallDesc, true));
78 if (smallRT0 && smallRT0->asRenderTarget()) {
79 smallRT0->asRenderTarget()->renderTargetPriv().attachStencilBuffer();
80 }
81
76 SkAutoTUnref<GrTexture> smallRT1(context->createTexture(smallDesc, true)); 82 SkAutoTUnref<GrTexture> smallRT1(context->createTexture(smallDesc, true));
83 if (smallRT1 && smallRT1->asRenderTarget()) {
84 smallRT1->asRenderTarget()->renderTargetPriv().attachStencilBuffer();
85 }
86
77 REPORTER_ASSERT(reporter, smallRT0 && smallRT1 && 87 REPORTER_ASSERT(reporter, smallRT0 && smallRT1 &&
78 smallRT0->asRenderTarget() && smallRT1->asRenderTa rget() && 88 smallRT0->asRenderTarget() && smallRT1->asRenderTa rget() &&
79 smallRT0->asRenderTarget()->getStencilBuffer() == 89 smallRT0->asRenderTarget()->renderTargetPriv().get StencilBuffer() ==
80 smallRT1->asRenderTarget()->getStencilBuffer()); 90 smallRT1->asRenderTarget()->renderTargetPriv().get StencilBuffer());
81 91
82 // An unbudgeted RT with the same desc should also share. 92 // An unbudgeted RT with the same desc should also share.
83 SkAutoTUnref<GrTexture> smallRT2(context->createTexture(smallDesc, false)); 93 SkAutoTUnref<GrTexture> smallRT2(context->createTexture(smallDesc, false));
94 if (smallRT2 && smallRT2->asRenderTarget()) {
95 smallRT2->asRenderTarget()->renderTargetPriv().attachStencilBuffer();
96 }
84 REPORTER_ASSERT(reporter, smallRT0 && smallRT2 && 97 REPORTER_ASSERT(reporter, smallRT0 && smallRT2 &&
85 smallRT0->asRenderTarget() && smallRT2->asRenderTa rget() && 98 smallRT0->asRenderTarget() && smallRT2->asRenderTa rget() &&
86 smallRT0->asRenderTarget()->getStencilBuffer() == 99 smallRT0->asRenderTarget()->renderTargetPriv().get StencilBuffer() ==
87 smallRT2->asRenderTarget()->getStencilBuffer()); 100 smallRT2->asRenderTarget()->renderTargetPriv().get StencilBuffer());
88 101
89 // An RT with a much larger size should not share. 102 // An RT with a much larger size should not share.
90 GrSurfaceDesc bigDesc; 103 GrSurfaceDesc bigDesc;
91 bigDesc.fFlags = kRenderTarget_GrSurfaceFlag; 104 bigDesc.fFlags = kRenderTarget_GrSurfaceFlag;
92 bigDesc.fConfig = kSkia8888_GrPixelConfig; 105 bigDesc.fConfig = kSkia8888_GrPixelConfig;
93 bigDesc.fWidth = 400; 106 bigDesc.fWidth = 400;
94 bigDesc.fHeight = 200; 107 bigDesc.fHeight = 200;
95 bigDesc.fSampleCnt = 0; 108 bigDesc.fSampleCnt = 0;
96 SkAutoTUnref<GrTexture> bigRT(context->createTexture(bigDesc, false)); 109 SkAutoTUnref<GrTexture> bigRT(context->createTexture(bigDesc, false));
110 if (bigRT && bigRT->asRenderTarget()) {
111 bigRT->asRenderTarget()->renderTargetPriv().attachStencilBuffer();
112 }
97 REPORTER_ASSERT(reporter, smallRT0 && bigRT && 113 REPORTER_ASSERT(reporter, smallRT0 && bigRT &&
98 smallRT0->asRenderTarget() && bigRT->asRenderTarge t() && 114 smallRT0->asRenderTarget() && bigRT->asRenderTarge t() &&
99 smallRT0->asRenderTarget()->getStencilBuffer() != 115 smallRT0->asRenderTarget()->renderTargetPriv().get StencilBuffer() !=
100 bigRT->asRenderTarget()->getStencilBuffer()); 116 bigRT->asRenderTarget()->renderTargetPriv().getSte ncilBuffer());
101 117
102 if (context->getMaxSampleCount() >= 4) { 118 if (context->getMaxSampleCount() >= 4) {
103 // An RT with a different sample count should not share. 119 // An RT with a different sample count should not share.
104 GrSurfaceDesc smallMSAADesc = smallDesc; 120 GrSurfaceDesc smallMSAADesc = smallDesc;
105 smallMSAADesc.fSampleCnt = 4; 121 smallMSAADesc.fSampleCnt = 4;
106 SkAutoTUnref<GrTexture> smallMSAART0(context->createTexture(smallMSAADes c, false)); 122 SkAutoTUnref<GrTexture> smallMSAART0(context->createTexture(smallMSAADes c, false));
123 if (smallMSAART0 && smallMSAART0->asRenderTarget()) {
124 smallMSAART0->asRenderTarget()->renderTargetPriv().attachStencilBuff er();
125 }
107 #ifdef SK_BUILD_FOR_ANDROID 126 #ifdef SK_BUILD_FOR_ANDROID
108 if (!smallMSAART0) { 127 if (!smallMSAART0) {
109 // The nexus player seems to fail to create MSAA textures. 128 // The nexus player seems to fail to create MSAA textures.
110 return; 129 return;
111 } 130 }
112 #endif 131 #endif
113 REPORTER_ASSERT(reporter, smallRT0 && smallMSAART0 && 132 REPORTER_ASSERT(reporter,
114 smallRT0->asRenderTarget() && smallMSAART0->as RenderTarget() && 133 smallRT0 && smallMSAART0 &&
115 smallRT0->asRenderTarget()->getStencilBuffer() != 134 smallRT0->asRenderTarget() && smallMSAART0->asRenderTarg et() &&
116 smallMSAART0->asRenderTarget()->getStencilBuff er()); 135 smallRT0->asRenderTarget()->renderTargetPriv().getStenci lBuffer() !=
136 smallMSAART0->asRenderTarget()->renderTargetPriv().getSt encilBuffer());
117 // A second MSAA RT should share with the first MSAA RT. 137 // A second MSAA RT should share with the first MSAA RT.
118 SkAutoTUnref<GrTexture> smallMSAART1(context->createTexture(smallMSAADes c, false)); 138 SkAutoTUnref<GrTexture> smallMSAART1(context->createTexture(smallMSAADes c, false));
119 REPORTER_ASSERT(reporter, smallMSAART0 && smallMSAART1 && 139 if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
120 smallMSAART0->asRenderTarget() && 140 smallMSAART1->asRenderTarget()->renderTargetPriv().attachStencilBuff er();
121 smallMSAART1->asRenderTarget() && 141 }
122 smallMSAART0->asRenderTarget()->getStencilBuff er() == 142 REPORTER_ASSERT(reporter,
123 smallMSAART1->asRenderTarget()->getStencilBuff er()); 143 smallMSAART0 && smallMSAART1 &&
144 smallMSAART0->asRenderTarget() &&
145 smallMSAART1->asRenderTarget() &&
146 smallMSAART0->asRenderTarget()->renderTargetPriv().getSt encilBuffer() ==
147 smallMSAART1->asRenderTarget()->renderTargetPriv().getSt encilBuffer());
124 // But not one with a larger sample count should not. (Also check that t he request for 4 148 // But not one with a larger sample count should not. (Also check that t he request for 4
125 // samples didn't get rounded up to >= 8 or else they could share.). 149 // samples didn't get rounded up to >= 8 or else they could share.).
126 if (context->getMaxSampleCount() >= 8 && smallMSAART0 && smallMSAART0->a sRenderTarget() && 150 if (context->getMaxSampleCount() >= 8 && smallMSAART0 && smallMSAART0->a sRenderTarget() &&
127 smallMSAART0->asRenderTarget()->numSamples() < 8) { 151 smallMSAART0->asRenderTarget()->numSamples() < 8) {
128 smallMSAADesc.fSampleCnt = 8; 152 smallMSAADesc.fSampleCnt = 8;
129 smallMSAART1.reset(context->createTexture(smallMSAADesc, false)); 153 smallMSAART1.reset(context->createTexture(smallMSAADesc, false));
130 REPORTER_ASSERT(reporter, smallMSAART0 && smallMSAART1 && 154 SkAutoTUnref<GrTexture> smallMSAART1(context->createTexture(smallMSA ADesc, false));
131 smallMSAART0->asRenderTarget() && 155 if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
132 smallMSAART1->asRenderTarget() && 156 smallMSAART1->asRenderTarget()->renderTargetPriv().attachStencil Buffer();
133 smallMSAART0->asRenderTarget()->getStencil Buffer() != 157 }
134 smallMSAART1->asRenderTarget()->getStencil Buffer()); 158 REPORTER_ASSERT(reporter,
159 smallMSAART0 && smallMSAART1 &&
160 smallMSAART0->asRenderTarget() &&
161 smallMSAART1->asRenderTarget() &&
162 smallMSAART0->asRenderTarget()->renderTargetPriv().g etStencilBuffer() !=
163 smallMSAART1->asRenderTarget()->renderTargetPriv().g etStencilBuffer());
135 } 164 }
136 } 165 }
137 } 166 }
138 167
139 class TestResource : public GrGpuResource { 168 class TestResource : public GrGpuResource {
140 static const size_t kDefaultSize = 100; 169 static const size_t kDefaultSize = 100;
141 enum ScratchConstructor { kScratchConstructor }; 170 enum ScratchConstructor { kScratchConstructor };
142 public: 171 public:
143 SK_DECLARE_INST_COUNT(TestResource); 172 SK_DECLARE_INST_COUNT(TestResource);
144 /** Property that distinctly categorizes the resource. 173 /** Property that distinctly categorizes the resource.
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 test_remove_scratch_key(reporter); 1115 test_remove_scratch_key(reporter);
1087 test_scratch_key_consistency(reporter); 1116 test_scratch_key_consistency(reporter);
1088 test_purge_invalidated(reporter); 1117 test_purge_invalidated(reporter);
1089 test_cache_chained_purge(reporter); 1118 test_cache_chained_purge(reporter);
1090 test_resource_size_changed(reporter); 1119 test_resource_size_changed(reporter);
1091 test_timestamp_wrap(reporter); 1120 test_timestamp_wrap(reporter);
1092 test_large_resource_count(reporter); 1121 test_large_resource_count(reporter);
1093 } 1122 }
1094 1123
1095 #endif 1124 #endif
OLDNEW
« no previous file with comments | « tests/ReadPixelsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698