Debian Codegraph @

example/external_client/src/ganesh_vulkan.cpp

raw
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
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 backendContext.fMemoryAllocator = nullptr;
31
32 // This call will fail if run, due to the context not being set up.
33 sk_sp<GrDirectContext> ctx = GrDirectContexts::MakeVulkan(backendContext);
34 if (!ctx) {
35 // There would need to be vulkan cleanup here.
36 return 1;
37 }
38
39 SkImageInfo imageInfo =
40 SkImageInfo::Make(200, 400, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
41
42 sk_sp<SkSurface> surface =
43 SkSurfaces::RenderTarget(ctx.get(), skgpu::Budgeted::kYes, imageInfo);
44 if (!surface) {
45 printf("Could not make surface from Vulkan DirectContext\n");
46 return 1;
47 }
48
49 SkCanvas* canvas = surface->getCanvas();
50 canvas->clear(SK_ColorYELLOW);
51 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeLTRB(10, 20, 50, 70), 10, 10);
52
53 SkPaint paint;
54 paint.setColor(SK_ColorMAGENTA);
55 paint.setAntiAlias(true);
56
57 canvas->drawRRect(rrect, paint);
58
59 ctx->flush();
60
61 // There would need to be vulkan cleanup here.
62 return 0;
63 }