OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 // This is a GPU-backend specific test. It relies on static intializers to work | 8 // This is a GPU-backend specific test. It relies on static intializers to work |
9 | 9 |
10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k
W, kH, kPixelConfig, | 32 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k
W, kH, kPixelConfig, |
33 false); | 33 false); |
34 const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(bac
kendObj); | 34 const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(bac
kendObj); |
35 | 35 |
36 // check basic borrowed creation | 36 // check basic borrowed creation |
37 GrBackendTextureDesc desc; | 37 GrBackendTextureDesc desc; |
38 desc.fConfig = kPixelConfig; | 38 desc.fConfig = kPixelConfig; |
39 desc.fWidth = kW; | 39 desc.fWidth = kW; |
40 desc.fHeight = kH; | 40 desc.fHeight = kH; |
41 desc.fTextureHandle = backendObj; | 41 desc.fTextureHandle = backendObj; |
42 GrTexture* tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | 42 sk_sp<GrTexture> tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership
); |
43 REPORTER_ASSERT(reporter, tex); | 43 REPORTER_ASSERT(reporter, tex); |
44 tex->unref(); | |
45 | 44 |
46 // image is null | 45 // image is null |
47 GrVkImageInfo backendCopy = *backendTex; | 46 GrVkImageInfo backendCopy = *backendTex; |
48 backendCopy.fImage = VK_NULL_HANDLE; | 47 backendCopy.fImage = VK_NULL_HANDLE; |
49 desc.fTextureHandle = (GrBackendObject) &backendCopy; | 48 desc.fTextureHandle = (GrBackendObject) &backendCopy; |
50 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | 49 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
51 REPORTER_ASSERT(reporter, !tex); | 50 REPORTER_ASSERT(reporter, !tex); |
52 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | 51 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
53 REPORTER_ASSERT(reporter, !tex); | 52 REPORTER_ASSERT(reporter, !tex); |
54 | 53 |
55 // alloc is null | 54 // alloc is null |
56 backendCopy.fImage = backendTex->fImage; | 55 backendCopy.fImage = backendTex->fImage; |
57 backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; | 56 backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
58 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | 57 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
59 REPORTER_ASSERT(reporter, !tex); | 58 REPORTER_ASSERT(reporter, !tex); |
60 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | 59 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
61 REPORTER_ASSERT(reporter, !tex); | 60 REPORTER_ASSERT(reporter, !tex); |
62 | 61 |
63 // check adopt creation | 62 // check adopt creation |
64 backendCopy.fAlloc = backendTex->fAlloc; | 63 backendCopy.fAlloc = backendTex->fAlloc; |
65 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | 64 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
66 REPORTER_ASSERT(reporter, tex); | 65 REPORTER_ASSERT(reporter, tex); |
67 tex->unref(); | |
68 | 66 |
69 gpu->deleteTestingOnlyBackendTexture(backendObj, true); | 67 gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
70 } | 68 } |
71 | 69 |
72 void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { | 70 void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { |
73 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); | 71 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
74 | 72 |
75 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k
W, kH, kPixelConfig, | 73 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k
W, kH, kPixelConfig, |
76 true); | 74 true); |
77 const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(bac
kendObj); | 75 const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(bac
kendObj); |
78 | 76 |
79 // check basic borrowed creation | 77 // check basic borrowed creation |
80 GrBackendRenderTargetDesc desc; | 78 GrBackendRenderTargetDesc desc; |
81 desc.fWidth = kW; | 79 desc.fWidth = kW; |
82 desc.fHeight = kH; | 80 desc.fHeight = kH; |
83 desc.fConfig = kPixelConfig; | 81 desc.fConfig = kPixelConfig; |
84 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 82 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
85 desc.fSampleCnt = 0; | 83 desc.fSampleCnt = 0; |
86 desc.fStencilBits = 0; | 84 desc.fStencilBits = 0; |
87 desc.fRenderTargetHandle = backendObj; | 85 desc.fRenderTargetHandle = backendObj; |
88 GrRenderTarget* rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwners
hip); | 86 sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrap
Ownership); |
89 REPORTER_ASSERT(reporter, rt); | 87 REPORTER_ASSERT(reporter, rt); |
90 rt->unref(); | |
91 | 88 |
92 // image is null | 89 // image is null |
93 GrVkImageInfo backendCopy = *backendTex; | 90 GrVkImageInfo backendCopy = *backendTex; |
94 backendCopy.fImage = VK_NULL_HANDLE; | 91 backendCopy.fImage = VK_NULL_HANDLE; |
95 desc.fRenderTargetHandle = (GrBackendObject)&backendCopy; | 92 desc.fRenderTargetHandle = (GrBackendObject)&backendCopy; |
96 rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwnership); | 93 rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwnership); |
97 REPORTER_ASSERT(reporter, !rt); | 94 REPORTER_ASSERT(reporter, !rt); |
98 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); | 95 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); |
99 REPORTER_ASSERT(reporter, !rt); | 96 REPORTER_ASSERT(reporter, !rt); |
100 | 97 |
101 // alloc is null | 98 // alloc is null |
102 backendCopy.fImage = backendTex->fImage; | 99 backendCopy.fImage = backendTex->fImage; |
103 backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; | 100 backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
104 // can wrap null alloc if borrowing | 101 // can wrap null alloc if borrowing |
105 rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwnership); | 102 rt = gpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwnership); |
106 REPORTER_ASSERT(reporter, rt); | 103 REPORTER_ASSERT(reporter, rt); |
107 // but not if adopting | 104 // but not if adopting |
108 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); | 105 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); |
109 REPORTER_ASSERT(reporter, !rt); | 106 REPORTER_ASSERT(reporter, !rt); |
110 | 107 |
111 // check adopt creation | 108 // check adopt creation |
112 backendCopy.fAlloc = backendTex->fAlloc; | 109 backendCopy.fAlloc = backendTex->fAlloc; |
113 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); | 110 rt = gpu->wrapBackendRenderTarget(desc, kAdopt_GrWrapOwnership); |
114 REPORTER_ASSERT(reporter, rt); | 111 REPORTER_ASSERT(reporter, rt); |
115 rt->unref(); | |
116 | 112 |
117 gpu->deleteTestingOnlyBackendTexture(backendObj, true); | 113 gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
118 } | 114 } |
119 | 115 |
120 void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { | 116 void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { |
121 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); | 117 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
122 | 118 |
123 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k
W, kH, kPixelConfig, | 119 GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, k
W, kH, kPixelConfig, |
124 true); | 120 true); |
125 const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(bac
kendObj); | 121 const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(bac
kendObj); |
126 | 122 |
127 // check basic borrowed creation | 123 // check basic borrowed creation |
128 GrBackendTextureDesc desc; | 124 GrBackendTextureDesc desc; |
129 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 125 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
130 desc.fConfig = kPixelConfig; | 126 desc.fConfig = kPixelConfig; |
131 desc.fWidth = kW; | 127 desc.fWidth = kW; |
132 desc.fHeight = kH; | 128 desc.fHeight = kH; |
133 desc.fTextureHandle = backendObj; | 129 desc.fTextureHandle = backendObj; |
134 GrTexture* tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | 130 sk_sp<GrTexture> tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership
); |
135 REPORTER_ASSERT(reporter, tex); | 131 REPORTER_ASSERT(reporter, tex); |
136 tex->unref(); | |
137 | 132 |
138 // image is null | 133 // image is null |
139 GrVkImageInfo backendCopy = *backendTex; | 134 GrVkImageInfo backendCopy = *backendTex; |
140 backendCopy.fImage = VK_NULL_HANDLE; | 135 backendCopy.fImage = VK_NULL_HANDLE; |
141 desc.fTextureHandle = (GrBackendObject)&backendCopy; | 136 desc.fTextureHandle = (GrBackendObject)&backendCopy; |
142 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | 137 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
143 REPORTER_ASSERT(reporter, !tex); | 138 REPORTER_ASSERT(reporter, !tex); |
144 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | 139 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
145 REPORTER_ASSERT(reporter, !tex); | 140 REPORTER_ASSERT(reporter, !tex); |
146 | 141 |
147 // alloc is null | 142 // alloc is null |
148 backendCopy.fImage = backendTex->fImage; | 143 backendCopy.fImage = backendTex->fImage; |
149 backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; | 144 backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
150 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); | 145 tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
151 REPORTER_ASSERT(reporter, !tex); | 146 REPORTER_ASSERT(reporter, !tex); |
152 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | 147 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
153 REPORTER_ASSERT(reporter, !tex); | 148 REPORTER_ASSERT(reporter, !tex); |
154 | 149 |
155 // check adopt creation | 150 // check adopt creation |
156 backendCopy.fAlloc = backendTex->fAlloc; | 151 backendCopy.fAlloc = backendTex->fAlloc; |
157 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); | 152 tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
158 REPORTER_ASSERT(reporter, tex); | 153 REPORTER_ASSERT(reporter, tex); |
159 tex->unref(); | |
160 | 154 |
161 gpu->deleteTestingOnlyBackendTexture(backendObj, true); | 155 gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
162 } | 156 } |
163 | 157 |
164 DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) { | 158 DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) { |
165 wrap_tex_test(reporter, ctxInfo.grContext()); | 159 wrap_tex_test(reporter, ctxInfo.grContext()); |
166 wrap_rt_test(reporter, ctxInfo.grContext()); | 160 wrap_rt_test(reporter, ctxInfo.grContext()); |
167 wrap_trt_test(reporter, ctxInfo.grContext()); | 161 wrap_trt_test(reporter, ctxInfo.grContext()); |
168 } | 162 } |
169 | 163 |
170 #endif | 164 #endif |
OLD | NEW |