blob: e23442d429333021222f58692f243ffd17fc764a [file] [log] [blame]
Lloyd Pique31cb2942018-10-19 17:23:03 -07001/*
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
25struct ANativeWindow;
26
27namespace android {
28
29namespace compositionengine {
30
31class CompositionEngine;
32class Display;
33class DisplaySurface;
34
35struct RenderSurfaceCreationArgs;
36
37namespace impl {
38
39class RenderSurface : public compositionengine::RenderSurface {
40public:
41 RenderSurface(const CompositionEngine&, compositionengine::Display&,
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070042 const compositionengine::RenderSurfaceCreationArgs&);
Lloyd Pique31cb2942018-10-19 17:23:03 -070043 ~RenderSurface() override;
44
45 bool isValid() const override;
46 void initialize() override;
47 const ui::Size& getSize() const override;
Peiyong Lin52010312019-05-02 14:22:16 -070048 bool isProtected() const override { return mProtected; }
Lloyd Pique31cb2942018-10-19 17:23:03 -070049
50 const sp<Fence>& getClientTargetAcquireFence() const override;
51 void setBufferDataspace(ui::Dataspace) override;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070052 void setBufferPixelFormat(ui::PixelFormat) override;
Lloyd Pique31cb2942018-10-19 17:23:03 -070053 void setDisplaySize(const ui::Size&) override;
54 void setProtected(bool useProtected) override;
55 status_t beginFrame(bool mustRecompose) override;
Lloyd Pique66d68602019-02-13 14:23:31 -080056 void prepareFrame(bool usesClientComposition, bool usesDeviceComposition) override;
Alec Mouri6338c9d2019-02-07 16:57:51 -080057 sp<GraphicBuffer> dequeueBuffer(base::unique_fd* bufferFence) override;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070058 void queueBuffer(base::unique_fd readyFence) override;
Lloyd Pique31cb2942018-10-19 17:23:03 -070059 void onPresentDisplayCompleted() override;
Lloyd Pique31cb2942018-10-19 17:23:03 -070060 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 Singh632e5982020-08-14 15:58:09 +053071 void flipClientTarget(bool flip) override;
72 void setViewportAndProjection() override;
Lloyd Pique31cb2942018-10-19 17:23:03 -070073
74private:
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 Pique31cb2942018-10-19 17:23:03 -070082 const sp<DisplaySurface> mDisplaySurface;
83 ui::Size mSize;
Peiyong Lin52010312019-05-02 14:22:16 -070084 bool mProtected{false};
Ramakant Singh632e5982020-08-14 15:58:09 +053085 bool mFlipClientTarget{false};
Lloyd Pique31cb2942018-10-19 17:23:03 -070086 std::uint32_t mPageFlipCount{0};
87};
88
89std::unique_ptr<compositionengine::RenderSurface> createRenderSurface(
90 const compositionengine::CompositionEngine&, compositionengine::Display&,
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070091 const compositionengine::RenderSurfaceCreationArgs&);
Lloyd Pique31cb2942018-10-19 17:23:03 -070092
93} // namespace impl
94} // namespace compositionengine
95} // namespace android