blob: 413817ffff37855bb6da54c45bec6262e384dc34 [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);
Nolan Scobie2526b2f2024-04-16 15:12:22 -040029 ~GraphiteGpuContext() override;
Nolan Scobie609e5972024-03-20 14:47:34 -040030
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
Nolan Scobie609e5972024-03-20 14:47:34 -040048 // TODO: b/293371537 - Triple-check and validate that no cleanup is necessary when switching
49 // contexts.
50 // No-op (unnecessary during context switch for Graphite's client-budgeted memory model).
51 void purgeUnlockedScratchResources() override{};
52 // No-op (only applicable to GL).
53 void resetContextIfApplicable() override{};
54
55 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
56
57private:
58 DISALLOW_COPY_AND_ASSIGN(GraphiteGpuContext);
59
Nolan Scobie2526b2f2024-04-16 15:12:22 -040060 std::shared_ptr<skgpu::graphite::Context> mContext;
Nolan Scobie609e5972024-03-20 14:47:34 -040061 std::shared_ptr<skgpu::graphite::Recorder> mRecorder;
62};
63
64} // namespace android::renderengine::skia