blob: 3c79084073854bdfdb4951641414ee6eb1b1247c [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&,
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 Pique37c2c9b2018-12-04 17:25:10 -080054 status_t prepareFrame() override;
Alec Mouri6338c9d2019-02-07 16:57:51 -080055 sp<GraphicBuffer> dequeueBuffer(base::unique_fd* bufferFence) override;
Alec Mourie7d1d4a2019-02-05 01:13:46 +000056 void queueBuffer(base::unique_fd&& readyFence) override;
Lloyd Pique31cb2942018-10-19 17:23:03 -070057 void onPresentDisplayCompleted() override;
Lloyd Pique31cb2942018-10-19 17:23:03 -070058 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
71private:
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 Pique31cb2942018-10-19 17:23:03 -070079 const sp<DisplaySurface> mDisplaySurface;
80 ui::Size mSize;
81 std::uint32_t mPageFlipCount{0};
82};
83
84std::unique_ptr<compositionengine::RenderSurface> createRenderSurface(
85 const compositionengine::CompositionEngine&, compositionengine::Display&,
86 compositionengine::RenderSurfaceCreationArgs&&);
87
88} // namespace impl
89} // namespace compositionengine
90} // namespace android