blob: 3bec3f7e4bbd06001aee70e2c51ed399872fd3a3 [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 "SkiaBackendTexture.h"
20
21#include <include/core/SkColorSpace.h>
22#include <include/core/SkImage.h>
23#include <include/core/SkSurface.h>
24#include <include/gpu/graphite/BackendTexture.h>
25#include <include/gpu/graphite/Recorder.h>
26
27#include <android-base/macros.h>
28#include <ui/GraphicTypes.h>
29
30#include <memory>
31
32namespace android::renderengine::skia {
33
34class GraphiteBackendTexture : public SkiaBackendTexture {
35public:
36 // Creates an internal skgpu::graphite::BackendTexture whose contents come from the provided
37 // buffer.
38 GraphiteBackendTexture(std::shared_ptr<skgpu::graphite::Recorder> recorder,
39 AHardwareBuffer* buffer, bool isOutputBuffer);
40
41 ~GraphiteBackendTexture() override;
42
43 sk_sp<SkImage> makeImage(SkAlphaType alphaType, ui::Dataspace dataspace,
44 TextureReleaseProc releaseImageProc,
45 ReleaseContext releaseContext) override;
46
47 sk_sp<SkSurface> makeSurface(ui::Dataspace dataspace, TextureReleaseProc releaseSurfaceProc,
48 ReleaseContext releaseContext) override;
49
50private:
51 DISALLOW_COPY_AND_ASSIGN(GraphiteBackendTexture);
52
53 void logFatalTexture(const char* msg, ui::Dataspace dataspace, SkColorType colorType);
54
55 const std::shared_ptr<skgpu::graphite::Recorder> mRecorder;
56 skgpu::graphite::BackendTexture mBackendTexture;
57};
58
59} // namespace android::renderengine::skia