blob: 27092270bb80efaddaf9f151031500547b83da66 [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"
21#include "renderthread/CanvasContext.h"
22#include "renderthread/IRenderPipeline.h"
Stan Iliev500a0c32016-10-26 10:30:09 -040023
Stan Ilieve9d00122017-09-19 12:07:10 -040024class SkPictureRecorder;
25
Stan Iliev500a0c32016-10-26 10:30:09 -040026namespace android {
27namespace uirenderer {
28namespace skiapipeline {
29
30class SkiaPipeline : public renderthread::IRenderPipeline {
31public:
32 SkiaPipeline(renderthread::RenderThread& thread);
Stan Iliev232f3622017-08-23 17:15:09 -040033 virtual ~SkiaPipeline();
Stan Iliev500a0c32016-10-26 10:30:09 -040034
35 TaskManager* getTaskManager() override;
36
37 void onDestroyHardwareResources() override;
38
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -040039 bool pinImages(std::vector<SkImage*>& mutableImages) override;
40 bool pinImages(LsaVector<sk_sp<Bitmap>>& images) override { return false; }
41 void unpinImages() override;
Stan Iliev47fed6ba2017-10-18 17:56:43 -040042 void onPrepareTree() override;
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -040043
Stan Iliev500a0c32016-10-26 10:30:09 -040044 void renderLayers(const FrameBuilder::LightGeometry& lightGeometry,
John Reck1bcacfd2017-11-03 10:12:19 -070045 LayerUpdateQueue* layerUpdateQueue, bool opaque, bool wideColorGamut,
46 const BakedOpRenderer::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,
49 bool wideColorGamut) override;
Stan Iliev500a0c32016-10-26 10:30:09 -040050
51 void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
John Reck1bcacfd2017-11-03 10:12:19 -070052 const std::vector<sp<RenderNode>>& nodes, bool opaque, bool wideColorGamut,
53 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 destroyLayer(RenderNode* node);
58
59 static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
60
Stan Ilieve9d00122017-09-19 12:07:10 -040061 void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque, bool wideColorGamut);
Stan Iliev500a0c32016-10-26 10:30:09 -040062
63 static float getLightRadius() {
64 if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) {
65 return Properties::overrideLightRadius;
66 }
67 return mLightRadius;
68 }
69
70 static uint8_t getAmbientShadowAlpha() {
71 if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) {
72 return Properties::overrideAmbientShadowStrength;
73 }
74 return mAmbientShadowAlpha;
75 }
76
77 static uint8_t getSpotShadowAlpha() {
78 if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) {
79 return Properties::overrideSpotShadowStrength;
80 }
81 return mSpotShadowAlpha;
82 }
83
84 static Vector3 getLightCenter() {
85 if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) {
86 Vector3 adjustedLightCenter = mLightCenter;
87 if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) {
88 // negated since this shifts up
John Reck1bcacfd2017-11-03 10:12:19 -070089 adjustedLightCenter.y = -Properties::overrideLightPosY;
Stan Iliev500a0c32016-10-26 10:30:09 -040090 }
91 if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) {
92 adjustedLightCenter.z = Properties::overrideLightPosZ;
93 }
94 return adjustedLightCenter;
95 }
96 return mLightCenter;
97 }
98
99 static void updateLighting(const FrameBuilder::LightGeometry& lightGeometry,
John Reck1bcacfd2017-11-03 10:12:19 -0700100 const BakedOpRenderer::LightInfo& lightInfo) {
Stan Iliev500a0c32016-10-26 10:30:09 -0400101 mLightRadius = lightGeometry.radius;
102 mAmbientShadowAlpha = lightInfo.ambientShadowAlpha;
103 mSpotShadowAlpha = lightInfo.spotShadowAlpha;
104 mLightCenter = lightGeometry.center;
105 }
Matt Sarett4bda6bf2016-11-07 15:43:41 -0500106
Stan Iliev500a0c32016-10-26 10:30:09 -0400107protected:
Matt Sarett4bda6bf2016-11-07 15:43:41 -0500108 void dumpResourceCacheUsage() const;
109
Stan Iliev500a0c32016-10-26 10:30:09 -0400110 renderthread::RenderThread& mRenderThread;
111
112private:
Matt Sarettf58cc922016-11-14 18:33:38 -0500113 void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip,
John Reck1bcacfd2017-11-03 10:12:19 -0700114 const std::vector<sp<RenderNode>>& nodes, bool opaque, bool wideColorGamut,
115 const Rect& contentDrawBounds, SkCanvas* canvas);
Matt Sarettf58cc922016-11-14 18:33:38 -0500116
117 /**
118 * Debugging feature. Draws a semi-transparent overlay on each pixel, indicating
119 * how many times it has been drawn.
120 */
121 void renderOverdraw(const LayerUpdateQueue& layers, const SkRect& clip,
John Reck1bcacfd2017-11-03 10:12:19 -0700122 const std::vector<sp<RenderNode>>& nodes, const Rect& contentDrawBounds,
123 sk_sp<SkSurface>);
Matt Sarettf58cc922016-11-14 18:33:38 -0500124
Stan Iliev23c38a92017-03-23 00:12:50 -0400125 /**
126 * Render mVectorDrawables into offscreen buffers.
127 */
128 void renderVectorDrawableCache();
129
Stan Ilieve9d00122017-09-19 12:07:10 -0400130 SkCanvas* tryCapture(SkSurface* surface);
131 void endCapture(SkSurface* surface);
132
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -0400133 std::vector<sk_sp<SkImage>> mPinnedImages;
Stan Iliev23c38a92017-03-23 00:12:50 -0400134
135 /**
136 * populated by prepareTree with dirty VDs
137 */
138 std::vector<VectorDrawableRoot*> mVectorDrawables;
Stan Ilieve9d00122017-09-19 12:07:10 -0400139
Stan Ilieve9d00122017-09-19 12:07:10 -0400140 // Block of properties used only for debugging to record a SkPicture and save it in a file.
141 /**
142 * mCapturedFile is used to enforce we don't capture more than once for a given name (cause
143 * permissions don't allow to reset a property from render thread).
144 */
145 std::string mCapturedFile;
146 /**
147 * mCaptureSequence counts how many frames are left to take in the sequence.
148 */
149 int mCaptureSequence = 0;
150 /**
151 * mSavePictureProcessor is used to run the file saving code in a separate thread.
152 */
153 class SavePictureProcessor;
154 sp<SavePictureProcessor> mSavePictureProcessor;
155 /**
156 * mRecorder holds the current picture recorder. We could store it on the stack to support
157 * parallel tryCapture calls (not really needed).
158 */
159 std::unique_ptr<SkPictureRecorder> mRecorder;
160
Stan Iliev500a0c32016-10-26 10:30:09 -0400161 static float mLightRadius;
162 static uint8_t mAmbientShadowAlpha;
163 static uint8_t mSpotShadowAlpha;
164 static Vector3 mLightCenter;
165};
166
167} /* namespace skiapipeline */
168} /* namespace uirenderer */
169} /* namespace android */