• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <renderengine/ExternalTexture.h>
20 #include <ui/Fence.h>
21 #include <ui/GraphicTypes.h>
22 #include <ui/Size.h>
23 #include <utils/Errors.h>
24 #include <utils/StrongPointer.h>
25 
26 #include <cstdint>
27 #include <vector>
28 
29 namespace android {
30 
31 class GraphicBuffer;
32 
33 namespace compositionengine {
34 
35 /**
36  * Encapsulates everything for composing to a render surface with RenderEngine
37  */
38 class RenderSurface {
39 public:
40     virtual ~RenderSurface();
41 
42     // Returns true if the render surface is valid. This is meant to be checked
43     // post-construction and prior to use, as not everything is set up by the
44     // constructor.
45     virtual bool isValid() const = 0;
46 
47     // Performs one-time initialization of the render surface. This is meant
48     // to be called after the validation check.
49     virtual void initialize() = 0;
50 
51     // Returns the bounds of the surface
52     virtual const ui::Size& getSize() const = 0;
53 
54     // Returns whether the surface is protected.
55     virtual bool isProtected() const = 0;
56 
57     // Gets the latest fence to pass to the HWC to signal that the surface
58     // buffer is done rendering
59     virtual const sp<Fence>& getClientTargetAcquireFence() const = 0;
60 
61     // Sets the size of the surface
62     virtual void setDisplaySize(const ui::Size&) = 0;
63 
64     // Sets the dataspace used for rendering the surface
65     virtual void setBufferDataspace(ui::Dataspace) = 0;
66 
67     // Sets the pixel format used for rendering the surface.
68     // Changing the pixel format of the buffer will result in buffer
69     // reallocation as well as some reconfiguration of the graphics context,
70     // which are both expensive operations.
71     virtual void setBufferPixelFormat(ui::PixelFormat) = 0;
72 
73     // Configures the protected rendering on the surface
74     virtual void setProtected(bool useProtected) = 0;
75 
76     // Called to signal that rendering has started. 'mustRecompose' should be
77     // true if the entire frame must be recomposed.
78     virtual status_t beginFrame(bool mustRecompose) = 0;
79 
80     // Prepares the frame for rendering
81     virtual void prepareFrame(bool usesClientComposition, bool usesDeviceComposition) = 0;
82 
83     // Allocates a buffer as scratch space for GPU composition
84     virtual std::shared_ptr<renderengine::ExternalTexture> dequeueBuffer(
85             base::unique_fd* bufferFence) = 0;
86 
87     // Queues the drawn buffer for consumption by HWC. readyFence is the fence
88     // which will fire when the buffer is ready for consumption.
89     virtual void queueBuffer(base::unique_fd readyFence) = 0;
90 
91     // Called after the HWC calls are made to present the display
92     virtual void onPresentDisplayCompleted() = 0;
93 
94     // Called after the surface has been rendering to signal the surface should
95     // be made ready for displaying
96     virtual void flip() = 0;
97 
98     // Debugging - Dumps the state of the RenderSurface to a string
99     virtual void dump(std::string& result) const = 0;
100 
101     // Debugging - gets the page flip count for the RenderSurface
102     virtual std::uint32_t getPageFlipCount() const = 0;
103 
104     // Returns true if the render surface supports client composition prediction.
105     virtual bool supportsCompositionStrategyPrediction() const = 0;
106 };
107 
108 } // namespace compositionengine
109 } // namespace android
110