blob: 685f89931041de4d815c3c144a3d4ebbd41c12df [file] [log] [blame]
Nolan Scobie609e5972024-03-20 14:47:34 -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#include "SkiaGpuContext.h"
20#include "graphite/Recorder.h"
21
22#include <android-base/macros.h>
23
24namespace android::renderengine::skia {
25
26class GraphiteGpuContext : public SkiaGpuContext {
27public:
28 GraphiteGpuContext(std::unique_ptr<skgpu::graphite::Context> context);
29 ~GraphiteGpuContext() override = default;
30
31 std::shared_ptr<skgpu::graphite::Context> graphiteContext() override;
32 std::shared_ptr<skgpu::graphite::Recorder> graphiteRecorder() override;
33
34 std::unique_ptr<SkiaBackendTexture> makeBackendTexture(AHardwareBuffer* buffer,
35 bool isOutputBuffer) override;
36
37 sk_sp<SkSurface> createRenderTarget(SkImageInfo imageInfo) override;
38
39 size_t getMaxRenderTargetSize() const override;
40 size_t getMaxTextureSize() const override;
41 bool isAbandonedOrDeviceLost() override;
42 // No-op (large resources like textures, surfaces, images, etc. created by clients don't count
43 // towards Graphite's internal caching budgets, so adjusting its limits based on display change
44 // events should be unnecessary. Additionally, Graphite doesn't expose many cache tweaking
45 // functions yet, as its design may evolve.)
46 void setResourceCacheLimit(size_t maxResourceBytes) override{};
47
48 void finishRenderingAndAbandonContext() override;
49 // TODO: b/293371537 - Triple-check and validate that no cleanup is necessary when switching
50 // contexts.
51 // No-op (unnecessary during context switch for Graphite's client-budgeted memory model).
52 void purgeUnlockedScratchResources() override{};
53 // No-op (only applicable to GL).
54 void resetContextIfApplicable() override{};
55
56 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
57
58private:
59 DISALLOW_COPY_AND_ASSIGN(GraphiteGpuContext);
60
61 const std::shared_ptr<skgpu::graphite::Context> mContext;
62 std::shared_ptr<skgpu::graphite::Recorder> mRecorder;
63};
64
65} // namespace android::renderengine::skia