blob: 6f5e719fc2c249f2a0985ad6ea0b87ee7b63939c [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);
31 virtual ~SkiaPipeline() {}
32
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;
40
Stan Iliev500a0c32016-10-26 10:30:09 -040041 void renderLayers(const FrameBuilder::LightGeometry& lightGeometry,
42 LayerUpdateQueue* layerUpdateQueue, bool opaque,
43 const BakedOpRenderer::LightInfo& lightInfo) override;
44
45 bool createOrUpdateLayer(RenderNode* node,
46 const DamageAccumulator& damageAccumulator) override;
47
48 void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
49 const std::vector< sp<RenderNode> >& nodes, bool opaque, const Rect &contentDrawBounds,
50 sk_sp<SkSurface> surface);
51
Stan Iliev23c38a92017-03-23 00:12:50 -040052 std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; }
53
Stan Iliev500a0c32016-10-26 10:30:09 -040054 static void destroyLayer(RenderNode* node);
55
56 static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
57
58 static void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque);
59
60 static bool skpCaptureEnabled() { return false; }
61
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,
113 const std::vector< sp<RenderNode> >& nodes, bool opaque, const Rect &contentDrawBounds,
114 SkCanvas* canvas);
115
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 Iliev500a0c32016-10-26 10:30:09 -0400129 TaskManager mTaskManager;
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 */