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