1 /* 2 * Copyright 2021 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 <ui/GraphicBuffer.h> 21 22 namespace android::renderengine { 23 24 class RenderEngine; 25 26 /** 27 * Manages GPU image resources on behalf of clients using RenderEngine. 28 * 29 * Clients of RenderEngine are required to wrap their GraphicBuffer objects as an ExternalTexture, 30 * which is then mapped into GPU resources required by RenderEngine. When a client no longer needs 31 * to use the GraphicBuffer as input into RenderEngine::drawLayers, then the client should delete 32 * their ExternalTexture so that resources may be freed. 33 */ 34 class ExternalTexture { 35 public: 36 // Usage specifies the rendering intent for the buffer. 37 enum Usage : uint32_t { 38 // When a buffer is not READABLE but is WRITEABLE, then GLESRenderEngine will use that as a 39 // hint to load the buffer into a separate cache 40 READABLE = 1 << 0, 41 42 // The buffer needs to be mapped as a 2D texture if set, otherwise must be mapped as an 43 // external texture 44 WRITEABLE = 1 << 1, 45 }; 46 // Creates an ExternalTexture for the provided buffer and RenderEngine instance, with the given 47 // usage hint of type Usage. 48 ExternalTexture(const sp<GraphicBuffer>& buffer, RenderEngine& renderEngine, uint32_t usage); 49 50 ~ExternalTexture(); 51 52 // Retrieves the buffer that is bound to this texture. getBuffer()53 const sp<GraphicBuffer>& getBuffer() const { return mBuffer; } 54 55 private: 56 sp<GraphicBuffer> mBuffer; 57 RenderEngine& mRenderEngine; 58 DISALLOW_COPY_AND_ASSIGN(ExternalTexture); 59 }; 60 61 } // namespace android::renderengine 62