blob: ee9158c5ffc14257c0eb3c04efa59eb86d894984 [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 Reckd9d7f122018-05-03 14:40:56 -070020#include "Lighting.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
Peiyong Lin1f6aa122018-09-10 16:28:08 -070045 void renderLayers(const LightGeometry& lightGeometry, LayerUpdateQueue* layerUpdateQueue,
46 bool opaque, const LightInfo& lightInfo) override;
Stan Iliev500a0c32016-10-26 10:30:09 -040047
John Reck1bcacfd2017-11-03 10:12:19 -070048 bool createOrUpdateLayer(RenderNode* node, const DamageAccumulator& damageAccumulator,
Peiyong Lin1f6aa122018-09-10 16:28:08 -070049 ErrorHandler* errorHandler) override;
Stan Iliev500a0c32016-10-26 10:30:09 -040050
51 void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
Peiyong Lin1f6aa122018-09-10 16:28:08 -070052 const std::vector<sp<RenderNode>>& nodes, bool opaque,
John Reck1bcacfd2017-11-03 10:12:19 -070053 const Rect& contentDrawBounds, sk_sp<SkSurface> surface);
Stan Iliev500a0c32016-10-26 10:30:09 -040054
Stan Iliev23c38a92017-03-23 00:12:50 -040055 std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; }
56
Stan Iliev500a0c32016-10-26 10:30:09 -040057 static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
58
Peiyong Lin1f6aa122018-09-10 16:28:08 -070059 void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque);
Stan Iliev500a0c32016-10-26 10:30:09 -040060
61 static float getLightRadius() {
62 if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) {
63 return Properties::overrideLightRadius;
64 }
65 return mLightRadius;
66 }
67
68 static uint8_t getAmbientShadowAlpha() {
69 if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) {
70 return Properties::overrideAmbientShadowStrength;
71 }
72 return mAmbientShadowAlpha;
73 }
74
75 static uint8_t getSpotShadowAlpha() {
76 if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) {
77 return Properties::overrideSpotShadowStrength;
78 }
79 return mSpotShadowAlpha;
80 }
81
82 static Vector3 getLightCenter() {
83 if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) {
84 Vector3 adjustedLightCenter = mLightCenter;
85 if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) {
86 // negated since this shifts up
John Reck1bcacfd2017-11-03 10:12:19 -070087 adjustedLightCenter.y = -Properties::overrideLightPosY;
Stan Iliev500a0c32016-10-26 10:30:09 -040088 }
89 if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) {
90 adjustedLightCenter.z = Properties::overrideLightPosZ;
91 }
92 return adjustedLightCenter;
93 }
94 return mLightCenter;
95 }
96
John Reckd9d7f122018-05-03 14:40:56 -070097 static void updateLighting(const LightGeometry& lightGeometry,
98 const LightInfo& lightInfo) {
Stan Iliev500a0c32016-10-26 10:30:09 -040099 mLightRadius = lightGeometry.radius;
100 mAmbientShadowAlpha = lightInfo.ambientShadowAlpha;
101 mSpotShadowAlpha = lightInfo.spotShadowAlpha;
102 mLightCenter = lightGeometry.center;
103 }
Matt Sarett4bda6bf2016-11-07 15:43:41 -0500104
Stan Iliev500a0c32016-10-26 10:30:09 -0400105protected:
Matt Sarett4bda6bf2016-11-07 15:43:41 -0500106 void dumpResourceCacheUsage() const;
107
Stan Iliev500a0c32016-10-26 10:30:09 -0400108 renderthread::RenderThread& mRenderThread;
109
110private:
Matt Sarettf58cc922016-11-14 18:33:38 -0500111 void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip,
Peiyong Lin1f6aa122018-09-10 16:28:08 -0700112 const std::vector<sp<RenderNode>>& nodes, bool opaque,
John Reck1bcacfd2017-11-03 10:12:19 -0700113 const Rect& contentDrawBounds, SkCanvas* canvas);
Matt Sarettf58cc922016-11-14 18:33:38 -0500114
115 /**
116 * Debugging feature. Draws a semi-transparent overlay on each pixel, indicating
117 * how many times it has been drawn.
118 */
119 void renderOverdraw(const LayerUpdateQueue& layers, const SkRect& clip,
John Reck1bcacfd2017-11-03 10:12:19 -0700120 const std::vector<sp<RenderNode>>& nodes, const Rect& contentDrawBounds,
121 sk_sp<SkSurface>);
Matt Sarettf58cc922016-11-14 18:33:38 -0500122
Stan Iliev23c38a92017-03-23 00:12:50 -0400123 /**
124 * Render mVectorDrawables into offscreen buffers.
125 */
126 void renderVectorDrawableCache();
127
Stan Ilieve9d00122017-09-19 12:07:10 -0400128 SkCanvas* tryCapture(SkSurface* surface);
129 void endCapture(SkSurface* surface);
130
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -0400131 std::vector<sk_sp<SkImage>> mPinnedImages;
Stan Iliev23c38a92017-03-23 00:12:50 -0400132
133 /**
134 * populated by prepareTree with dirty VDs
135 */
136 std::vector<VectorDrawableRoot*> mVectorDrawables;
Stan Ilieve9d00122017-09-19 12:07:10 -0400137
Stan Ilieve9d00122017-09-19 12:07:10 -0400138 // Block of properties used only for debugging to record a SkPicture and save it in a file.
139 /**
140 * mCapturedFile is used to enforce we don't capture more than once for a given name (cause
141 * permissions don't allow to reset a property from render thread).
142 */
143 std::string mCapturedFile;
144 /**
145 * mCaptureSequence counts how many frames are left to take in the sequence.
146 */
147 int mCaptureSequence = 0;
148 /**
149 * mSavePictureProcessor is used to run the file saving code in a separate thread.
150 */
151 class SavePictureProcessor;
152 sp<SavePictureProcessor> mSavePictureProcessor;
153 /**
154 * mRecorder holds the current picture recorder. We could store it on the stack to support
155 * parallel tryCapture calls (not really needed).
156 */
157 std::unique_ptr<SkPictureRecorder> mRecorder;
158
Stan Iliev500a0c32016-10-26 10:30:09 -0400159 static float mLightRadius;
160 static uint8_t mAmbientShadowAlpha;
161 static uint8_t mSpotShadowAlpha;
162 static Vector3 mLightCenter;
163};
164
165} /* namespace skiapipeline */
166} /* namespace uirenderer */
167} /* namespace android */