blob: 42a411a6808c320f202cd23afa1b76b6387b5b5e [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
Peiyong Lin189021b2018-09-27 16:41:40 -070051 SkColorType getSurfaceColorType() const { return mSurfaceColorType; }
52 sk_sp<SkColorSpace> getSurfaceColorSpace() override { return mSurfaceColorSpace; }
53
Stan Iliev500a0c32016-10-26 10:30:09 -040054 void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
Peiyong Lin1f6aa122018-09-10 16:28:08 -070055 const std::vector<sp<RenderNode>>& nodes, bool opaque,
John Reck1bcacfd2017-11-03 10:12:19 -070056 const Rect& contentDrawBounds, sk_sp<SkSurface> surface);
Stan Iliev500a0c32016-10-26 10:30:09 -040057
Stan Iliev23c38a92017-03-23 00:12:50 -040058 std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; }
59
Stan Iliev500a0c32016-10-26 10:30:09 -040060 static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
61
Peiyong Lin1f6aa122018-09-10 16:28:08 -070062 void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque);
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
John Reckd9d7f122018-05-03 14:40:56 -0700100 static void updateLighting(const LightGeometry& lightGeometry,
101 const 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;
Peiyong Lin189021b2018-09-27 16:41:40 -0700112 SkColorType mSurfaceColorType;
113 sk_sp<SkColorSpace> mSurfaceColorSpace;
Stan Iliev500a0c32016-10-26 10:30:09 -0400114
115private:
Matt Sarettf58cc922016-11-14 18:33:38 -0500116 void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip,
Peiyong Lin1f6aa122018-09-10 16:28:08 -0700117 const std::vector<sp<RenderNode>>& nodes, bool opaque,
John Reck1bcacfd2017-11-03 10:12:19 -0700118 const Rect& contentDrawBounds, SkCanvas* canvas);
Matt Sarettf58cc922016-11-14 18:33:38 -0500119
120 /**
121 * Debugging feature. Draws a semi-transparent overlay on each pixel, indicating
122 * how many times it has been drawn.
123 */
124 void renderOverdraw(const LayerUpdateQueue& layers, const SkRect& clip,
John Reck1bcacfd2017-11-03 10:12:19 -0700125 const std::vector<sp<RenderNode>>& nodes, const Rect& contentDrawBounds,
126 sk_sp<SkSurface>);
Matt Sarettf58cc922016-11-14 18:33:38 -0500127
Stan Iliev23c38a92017-03-23 00:12:50 -0400128 /**
129 * Render mVectorDrawables into offscreen buffers.
130 */
131 void renderVectorDrawableCache();
132
Stan Ilieve9d00122017-09-19 12:07:10 -0400133 SkCanvas* tryCapture(SkSurface* surface);
134 void endCapture(SkSurface* surface);
135
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -0400136 std::vector<sk_sp<SkImage>> mPinnedImages;
Stan Iliev23c38a92017-03-23 00:12:50 -0400137
138 /**
139 * populated by prepareTree with dirty VDs
140 */
141 std::vector<VectorDrawableRoot*> mVectorDrawables;
Stan Ilieve9d00122017-09-19 12:07:10 -0400142
Stan Ilieve9d00122017-09-19 12:07:10 -0400143 // Block of properties used only for debugging to record a SkPicture and save it in a file.
144 /**
145 * mCapturedFile is used to enforce we don't capture more than once for a given name (cause
146 * permissions don't allow to reset a property from render thread).
147 */
148 std::string mCapturedFile;
149 /**
150 * mCaptureSequence counts how many frames are left to take in the sequence.
151 */
152 int mCaptureSequence = 0;
153 /**
154 * mSavePictureProcessor is used to run the file saving code in a separate thread.
155 */
156 class SavePictureProcessor;
157 sp<SavePictureProcessor> mSavePictureProcessor;
158 /**
159 * mRecorder holds the current picture recorder. We could store it on the stack to support
160 * parallel tryCapture calls (not really needed).
161 */
162 std::unique_ptr<SkPictureRecorder> mRecorder;
163
Stan Iliev500a0c32016-10-26 10:30:09 -0400164 static float mLightRadius;
165 static uint8_t mAmbientShadowAlpha;
166 static uint8_t mSpotShadowAlpha;
167 static Vector3 mLightCenter;
168};
169
170} /* namespace skiapipeline */
171} /* namespace uirenderer */
172} /* namespace android */