blob: d1faa8a4ccb5698abc30f894020da06f99eacbcf [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
19#include "renderthread/CanvasContext.h"
20#include "FrameBuilder.h"
21#include "renderthread/IRenderPipeline.h"
22#include <SkSurface.h>
23
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;
42
Stan Iliev500a0c32016-10-26 10:30:09 -040043 void renderLayers(const FrameBuilder::LightGeometry& lightGeometry,
Romain Guy07ae5052017-06-13 18:25:32 -070044 LayerUpdateQueue* layerUpdateQueue, bool opaque, bool wideColorGamut,
Stan Iliev500a0c32016-10-26 10:30:09 -040045 const BakedOpRenderer::LightInfo& lightInfo) override;
46
47 bool createOrUpdateLayer(RenderNode* node,
Romain Guy07ae5052017-06-13 18:25:32 -070048 const DamageAccumulator& damageAccumulator, bool wideColorGamut) override;
Stan Iliev500a0c32016-10-26 10:30:09 -040049
50 void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
Romain Guy07ae5052017-06-13 18:25:32 -070051 const std::vector< sp<RenderNode> >& nodes, bool opaque, bool wideColorGamut,
52 const Rect &contentDrawBounds, sk_sp<SkSurface> surface);
Stan Iliev500a0c32016-10-26 10:30:09 -040053
Stan Iliev23c38a92017-03-23 00:12:50 -040054 std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; }
55
Stan Iliev500a0c32016-10-26 10:30:09 -040056 static void destroyLayer(RenderNode* node);
57
58 static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
59
Stan Ilieve9d00122017-09-19 12:07:10 -040060 void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque, bool wideColorGamut);
Stan Iliev500a0c32016-10-26 10:30:09 -040061
62 static float getLightRadius() {
63 if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) {
64 return Properties::overrideLightRadius;
65 }
66 return mLightRadius;
67 }
68
69 static uint8_t getAmbientShadowAlpha() {
70 if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) {
71 return Properties::overrideAmbientShadowStrength;
72 }
73 return mAmbientShadowAlpha;
74 }
75
76 static uint8_t getSpotShadowAlpha() {
77 if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) {
78 return Properties::overrideSpotShadowStrength;
79 }
80 return mSpotShadowAlpha;
81 }
82
83 static Vector3 getLightCenter() {
84 if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) {
85 Vector3 adjustedLightCenter = mLightCenter;
86 if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) {
87 // negated since this shifts up
88 adjustedLightCenter.y = - Properties::overrideLightPosY;
89 }
90 if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) {
91 adjustedLightCenter.z = Properties::overrideLightPosZ;
92 }
93 return adjustedLightCenter;
94 }
95 return mLightCenter;
96 }
97
98 static void updateLighting(const FrameBuilder::LightGeometry& lightGeometry,
99 const BakedOpRenderer::LightInfo& lightInfo) {
100 mLightRadius = lightGeometry.radius;
101 mAmbientShadowAlpha = lightInfo.ambientShadowAlpha;
102 mSpotShadowAlpha = lightInfo.spotShadowAlpha;
103 mLightCenter = lightGeometry.center;
104 }
Matt Sarett4bda6bf2016-11-07 15:43:41 -0500105
Stan Iliev500a0c32016-10-26 10:30:09 -0400106protected:
Matt Sarett4bda6bf2016-11-07 15:43:41 -0500107 void dumpResourceCacheUsage() const;
108
Stan Iliev500a0c32016-10-26 10:30:09 -0400109 renderthread::RenderThread& mRenderThread;
110
111private:
Matt Sarettf58cc922016-11-14 18:33:38 -0500112 void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip,
Romain Guy07ae5052017-06-13 18:25:32 -0700113 const std::vector< sp<RenderNode> >& nodes, bool opaque, bool wideColorGamut,
114 const Rect &contentDrawBounds, SkCanvas* canvas);
Matt Sarettf58cc922016-11-14 18:33:38 -0500115
116 /**
117 * Debugging feature. Draws a semi-transparent overlay on each pixel, indicating
118 * how many times it has been drawn.
119 */
120 void renderOverdraw(const LayerUpdateQueue& layers, const SkRect& clip,
121 const std::vector< sp<RenderNode> >& nodes, const Rect &contentDrawBounds,
122 sk_sp<SkSurface>);
123
Stan Iliev23c38a92017-03-23 00:12:50 -0400124 /**
125 * Render mVectorDrawables into offscreen buffers.
126 */
127 void renderVectorDrawableCache();
128
Stan Ilieve9d00122017-09-19 12:07:10 -0400129 SkCanvas* tryCapture(SkSurface* surface);
130 void endCapture(SkSurface* surface);
131
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -0400132 std::vector<sk_sp<SkImage>> mPinnedImages;
Stan Iliev23c38a92017-03-23 00:12:50 -0400133
134 /**
135 * populated by prepareTree with dirty VDs
136 */
137 std::vector<VectorDrawableRoot*> mVectorDrawables;
Stan Ilieve9d00122017-09-19 12:07:10 -0400138
139
140 // 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 */