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&, |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 42 | const compositionengine::RenderSurfaceCreationArgs&); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 43 | ~RenderSurface() override; |
| 44 | |
| 45 | bool isValid() const override; |
| 46 | void initialize() override; |
| 47 | const ui::Size& getSize() const override; |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 48 | bool isProtected() const override { return mProtected; } |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 49 | |
| 50 | const sp<Fence>& getClientTargetAcquireFence() const override; |
| 51 | void setBufferDataspace(ui::Dataspace) override; |
Peiyong Lin | dfc3f7c | 2020-05-07 20:15:50 -0700 | [diff] [blame] | 52 | void setBufferPixelFormat(ui::PixelFormat) override; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 53 | void setDisplaySize(const ui::Size&) override; |
| 54 | void setProtected(bool useProtected) override; |
| 55 | status_t beginFrame(bool mustRecompose) override; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 56 | void prepareFrame(bool usesClientComposition, bool usesDeviceComposition) override; |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 57 | sp<GraphicBuffer> dequeueBuffer(base::unique_fd* bufferFence) override; |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 58 | void queueBuffer(base::unique_fd readyFence) override; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 59 | void onPresentDisplayCompleted() override; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 60 | void flip() override; |
| 61 | |
| 62 | // Debugging |
| 63 | void dump(std::string& result) const override; |
| 64 | std::uint32_t getPageFlipCount() const override; |
| 65 | |
| 66 | // Testing |
| 67 | void setPageFlipCountForTest(std::uint32_t); |
| 68 | void setSizeForTest(const ui::Size&); |
| 69 | sp<GraphicBuffer>& mutableGraphicBufferForTest(); |
| 70 | base::unique_fd& mutableBufferReadyForTest(); |
Ramakant Singh | 632e598 | 2020-08-14 15:58:09 +0530 | [diff] [blame] | 71 | void flipClientTarget(bool flip) override; |
| 72 | void setViewportAndProjection() override; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 73 | |
| 74 | private: |
| 75 | const compositionengine::CompositionEngine& mCompositionEngine; |
| 76 | const compositionengine::Display& mDisplay; |
| 77 | |
| 78 | // ANativeWindow being rendered into |
| 79 | const sp<ANativeWindow> mNativeWindow; |
| 80 | // Current buffer being rendered into |
| 81 | sp<GraphicBuffer> mGraphicBuffer; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 82 | const sp<DisplaySurface> mDisplaySurface; |
| 83 | ui::Size mSize; |
Peiyong Lin | 5201031 | 2019-05-02 14:22:16 -0700 | [diff] [blame] | 84 | bool mProtected{false}; |
Ramakant Singh | 632e598 | 2020-08-14 15:58:09 +0530 | [diff] [blame] | 85 | bool mFlipClientTarget{false}; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 86 | std::uint32_t mPageFlipCount{0}; |
| 87 | }; |
| 88 | |
| 89 | std::unique_ptr<compositionengine::RenderSurface> createRenderSurface( |
| 90 | const compositionengine::CompositionEngine&, compositionengine::Display&, |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 91 | const compositionengine::RenderSurfaceCreationArgs&); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 92 | |
| 93 | } // namespace impl |
| 94 | } // namespace compositionengine |
| 95 | } // namespace android |