1 /* 2 * Copyright 2022 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 <android-base/macros.h> 20 #include <renderengine/ExternalTexture.h> 21 #include <ui/GraphicBuffer.h> 22 23 namespace android::renderengine::impl { 24 25 class RenderEngine; 26 27 class ExternalTexture : public android::renderengine::ExternalTexture { 28 public: 29 // Usage specifies the rendering intent for the buffer. 30 enum Usage : uint32_t { 31 // When a buffer is not READABLE but is WRITEABLE, then GLESRenderEngine will use that as a 32 // hint to load the buffer into a separate cache 33 READABLE = 1 << 0, 34 35 // The buffer needs to be mapped as a 2D texture if set, otherwise must be mapped as an 36 // external texture 37 WRITEABLE = 1 << 1, 38 }; 39 40 // Creates an ExternalTexture for the provided buffer and RenderEngine instance, with the given 41 // usage hint of type Usage. 42 ExternalTexture(const sp<GraphicBuffer>& buffer, 43 android::renderengine::RenderEngine& renderEngine, uint32_t usage); 44 ~ExternalTexture(); getBuffer()45 const sp<GraphicBuffer>& getBuffer() const override { return mBuffer; }; getWidth()46 uint32_t getWidth() const override { return getBuffer()->getWidth(); } getHeight()47 uint32_t getHeight() const override { return getBuffer()->getHeight(); } getId()48 uint64_t getId() const override { return getBuffer()->getId(); } getPixelFormat()49 PixelFormat getPixelFormat() const override { return getBuffer()->getPixelFormat(); } getUsage()50 uint64_t getUsage() const override { return getBuffer()->getUsage(); } hasSameBuffer(const renderengine::ExternalTexture & other)51 bool hasSameBuffer(const renderengine::ExternalTexture& other) const override { 52 return getBuffer() == other.getBuffer(); 53 } 54 void remapBuffer() override; 55 56 private: 57 sp<GraphicBuffer> mBuffer; 58 android::renderengine::RenderEngine& mRenderEngine; 59 const bool mWritable; 60 }; 61 62 } // namespace android::renderengine::impl 63