blob: 8222e6281d7eda2fe024c3785c60c1b5bba57922 [file] [log] [blame]
Nolan Scobiefc125ec2024-03-11 20:08:27 -04001/*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#undef LOG_TAG
20#define LOG_TAG "RenderEngine"
21
22#include <include/core/SkSurface.h>
23#include <include/gpu/GrDirectContext.h>
24#include <include/gpu/gl/GrGLInterface.h>
25#include <include/gpu/vk/GrVkBackendContext.h>
26
Nolan Scobieca050282024-03-15 13:27:06 -040027#include "SkiaBackendTexture.h"
28
Nolan Scobiefc125ec2024-03-11 20:08:27 -040029#include <log/log.h>
30
Nolan Scobieca050282024-03-15 13:27:06 -040031#include <memory>
32
Nolan Scobiefc125ec2024-03-11 20:08:27 -040033namespace android::renderengine::skia {
34
35/**
36 * Abstraction over Ganesh and Graphite's underlying context-like objects.
37 */
38class SkiaGpuContext {
39public:
40 static std::unique_ptr<SkiaGpuContext> MakeGL_Ganesh(
41 sk_sp<const GrGLInterface> glInterface,
42 GrContextOptions::PersistentCache& skSLCacheMonitor);
43
44 // TODO: b/293371537 - Graphite variant.
45 static std::unique_ptr<SkiaGpuContext> MakeVulkan_Ganesh(
46 const GrVkBackendContext& grVkBackendContext,
47 GrContextOptions::PersistentCache& skSLCacheMonitor);
48
49 virtual ~SkiaGpuContext() = default;
50
51 // TODO: b/293371537 - Maybe expose whether this SkiaGpuContext is using Ganesh or Graphite?
52 /**
53 * Only callable on Ganesh-backed instances of SkiaGpuContext, otherwise fatal.
54 */
55 virtual sk_sp<GrDirectContext> grDirectContext() {
56 LOG_ALWAYS_FATAL("grDirectContext() called on a non-Ganesh instance of SkiaGpuContext!");
57 }
58
Nolan Scobieca050282024-03-15 13:27:06 -040059 virtual std::unique_ptr<SkiaBackendTexture> makeBackendTexture(AHardwareBuffer* buffer,
60 bool isOutputBuffer) = 0;
61
Nolan Scobiefc125ec2024-03-11 20:08:27 -040062 /**
63 * Notes:
64 * - The surface doesn't count against Skia's caching budgets.
65 * - Protected status is set to match the implementation's underlying context.
66 * - The origin of the surface in texture space corresponds to the top-left content pixel.
67 * - AA is always enabled.
68 */
69 virtual sk_sp<SkSurface> createRenderTarget(SkImageInfo imageInfo) = 0;
70
Nolan Scobie17ffe902024-03-25 11:07:30 -040071 virtual bool isAbandonedOrDeviceLost() = 0;
Nolan Scobiefc125ec2024-03-11 20:08:27 -040072 virtual size_t getMaxRenderTargetSize() const = 0;
73 virtual size_t getMaxTextureSize() const = 0;
74 virtual void setResourceCacheLimit(size_t maxResourceBytes) = 0;
75
76 virtual void finishRenderingAndAbandonContext() = 0;
77 virtual void purgeUnlockedScratchResources() = 0;
78 virtual void resetContextIfApplicable() = 0; // No-op outside of GL (&& Ganesh at this point.)
79
80 virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const = 0;
81};
82
83} // namespace android::renderengine::skia