Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | namespace android { |
| 25 | namespace uirenderer { |
| 26 | namespace skiapipeline { |
| 27 | |
| 28 | class SkiaPipeline : public renderthread::IRenderPipeline { |
| 29 | public: |
| 30 | SkiaPipeline(renderthread::RenderThread& thread); |
Stan Iliev | 232f362 | 2017-08-23 17:15:09 -0400 | [diff] [blame] | 31 | virtual ~SkiaPipeline(); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 32 | |
| 33 | TaskManager* getTaskManager() override; |
| 34 | |
| 35 | void onDestroyHardwareResources() override; |
| 36 | |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 37 | bool pinImages(std::vector<SkImage*>& mutableImages) override; |
| 38 | bool pinImages(LsaVector<sk_sp<Bitmap>>& images) override { return false; } |
| 39 | void unpinImages() override; |
Stan Iliev | 47fed6ba | 2017-10-18 17:56:43 -0400 | [diff] [blame^] | 40 | void onPrepareTree() override; |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 41 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 42 | void renderLayers(const FrameBuilder::LightGeometry& lightGeometry, |
Romain Guy | 07ae505 | 2017-06-13 18:25:32 -0700 | [diff] [blame] | 43 | LayerUpdateQueue* layerUpdateQueue, bool opaque, bool wideColorGamut, |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 44 | const BakedOpRenderer::LightInfo& lightInfo) override; |
| 45 | |
| 46 | bool createOrUpdateLayer(RenderNode* node, |
Romain Guy | 07ae505 | 2017-06-13 18:25:32 -0700 | [diff] [blame] | 47 | const DamageAccumulator& damageAccumulator, bool wideColorGamut) override; |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 48 | |
| 49 | void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip, |
Romain Guy | 07ae505 | 2017-06-13 18:25:32 -0700 | [diff] [blame] | 50 | const std::vector< sp<RenderNode> >& nodes, bool opaque, bool wideColorGamut, |
| 51 | const Rect &contentDrawBounds, sk_sp<SkSurface> surface); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 52 | |
Stan Iliev | 23c38a9 | 2017-03-23 00:12:50 -0400 | [diff] [blame] | 53 | std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; } |
| 54 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 55 | static void destroyLayer(RenderNode* node); |
| 56 | |
| 57 | static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap); |
| 58 | |
Romain Guy | 07ae505 | 2017-06-13 18:25:32 -0700 | [diff] [blame] | 59 | static void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque, bool wideColorGamut); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 60 | |
| 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 Sarett | 4bda6bf | 2016-11-07 15:43:41 -0500 | [diff] [blame] | 106 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 107 | protected: |
Matt Sarett | 4bda6bf | 2016-11-07 15:43:41 -0500 | [diff] [blame] | 108 | void dumpResourceCacheUsage() const; |
| 109 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 110 | renderthread::RenderThread& mRenderThread; |
| 111 | |
| 112 | private: |
Matt Sarett | f58cc92 | 2016-11-14 18:33:38 -0500 | [diff] [blame] | 113 | void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip, |
Romain Guy | 07ae505 | 2017-06-13 18:25:32 -0700 | [diff] [blame] | 114 | const std::vector< sp<RenderNode> >& nodes, bool opaque, bool wideColorGamut, |
| 115 | const Rect &contentDrawBounds, SkCanvas* canvas); |
Matt Sarett | f58cc92 | 2016-11-14 18:33:38 -0500 | [diff] [blame] | 116 | |
| 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 Iliev | 23c38a9 | 2017-03-23 00:12:50 -0400 | [diff] [blame] | 125 | /** |
| 126 | * Render mVectorDrawables into offscreen buffers. |
| 127 | */ |
| 128 | void renderVectorDrawableCache(); |
| 129 | |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 130 | std::vector<sk_sp<SkImage>> mPinnedImages; |
Stan Iliev | 23c38a9 | 2017-03-23 00:12:50 -0400 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * populated by prepareTree with dirty VDs |
| 134 | */ |
| 135 | std::vector<VectorDrawableRoot*> mVectorDrawables; |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 136 | 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 */ |