SkiaPipeline.h revision 4bda6bfaa6b8cb775f18f2453720d05f4cb29152
1500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev/*
2500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * Copyright (C) 2016 The Android Open Source Project
3500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev *
4500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * Licensed under the Apache License, Version 2.0 (the "License");
5500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * you may not use this file except in compliance with the License.
6500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * You may obtain a copy of the License at
7500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev *
8500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev *      http://www.apache.org/licenses/LICENSE-2.0
9500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev *
10500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * Unless required by applicable law or agreed to in writing, software
11500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * distributed under the License is distributed on an "AS IS" BASIS,
12500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * See the License for the specific language governing permissions and
14500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev * limitations under the License.
15500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev */
16500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
17500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev#pragma once
18500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
19500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev#include "renderthread/CanvasContext.h"
20500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev#include "FrameBuilder.h"
21500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev#include "renderthread/IRenderPipeline.h"
22500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev#include <SkSurface.h>
23500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
24500a0c30d4dcd012218c3e44a62926a1c34a259fStan Ilievnamespace android {
25500a0c30d4dcd012218c3e44a62926a1c34a259fStan Ilievnamespace uirenderer {
26500a0c30d4dcd012218c3e44a62926a1c34a259fStan Ilievnamespace skiapipeline {
27500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
28500a0c30d4dcd012218c3e44a62926a1c34a259fStan Ilievclass SkiaPipeline : public renderthread::IRenderPipeline {
29500a0c30d4dcd012218c3e44a62926a1c34a259fStan Ilievpublic:
30500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    SkiaPipeline(renderthread::RenderThread& thread);
31500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    virtual ~SkiaPipeline() {}
32500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
33500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    TaskManager* getTaskManager() override;
34500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
35500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    void onDestroyHardwareResources() override;
36500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
37500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    void renderLayers(const FrameBuilder::LightGeometry& lightGeometry,
38500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            LayerUpdateQueue* layerUpdateQueue, bool opaque,
39500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            const BakedOpRenderer::LightInfo& lightInfo) override;
40500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
41500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    bool createOrUpdateLayer(RenderNode* node,
42500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            const DamageAccumulator& damageAccumulator) override;
43500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
44500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip,
45500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            const std::vector< sp<RenderNode> >& nodes, bool opaque, const Rect &contentDrawBounds,
46500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            sk_sp<SkSurface> surface);
47500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
48500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static void destroyLayer(RenderNode* node);
49500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
50500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
51500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
52500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque);
53500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
54500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static bool skpCaptureEnabled() { return false; }
55500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
56500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static float getLightRadius() {
57500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) {
58500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            return Properties::overrideLightRadius;
59500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        }
60500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        return mLightRadius;
61500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    }
62500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
63500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static uint8_t getAmbientShadowAlpha() {
64500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) {
65500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            return Properties::overrideAmbientShadowStrength;
66500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        }
67500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        return mAmbientShadowAlpha;
68500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    }
69500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
70500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static uint8_t getSpotShadowAlpha() {
71500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) {
72500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            return Properties::overrideSpotShadowStrength;
73500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        }
74500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        return mSpotShadowAlpha;
75500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    }
76500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
77500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static Vector3 getLightCenter() {
78500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) {
79500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            Vector3 adjustedLightCenter = mLightCenter;
80500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) {
81500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev                // negated since this shifts up
82500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev                adjustedLightCenter.y = - Properties::overrideLightPosY;
83500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            }
84500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) {
85500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev                adjustedLightCenter.z = Properties::overrideLightPosZ;
86500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            }
87500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            return adjustedLightCenter;
88500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        }
89500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        return mLightCenter;
90500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    }
91500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
92500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static void updateLighting(const FrameBuilder::LightGeometry& lightGeometry,
93500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev            const BakedOpRenderer::LightInfo& lightInfo) {
94500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        mLightRadius = lightGeometry.radius;
95500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        mAmbientShadowAlpha = lightInfo.ambientShadowAlpha;
96500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        mSpotShadowAlpha = lightInfo.spotShadowAlpha;
97500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev        mLightCenter = lightGeometry.center;
98500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    }
994bda6bfaa6b8cb775f18f2453720d05f4cb29152Matt Sarett
100500a0c30d4dcd012218c3e44a62926a1c34a259fStan Ilievprotected:
1014bda6bfaa6b8cb775f18f2453720d05f4cb29152Matt Sarett    void dumpResourceCacheUsage() const;
1024bda6bfaa6b8cb775f18f2453720d05f4cb29152Matt Sarett
103500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    renderthread::RenderThread& mRenderThread;
104500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
105500a0c30d4dcd012218c3e44a62926a1c34a259fStan Ilievprivate:
106500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    TaskManager mTaskManager;
107500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static float mLightRadius;
108500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static uint8_t mAmbientShadowAlpha;
109500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static uint8_t mSpotShadowAlpha;
110500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev    static Vector3 mLightCenter;
111500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev};
112500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev
113500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev} /* namespace skiapipeline */
114500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev} /* namespace uirenderer */
115500a0c30d4dcd012218c3e44a62926a1c34a259fStan Iliev} /* namespace android */
116