blob: dc0b8f6dd2bcf5adf8f7cc0fb779aa6ee5ab3561 [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
24namespace android {
25namespace uirenderer {
26namespace skiapipeline {
27
28class SkiaPipeline : public renderthread::IRenderPipeline {
29public:
30 SkiaPipeline(renderthread::RenderThread& thread);
Stan Iliev232f3622017-08-23 17:15:09 -040031 virtual ~SkiaPipeline();
Stan Iliev500a0c32016-10-26 10:30:09 -040032
33 TaskManager* getTaskManager() override;
34
35 void onDestroyHardwareResources() override;
36
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -040037 bool pinImages(std::vector<SkImage*>& mutableImages) override;
38 bool pinImages(LsaVector<sk_sp<Bitmap>>& images) override { return false; }
39 void unpinImages() override;
Stan Iliev47fed6ba2017-10-18 17:56:43 -040040 void onPrepareTree() override;
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -040041
Stan Iliev500a0c32016-10-26 10:30:09 -040042 void renderLayers(const FrameBuilder::LightGeometry& lightGeometry,
Romain Guy07ae5052017-06-13 18:25:32 -070043 LayerUpdateQueue* layerUpdateQueue, bool opaque, bool wideColorGamut,
Stan Iliev500a0c32016-10-26 10:30:09 -040044 const BakedOpRenderer::LightInfo& lightInfo) override;
45
46 bool createOrUpdateLayer(RenderNode* node,
Romain Guy07ae5052017-06-13 18:25:32 -070047 const DamageAccumulator& damageAccumulator, bool wideColorGamut) override;
Stan Iliev500a0c32016-10-26 10:30:09 -040048
49 void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
Romain Guy07ae5052017-06-13 18:25:32 -070050 const std::vector< sp<RenderNode> >& nodes, bool opaque, bool wideColorGamut,
51 const Rect &contentDrawBounds, sk_sp<SkSurface> surface);
Stan Iliev500a0c32016-10-26 10:30:09 -040052
Stan Iliev23c38a92017-03-23 00:12:50 -040053 std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; }
54
Stan Iliev500a0c32016-10-26 10:30:09 -040055 static void destroyLayer(RenderNode* node);
56
57 static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
58
Romain Guy07ae5052017-06-13 18:25:32 -070059 static void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque, bool wideColorGamut);
Stan Iliev500a0c32016-10-26 10:30:09 -040060
61 static bool skpCaptureEnabled() { return false; }
62
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
89 adjustedLightCenter.y = - Properties::overrideLightPosY;
90 }
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,
100 const BakedOpRenderer::LightInfo& lightInfo) {
101 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,
Romain Guy07ae5052017-06-13 18:25:32 -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,
122 const std::vector< sp<RenderNode> >& nodes, const Rect &contentDrawBounds,
123 sk_sp<SkSurface>);
124
Stan Iliev23c38a92017-03-23 00:12:50 -0400125 /**
126 * Render mVectorDrawables into offscreen buffers.
127 */
128 void renderVectorDrawableCache();
129
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -0400130 std::vector<sk_sp<SkImage>> mPinnedImages;
Stan Iliev23c38a92017-03-23 00:12:50 -0400131
132 /**
133 * populated by prepareTree with dirty VDs
134 */
135 std::vector<VectorDrawableRoot*> mVectorDrawables;
Stan Iliev500a0c32016-10-26 10:30:09 -0400136 static float mLightRadius;
137 static uint8_t mAmbientShadowAlpha;
138 static uint8_t mSpotShadowAlpha;
139 static Vector3 mLightCenter;
140};
141
142} /* namespace skiapipeline */
143} /* namespace uirenderer */
144} /* namespace android */