Home | History | Annotate | Download | only in impl
      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&,
     42                   compositionengine::RenderSurfaceCreationArgs&&);
     43     ~RenderSurface() override;
     44 
     45     bool isValid() const override;
     46     void initialize() override;
     47     const ui::Size& getSize() const override;
     48     bool isProtected() const override { return mProtected; }
     49 
     50     const sp<Fence>& getClientTargetAcquireFence() const override;
     51     void setBufferDataspace(ui::Dataspace) override;
     52     void setDisplaySize(const ui::Size&) override;
     53     void setProtected(bool useProtected) override;
     54     status_t beginFrame(bool mustRecompose) override;
     55     status_t prepareFrame() override;
     56     sp<GraphicBuffer> dequeueBuffer(base::unique_fd* bufferFence) override;
     57     void queueBuffer(base::unique_fd&& readyFence) override;
     58     void onPresentDisplayCompleted() override;
     59     void setViewportAndProjection() override;
     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();
     71 
     72 private:
     73     const compositionengine::CompositionEngine& mCompositionEngine;
     74     const compositionengine::Display& mDisplay;
     75 
     76     // ANativeWindow being rendered into
     77     const sp<ANativeWindow> mNativeWindow;
     78     // Current buffer being rendered into
     79     sp<GraphicBuffer> mGraphicBuffer;
     80     const sp<DisplaySurface> mDisplaySurface;
     81     ui::Size mSize;
     82     bool mProtected{false};
     83     std::uint32_t mPageFlipCount{0};
     84 };
     85 
     86 std::unique_ptr<compositionengine::RenderSurface> createRenderSurface(
     87         const compositionengine::CompositionEngine&, compositionengine::Display&,
     88         compositionengine::RenderSurfaceCreationArgs&&);
     89 
     90 } // namespace impl
     91 } // namespace compositionengine
     92 } // namespace android
     93