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