OLD | NEW |
---|---|
(Empty) | |
1 | |
2 /* | |
3 * Copyright 2015 Google Inc. | |
bsalomon
2016/03/18 15:20:44
2016
jvanverth1
2016/03/18 18:32:53
Done.
| |
4 * | |
5 * Use of this source code is governed by a BSD-style license that can be | |
6 * found in the LICENSE file. | |
7 */ | |
8 | |
9 // This is a GPU-backend specific test. It relies on static intializers to work | |
10 | |
11 #include "SkTypes.h" | |
12 | |
13 #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_VULKAN) | |
14 | |
15 #include "GrContextFactory.h" | |
16 #include "GrTest.h" | |
17 #include "Test.h" | |
18 #include "vk/GrVkCaps.h" | |
19 #include "vk/GrVkGpu.h" | |
20 #include "vk/GrVkMemory.h" | |
21 #include "vk/GrVkTypes.h" | |
22 | |
23 const int kW = 1024; | |
24 const int kH = 1024; | |
25 const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig; | |
26 | |
27 void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { | |
28 | |
29 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); | |
30 | |
31 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k W, kH, kPixelConfig); | |
32 const GrVkTextureInfo* backendTex = reinterpret_cast<const GrVkTextureInfo*> (backendObj); | |
33 | |
34 // check basic borrowed creation | |
35 GrBackendTextureDesc desc; | |
36 desc.fConfig = kPixelConfig; | |
37 desc.fWidth = kW; | |
38 desc.fHeight = kH; | |
39 desc.fTextureHandle = backendObj; | |
40 GrTexture* tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | |
41 REPORTER_ASSERT(reporter, tex); | |
42 tex->unref(); | |
43 | |
44 // image is null | |
45 GrVkTextureInfo backendCopy = *backendTex; | |
46 backendCopy.fImage = VK_NULL_HANDLE; | |
47 desc.fTextureHandle = (GrBackendObject) &backendCopy; | |
48 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | |
49 REPORTER_ASSERT(reporter, !tex); | |
50 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | |
51 REPORTER_ASSERT(reporter, !tex); | |
52 | |
53 // alloc is null | |
54 backendCopy.fImage = backendTex->fImage; | |
55 backendCopy.fAlloc = VK_NULL_HANDLE; | |
56 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | |
57 REPORTER_ASSERT(reporter, !tex); | |
58 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | |
59 REPORTER_ASSERT(reporter, !tex); | |
60 | |
61 // check adopt creation | |
62 backendCopy.fAlloc = backendTex->fAlloc; | |
63 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | |
64 REPORTER_ASSERT(reporter, tex); | |
65 tex->unref(); | |
66 | |
67 gpu->deleteTestingOnlyBackendTexture(backendObj, true); | |
68 } | |
69 | |
70 void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { | |
71 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); | |
72 | |
73 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k W, kH, kPixelConfig); | |
74 const GrVkTextureInfo* backendTex = reinterpret_cast<const GrVkTextureInfo*> (backendObj); | |
75 | |
76 // check basic borrowed creation | |
77 GrBackendRenderTargetDesc desc; | |
78 desc.fWidth = kW; | |
79 desc.fHeight = kH; | |
80 desc.fConfig = kPixelConfig; | |
81 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
82 desc.fSampleCnt = 0; | |
83 desc.fStencilBits = 0; | |
84 desc.fRenderTargetHandle = backendObj; | |
85 GrRenderTarget* rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwners hip); | |
86 REPORTER_ASSERT(reporter, rt); | |
87 rt->unref(); | |
88 | |
89 // image is null | |
90 GrVkTextureInfo backendCopy = *backendTex; | |
91 backendCopy.fImage = VK_NULL_HANDLE; | |
92 desc.fRenderTargetHandle = (GrBackendObject)&backendCopy; | |
93 rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwnership); | |
94 REPORTER_ASSERT(reporter, !rt); | |
95 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); | |
96 REPORTER_ASSERT(reporter, !rt); | |
97 | |
98 // alloc is null | |
99 backendCopy.fImage = backendTex->fImage; | |
100 backendCopy.fAlloc = VK_NULL_HANDLE; | |
101 // can wrap null alloc if borrowing | |
102 rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwnership); | |
103 REPORTER_ASSERT(reporter, rt); | |
104 // but not if adopting | |
105 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); | |
106 REPORTER_ASSERT(reporter, !rt); | |
107 | |
108 // check adopt creation | |
109 backendCopy.fAlloc = backendTex->fAlloc; | |
110 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); | |
111 REPORTER_ASSERT(reporter, rt); | |
112 rt->unref(); | |
113 | |
114 gpu->deleteTestingOnlyBackendTexture(backendObj, true); | |
115 } | |
116 | |
117 void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { | |
118 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); | |
119 | |
120 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k W, kH, kPixelConfig); | |
121 const GrVkTextureInfo* backendTex = reinterpret_cast<const GrVkTextureInfo*> (backendObj); | |
122 | |
123 // check basic borrowed creation | |
124 GrBackendTextureDesc desc; | |
125 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
126 desc.fConfig = kPixelConfig; | |
127 desc.fWidth = kW; | |
128 desc.fHeight = kH; | |
129 desc.fTextureHandle = backendObj; | |
130 GrTexture* tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | |
131 REPORTER_ASSERT(reporter, tex); | |
132 tex->unref(); | |
133 | |
134 // image is null | |
135 GrVkTextureInfo backendCopy = *backendTex; | |
136 backendCopy.fImage = VK_NULL_HANDLE; | |
137 desc.fTextureHandle = (GrBackendObject)&backendCopy; | |
138 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | |
139 REPORTER_ASSERT(reporter, !tex); | |
140 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | |
141 REPORTER_ASSERT(reporter, !tex); | |
142 | |
143 // alloc is null | |
144 backendCopy.fImage = backendTex->fImage; | |
145 backendCopy.fAlloc = VK_NULL_HANDLE; | |
146 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | |
147 REPORTER_ASSERT(reporter, !tex); | |
148 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | |
149 REPORTER_ASSERT(reporter, !tex); | |
150 | |
151 // check adopt creation | |
152 backendCopy.fAlloc = backendTex->fAlloc; | |
153 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | |
154 REPORTER_ASSERT(reporter, tex); | |
155 tex->unref(); | |
156 | |
157 gpu->deleteTestingOnlyBackendTexture(backendObj, true); | |
158 } | |
159 | |
160 DEF_GPUTEST(VkWrapTests, reporter, factory) { | |
161 GrContextOptions opts; | |
162 opts.fSuppressPrints = true; | |
163 GrContextFactory debugFactory(opts); | |
164 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { | |
165 if (static_cast<GrContextFactory::GLContextType>(type) != | |
166 GrContextFactory::kNative_GLContextType) { | |
167 continue; | |
168 } | |
169 GrContext* context = debugFactory.get(static_cast<GrContextFactory::GLCo ntextType>(type)); | |
170 if (context) { | |
171 wrap_tex_test(reporter, context); | |
172 wrap_rt_test(reporter, context); | |
173 } | |
174 | |
175 } | |
176 } | |
177 | |
178 #endif | |
OLD | NEW |