1 /*
2  * Copyright (C) 2016 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 <SkColorSpace.h>
20 #include <SkRect.h>
21 #include <android-base/unique_fd.h>
22 #include <utils/RefBase.h>
23 
24 #include "ColorMode.h"
25 #include "DamageAccumulator.h"
26 #include "FrameInfoVisualizer.h"
27 #include "HardwareBufferRenderParams.h"
28 #include "LayerUpdateQueue.h"
29 #include "Lighting.h"
30 #include "SwapBehavior.h"
31 #include "hwui/Bitmap.h"
32 
33 struct ANativeWindow;
34 
35 namespace android {
36 
37 namespace uirenderer {
38 
39 class DeferredLayerUpdater;
40 class ErrorHandler;
41 class TaskManager;
42 
43 namespace renderthread {
44 
45 enum class MakeCurrentResult { AlreadyCurrent, Failed, Succeeded };
46 
47 class Frame;
48 
49 class IRenderPipeline {
50 public:
51     virtual MakeCurrentResult makeCurrent() = 0;
52     virtual Frame getFrame() = 0;
53 
54     // Result of IRenderPipeline::draw
55     struct DrawResult {
56         // True if draw() succeeded, false otherwise
57         bool success = false;
58         // If drawing was successful, reports the time at which command
59         // submission occurred. -1 if this time is unknown.
60         static constexpr nsecs_t kUnknownTime = -1;
61         nsecs_t commandSubmissionTime = kUnknownTime;
62         android::base::unique_fd presentFence;
63     };
64     virtual DrawResult draw(const Frame& frame, const SkRect& screenDirty, const SkRect& dirty,
65                             const LightGeometry& lightGeometry, LayerUpdateQueue* layerUpdateQueue,
66                             const Rect& contentDrawBounds, bool opaque, const LightInfo& lightInfo,
67                             const std::vector<sp<RenderNode>>& renderNodes,
68                             FrameInfoVisualizer* profiler,
69                             const HardwareBufferRenderParams& bufferParams,
70                             std::mutex& profilerLock) = 0;
71     virtual bool swapBuffers(const Frame& frame, IRenderPipeline::DrawResult&,
72                              const SkRect& screenDirty, FrameInfo* currentFrameInfo,
73                              bool* requireSwap) = 0;
74     virtual DeferredLayerUpdater* createTextureLayer() = 0;
75     [[nodiscard]] virtual android::base::unique_fd flush() = 0;
76     virtual void setHardwareBuffer(AHardwareBuffer* hardwareBuffer) = 0;
77     virtual bool hasHardwareBuffer() = 0;
78     virtual bool setSurface(ANativeWindow* window, SwapBehavior swapBehavior) = 0;
79     virtual void onStop() = 0;
80     virtual bool isSurfaceReady() = 0;
81     virtual bool isContextReady() = 0;
82     virtual void onDestroyHardwareResources() = 0;
83     virtual void renderLayers(const LightGeometry& lightGeometry,
84                               LayerUpdateQueue* layerUpdateQueue, bool opaque,
85                               const LightInfo& lightInfo) = 0;
86     virtual bool createOrUpdateLayer(RenderNode* node, const DamageAccumulator& damageAccumulator,
87                                      ErrorHandler* errorHandler) = 0;
88     virtual bool pinImages(std::vector<SkImage*>& mutableImages) = 0;
89     virtual bool pinImages(LsaVector<sk_sp<Bitmap>>& images) = 0;
90     virtual void unpinImages() = 0;
91 
92     virtual void setSurfaceColorProperties(ColorMode colorMode) = 0;
93     virtual SkColorType getSurfaceColorType() const = 0;
94     virtual sk_sp<SkColorSpace> getSurfaceColorSpace() = 0;
95     virtual void setPictureCapturedCallback(
96             const std::function<void(sk_sp<SkPicture>&&)>& callback) = 0;
97 
98     virtual void setTargetSdrHdrRatio(float ratio) = 0;
99     virtual const SkM44& getPixelSnapMatrix() const = 0;
100 
~IRenderPipeline()101     virtual ~IRenderPipeline() {}
102 };
103 
104 } /* namespace renderthread */
105 } /* namespace uirenderer */
106 } /* namespace android */
107