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, float hdrSdrRatio) override; 64 void onPresentDisplayCompleted() override; 65 bool supportsCompositionStrategyPrediction() const override; 66 67 // Debugging 68 void dump(std::string& result) const override; 69 70 // Testing 71 void setSizeForTest(const ui::Size&); 72 std::shared_ptr<renderengine::ExternalTexture>& mutableTextureForTest(); 73 base::unique_fd& mutableBufferReadyForTest(); 74 75 private: 76 const compositionengine::CompositionEngine& mCompositionEngine; 77 const compositionengine::Display& mDisplay; 78 79 // ANativeWindow being rendered into 80 const sp<ANativeWindow> mNativeWindow; 81 82 std::vector<std::shared_ptr<renderengine::ExternalTexture>> mTextureCache; 83 // Current texture being rendered into 84 std::shared_ptr<renderengine::ExternalTexture> mTexture; 85 const sp<DisplaySurface> mDisplaySurface; 86 ui::Size mSize; 87 const size_t mMaxTextureCacheSize; 88 bool mProtected{false}; 89 }; 90 91 std::unique_ptr<compositionengine::RenderSurface> createRenderSurface( 92 const compositionengine::CompositionEngine&, compositionengine::Display&, 93 const compositionengine::RenderSurfaceCreationArgs&); 94 95 } // namespace impl 96 } // namespace compositionengine 97 } // namespace android 98