blob: 38ad9c09a8aab725a41b4e815b4b74281ba7ac99 [file] [log] [blame]
Stan Iliev500a0c32016-10-26 10:30:09 -04001/*
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
Stan Iliev500a0c32016-10-26 10:30:09 -040019#include <SkSurface.h>
John Reck1bcacfd2017-11-03 10:12:19 -070020#include "FrameBuilder.h"
Derek Sollenberger2d142132018-01-22 10:25:26 -050021#include "hwui/AnimatedImageDrawable.h"
John Reck1bcacfd2017-11-03 10:12:19 -070022#include "renderthread/CanvasContext.h"
23#include "renderthread/IRenderPipeline.h"
Stan Iliev500a0c32016-10-26 10:30:09 -040024
Stan Ilieve9d00122017-09-19 12:07:10 -040025class SkPictureRecorder;
26
Stan Iliev500a0c32016-10-26 10:30:09 -040027namespace android {
28namespace uirenderer {
29namespace skiapipeline {
30
31class SkiaPipeline : public renderthread::IRenderPipeline {
32public:
33 SkiaPipeline(renderthread::RenderThread& thread);
Stan Iliev232f3622017-08-23 17:15:09 -040034 virtual ~SkiaPipeline();
Stan Iliev500a0c32016-10-26 10:30:09 -040035
36 TaskManager* getTaskManager() override;
37
38 void onDestroyHardwareResources() override;
39
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -040040 bool pinImages(std::vector<SkImage*>& mutableImages) override;
41 bool pinImages(LsaVector<sk_sp<Bitmap>>& images) override { return false; }
42 void unpinImages() override;
Stan Iliev47fed6ba2017-10-18 17:56:43 -040043 void onPrepareTree() override;
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -040044
Stan Iliev500a0c32016-10-26 10:30:09 -040045 void renderLayers(const FrameBuilder::LightGeometry& lightGeometry,
John Reck1bcacfd2017-11-03 10:12:19 -070046 LayerUpdateQueue* layerUpdateQueue, bool opaque, bool wideColorGamut,
47 const BakedOpRenderer::LightInfo& lightInfo) override;
Stan Iliev500a0c32016-10-26 10:30:09 -040048
John Reck1bcacfd2017-11-03 10:12:19 -070049 bool createOrUpdateLayer(RenderNode* node, const DamageAccumulator& damageAccumulator,
Stan Iliev216b1572018-03-26 14:29:50 -040050 bool wideColorGamut, ErrorHandler* errorHandler) override;
Stan Iliev500a0c32016-10-26 10:30:09 -040051
52 void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
John Reck1bcacfd2017-11-03 10:12:19 -070053 const std::vector<sp<RenderNode>>& nodes, bool opaque, bool wideColorGamut,
54 const Rect& contentDrawBounds, sk_sp<SkSurface> surface);
Stan Iliev500a0c32016-10-26 10:30:09 -040055
Stan Iliev23c38a92017-03-23 00:12:50 -040056 std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; }
57
Stan Iliev500a0c32016-10-26 10:30:09 -040058 static void destroyLayer(RenderNode* node);
59
60 static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
61
Stan Ilieve9d00122017-09-19 12:07:10 -040062 void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque, bool wideColorGamut);
Stan Iliev500a0c32016-10-26 10:30:09 -040063
64 static float getLightRadius() {
65 if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) {
66 return Properties::overrideLightRadius;
67 }
68 return mLightRadius;
69 }
70
71 static uint8_t getAmbientShadowAlpha() {
72 if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) {
73 return Properties::overrideAmbientShadowStrength;
74 }
75 return mAmbientShadowAlpha;
76 }
77
78 static uint8_t getSpotShadowAlpha() {
79 if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) {
80 return Properties::overrideSpotShadowStrength;
81 }
82 return mSpotShadowAlpha;
83 }
84
85 static Vector3 getLightCenter() {
86 if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) {
87 Vector3 adjustedLightCenter = mLightCenter;
88 if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) {
89 // negated since this shifts up
John Reck1bcacfd2017-11-03 10:12:19 -070090 adjustedLightCenter.y = -Properties::overrideLightPosY;
Stan Iliev500a0c32016-10-26 10:30:09 -040091 }
92 if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) {
93 adjustedLightCenter.z = Properties::overrideLightPosZ;
94 }
95 return adjustedLightCenter;
96 }
97 return mLightCenter;
98 }
99
100 static void updateLighting(const FrameBuilder::LightGeometry& lightGeometry,
John Reck1bcacfd2017-11-03 10:12:19 -0700101 const BakedOpRenderer::LightInfo& lightInfo) {
Stan Iliev500a0c32016-10-26 10:30:09 -0400102 mLightRadius = lightGeometry.radius;
103 mAmbientShadowAlpha = lightInfo.ambientShadowAlpha;
104 mSpotShadowAlpha = lightInfo.spotShadowAlpha;
105 mLightCenter = lightGeometry.center;
106 }
Matt Sarett4bda6bf2016-11-07 15:43:41 -0500107
Stan Iliev500a0c32016-10-26 10:30:09 -0400108protected:
Matt Sarett4bda6bf2016-11-07 15:43:41 -0500109 void dumpResourceCacheUsage() const;
110
Stan Iliev500a0c32016-10-26 10:30:09 -0400111 renderthread::RenderThread& mRenderThread;
112
113private:
Matt Sarettf58cc922016-11-14 18:33:38 -0500114 void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip,
John Reck1bcacfd2017-11-03 10:12:19 -0700115 const std::vector<sp<RenderNode>>& nodes, bool opaque, bool wideColorGamut,
116 const Rect& contentDrawBounds, SkCanvas* canvas);
Matt Sarettf58cc922016-11-14 18:33:38 -0500117
118 /**
119 * Debugging feature. Draws a semi-transparent overlay on each pixel, indicating
120 * how many times it has been drawn.
121 */
122 void renderOverdraw(const LayerUpdateQueue& layers, const SkRect& clip,
John Reck1bcacfd2017-11-03 10:12:19 -0700123 const std::vector<sp<RenderNode>>& nodes, const Rect& contentDrawBounds,
124 sk_sp<SkSurface>);
Matt Sarettf58cc922016-11-14 18:33:38 -0500125
Stan Iliev23c38a92017-03-23 00:12:50 -0400126 /**
127 * Render mVectorDrawables into offscreen buffers.
128 */
129 void renderVectorDrawableCache();
130
Stan Ilieve9d00122017-09-19 12:07:10 -0400131 SkCanvas* tryCapture(SkSurface* surface);
132 void endCapture(SkSurface* surface);
133
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -0400134 std::vector<sk_sp<SkImage>> mPinnedImages;
Stan Iliev23c38a92017-03-23 00:12:50 -0400135
136 /**
137 * populated by prepareTree with dirty VDs
138 */
139 std::vector<VectorDrawableRoot*> mVectorDrawables;
Stan Ilieve9d00122017-09-19 12:07:10 -0400140
Stan Ilieve9d00122017-09-19 12:07:10 -0400141 // Block of properties used only for debugging to record a SkPicture and save it in a file.
142 /**
143 * mCapturedFile is used to enforce we don't capture more than once for a given name (cause
144 * permissions don't allow to reset a property from render thread).
145 */
146 std::string mCapturedFile;
147 /**
148 * mCaptureSequence counts how many frames are left to take in the sequence.
149 */
150 int mCaptureSequence = 0;
151 /**
152 * mSavePictureProcessor is used to run the file saving code in a separate thread.
153 */
154 class SavePictureProcessor;
155 sp<SavePictureProcessor> mSavePictureProcessor;
156 /**
157 * mRecorder holds the current picture recorder. We could store it on the stack to support
158 * parallel tryCapture calls (not really needed).
159 */
160 std::unique_ptr<SkPictureRecorder> mRecorder;
161
Stan Iliev500a0c32016-10-26 10:30:09 -0400162 static float mLightRadius;
163 static uint8_t mAmbientShadowAlpha;
164 static uint8_t mSpotShadowAlpha;
165 static Vector3 mLightCenter;
166};
167
168} /* namespace skiapipeline */
169} /* namespace uirenderer */
170} /* namespace android */