1 /* 2 * Copyright 2019 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/unique_fd.h> 20 #include <compositionengine/RenderSurface.h> 21 #include <utils/StrongPointer.h> 22 23 #include <memory> 24 #include <vector> 25 26 #include "renderengine/ExternalTexture.h" 27 #include "renderengine/RenderEngine.h" 28 29 struct ANativeWindow; 30 31 namespace android { 32 33 namespace compositionengine { 34 35 class CompositionEngine; 36 class Display; 37 class DisplaySurface; 38 39 struct RenderSurfaceCreationArgs; 40 41 namespace impl { 42 43 class RenderSurface : public compositionengine::RenderSurface { 44 public: 45 RenderSurface(const CompositionEngine&, compositionengine::Display&, 46 const compositionengine::RenderSurfaceCreationArgs&); 47 ~RenderSurface() override; 48 49 bool isValid() const override; 50 void initialize() override; 51 const ui::Size& getSize() const override; isProtected()52 bool isProtected() const override { return mProtected; } 53 54 const sp<Fence>& getClientTargetAcquireFence() const override; 55 void setBufferDataspace(ui::Dataspace) override; 56 void setBufferPixelFormat(ui::PixelFormat) override; 57 void setDisplaySize(const ui::Size&) override; 58 void setProtected(bool useProtected) override; 59 status_t beginFrame(bool mustRecompose) override; 60 void prepareFrame(bool usesClientComposition, bool usesDeviceComposition) override; 61 std::shared_ptr<renderengine::ExternalTexture> dequeueBuffer( 62 base::unique_fd* bufferFence) override; 63 void queueBuffer(base::unique_fd readyFence) override; 64 void onPresentDisplayCompleted() override; 65 void flip() override; 66 67 // Debugging 68 void dump(std::string& result) const override; 69 std::uint32_t getPageFlipCount() const override; 70 71 // Testing 72 void setPageFlipCountForTest(std::uint32_t); 73 void setSizeForTest(const ui::Size&); 74 std::shared_ptr<renderengine::ExternalTexture>& mutableTextureForTest(); 75 base::unique_fd& mutableBufferReadyForTest(); 76 77 private: 78 const compositionengine::CompositionEngine& mCompositionEngine; 79 const compositionengine::Display& mDisplay; 80 81 // ANativeWindow being rendered into 82 const sp<ANativeWindow> mNativeWindow; 83 84 std::vector<std::shared_ptr<renderengine::ExternalTexture>> mTextureCache; 85 // Current texture being rendered into 86 std::shared_ptr<renderengine::ExternalTexture> mTexture; 87 const sp<DisplaySurface> mDisplaySurface; 88 ui::Size mSize; 89 const size_t mMaxTextureCacheSize; 90 bool mProtected{false}; 91 std::uint32_t mPageFlipCount{0}; 92 }; 93 94 std::unique_ptr<compositionengine::RenderSurface> createRenderSurface( 95 const compositionengine::CompositionEngine&, compositionengine::Display&, 96 const compositionengine::RenderSurfaceCreationArgs&); 97 98 } // namespace impl 99 } // namespace compositionengine 100 } // namespace android 101