blob: ba167f352d730c88a43e854cd2b2098856ad1050 [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
27#include <log/log.h>
28
29namespace android::renderengine::skia {
30
31/**
32 * Abstraction over Ganesh and Graphite's underlying context-like objects.
33 */
34class SkiaGpuContext {
35public:
36 static std::unique_ptr<SkiaGpuContext> MakeGL_Ganesh(
37 sk_sp<const GrGLInterface> glInterface,
38 GrContextOptions::PersistentCache& skSLCacheMonitor);
39
40 // TODO: b/293371537 - Graphite variant.
41 static std::unique_ptr<SkiaGpuContext> MakeVulkan_Ganesh(
42 const GrVkBackendContext& grVkBackendContext,
43 GrContextOptions::PersistentCache& skSLCacheMonitor);
44
45 virtual ~SkiaGpuContext() = default;
46
47 // TODO: b/293371537 - Maybe expose whether this SkiaGpuContext is using Ganesh or Graphite?
48 /**
49 * Only callable on Ganesh-backed instances of SkiaGpuContext, otherwise fatal.
50 */
51 virtual sk_sp<GrDirectContext> grDirectContext() {
52 LOG_ALWAYS_FATAL("grDirectContext() called on a non-Ganesh instance of SkiaGpuContext!");
53 }
54
55 /**
56 * Notes:
57 * - The surface doesn't count against Skia's caching budgets.
58 * - Protected status is set to match the implementation's underlying context.
59 * - The origin of the surface in texture space corresponds to the top-left content pixel.
60 * - AA is always enabled.
61 */
62 virtual sk_sp<SkSurface> createRenderTarget(SkImageInfo imageInfo) = 0;
63
64 virtual bool isAbandoned() = 0;
65 virtual size_t getMaxRenderTargetSize() const = 0;
66 virtual size_t getMaxTextureSize() const = 0;
67 virtual void setResourceCacheLimit(size_t maxResourceBytes) = 0;
68
69 virtual void finishRenderingAndAbandonContext() = 0;
70 virtual void purgeUnlockedScratchResources() = 0;
71 virtual void resetContextIfApplicable() = 0; // No-op outside of GL (&& Ganesh at this point.)
72
73 virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const = 0;
74};
75
76} // namespace android::renderengine::skia