Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 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 <memory> |
| 20 | |
| 21 | #include <android-base/unique_fd.h> |
| 22 | #include <compositionengine/RenderSurface.h> |
| 23 | #include <utils/StrongPointer.h> |
| 24 | |
| 25 | struct ANativeWindow; |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | namespace compositionengine { |
| 30 | |
| 31 | class CompositionEngine; |
| 32 | class Display; |
| 33 | class DisplaySurface; |
| 34 | |
| 35 | struct RenderSurfaceCreationArgs; |
| 36 | |
| 37 | namespace impl { |
| 38 | |
| 39 | class RenderSurface : public compositionengine::RenderSurface { |
| 40 | public: |
| 41 | RenderSurface(const CompositionEngine&, compositionengine::Display&, |
| 42 | compositionengine::RenderSurfaceCreationArgs&&); |
| 43 | ~RenderSurface() override; |
| 44 | |
| 45 | bool isValid() const override; |
| 46 | void initialize() override; |
| 47 | const ui::Size& getSize() const override; |
| 48 | |
| 49 | const sp<Fence>& getClientTargetAcquireFence() const override; |
| 50 | void setBufferDataspace(ui::Dataspace) override; |
| 51 | void setDisplaySize(const ui::Size&) override; |
| 52 | void setProtected(bool useProtected) override; |
| 53 | status_t beginFrame(bool mustRecompose) override; |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 54 | status_t prepareFrame() override; |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 55 | sp<GraphicBuffer> dequeueBuffer(base::unique_fd* bufferFence) override; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 56 | void queueBuffer(base::unique_fd&& readyFence) override; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 57 | void onPresentDisplayCompleted() override; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 58 | void setViewportAndProjection() override; |
| 59 | void flip() override; |
| 60 | |
| 61 | // Debugging |
| 62 | void dump(std::string& result) const override; |
| 63 | std::uint32_t getPageFlipCount() const override; |
| 64 | |
| 65 | // Testing |
| 66 | void setPageFlipCountForTest(std::uint32_t); |
| 67 | void setSizeForTest(const ui::Size&); |
| 68 | sp<GraphicBuffer>& mutableGraphicBufferForTest(); |
| 69 | base::unique_fd& mutableBufferReadyForTest(); |
| 70 | |
| 71 | private: |
| 72 | const compositionengine::CompositionEngine& mCompositionEngine; |
| 73 | const compositionengine::Display& mDisplay; |
| 74 | |
| 75 | // ANativeWindow being rendered into |
| 76 | const sp<ANativeWindow> mNativeWindow; |
| 77 | // Current buffer being rendered into |
| 78 | sp<GraphicBuffer> mGraphicBuffer; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 79 | const sp<DisplaySurface> mDisplaySurface; |
| 80 | ui::Size mSize; |
| 81 | std::uint32_t mPageFlipCount{0}; |
| 82 | }; |
| 83 | |
| 84 | std::unique_ptr<compositionengine::RenderSurface> createRenderSurface( |
| 85 | const compositionengine::CompositionEngine&, compositionengine::Display&, |
| 86 | compositionengine::RenderSurfaceCreationArgs&&); |
| 87 | |
| 88 | } // namespace impl |
| 89 | } // namespace compositionengine |
| 90 | } // namespace android |