1 /*
2 * Copyright 2024 Google LLC
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 #include "include/core/SkAlphaType.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkColorType.h"
12 #include "include/core/SkImageInfo.h"
13 #include "include/core/SkRRect.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkSurface.h"
16 #include "include/gpu/ganesh/GrDirectContext.h"
17 #include "include/gpu/ganesh/SkSurfaceGanesh.h"
18 #include "include/gpu/ganesh/vk/GrVkDirectContext.h"
19 #include "include/gpu/vk/VulkanBackendContext.h"
20 #include "include/gpu/vk/VulkanExtensions.h"
21
main(int argc,char ** argv)22 int main(int argc, char** argv) {
23 // This will not run (since it's missing all the Vulkan setup code),
24 // but it should compile and link to test the build system.
25 skgpu::VulkanBackendContext backendContext;
26
27 std::unique_ptr<skgpu::VulkanExtensions> extensions(new skgpu::VulkanExtensions());
28 backendContext.fInstance = VK_NULL_HANDLE;
29 backendContext.fDevice = VK_NULL_HANDLE;
30
31 // This call will fail if run, due to the context not being set up.
32 sk_sp<GrDirectContext> ctx = GrDirectContexts::MakeVulkan(backendContext);
33 if (!ctx) {
34 // There would need to be vulkan cleanup here.
35 return 1;
36 }
37
38 SkImageInfo imageInfo =
39 SkImageInfo::Make(200, 400, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
40
41 sk_sp<SkSurface> surface =
42 SkSurfaces::RenderTarget(ctx.get(), skgpu::Budgeted::kYes, imageInfo);
43 if (!surface) {
44 printf("Could not make surface from Vulkan DirectContext\n");
45 return 1;
46 }
47
48 SkCanvas* canvas = surface->getCanvas();
49 canvas->clear(SK_ColorYELLOW);
50 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeLTRB(10, 20, 50, 70), 10, 10);
51
52 SkPaint paint;
53 paint.setColor(SK_ColorMAGENTA);
54 paint.setAntiAlias(true);
55
56 canvas->drawRRect(rrect, paint);
57
58 ctx->flush();
59
60 // There would need to be vulkan cleanup here.
61 return 0;
62 }
63