summaryrefslogtreecommitdiff
path: root/libs/renderengine/include/renderengine/ExternalTexture.h
blob: 82e5d83c30fc12a951524d754efee3729960da4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <android-base/macros.h>
#include <ui/GraphicBuffer.h>

namespace android::renderengine {

class RenderEngine;

/**
 * Manages GPU image resources on behalf of clients using RenderEngine.
 *
 * Clients of RenderEngine are required to wrap their GraphicBuffer objects as an ExternalTexture,
 * which is then mapped into GPU resources required by RenderEngine. When a client no longer needs
 * to use the GraphicBuffer as input into RenderEngine::drawLayers, then the client should delete
 * their ExternalTexture so that resources may be freed.
 */
class ExternalTexture {
public:
    ExternalTexture() = default;
    virtual ~ExternalTexture() = default;

    virtual bool hasSameBuffer(const ExternalTexture& other) const = 0;
    virtual uint32_t getWidth() const = 0;
    virtual uint32_t getHeight() const = 0;
    virtual uint64_t getId() const = 0;
    virtual PixelFormat getPixelFormat() const = 0;
    virtual uint64_t getUsage() const = 0;

    // Retrieves the buffer that is bound to this texture.
    virtual const sp<GraphicBuffer>& getBuffer() const = 0;

    virtual void remapBuffer() = 0;

    Rect getBounds() const {
        return {0, 0, static_cast<int32_t>(getWidth()), static_cast<int32_t>(getHeight())};
    }
    DISALLOW_COPY_AND_ASSIGN(ExternalTexture);
};

} // namespace android::renderengine