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