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 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 19 | #include <SkSurface.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 20 | #include "FrameBuilder.h" |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 21 | #include "hwui/AnimatedImageDrawable.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 22 | #include "renderthread/CanvasContext.h" |
| 23 | #include "renderthread/IRenderPipeline.h" |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 24 | |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 25 | class SkPictureRecorder; |
| 26 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | namespace skiapipeline { |
| 30 | |
| 31 | class SkiaPipeline : public renderthread::IRenderPipeline { |
| 32 | public: |
| 33 | SkiaPipeline(renderthread::RenderThread& thread); |
Stan Iliev | 232f362 | 2017-08-23 17:15:09 -0400 | [diff] [blame] | 34 | virtual ~SkiaPipeline(); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 35 | |
| 36 | TaskManager* getTaskManager() override; |
| 37 | |
| 38 | void onDestroyHardwareResources() override; |
| 39 | |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 40 | bool pinImages(std::vector<SkImage*>& mutableImages) override; |
| 41 | bool pinImages(LsaVector<sk_sp<Bitmap>>& images) override { return false; } |
| 42 | void unpinImages() override; |
Stan Iliev | 47fed6ba | 2017-10-18 17:56:43 -0400 | [diff] [blame] | 43 | void onPrepareTree() override; |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 44 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 45 | void renderLayers(const FrameBuilder::LightGeometry& lightGeometry, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 46 | LayerUpdateQueue* layerUpdateQueue, bool opaque, bool wideColorGamut, |
| 47 | const BakedOpRenderer::LightInfo& lightInfo) override; |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 48 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 49 | bool createOrUpdateLayer(RenderNode* node, const DamageAccumulator& damageAccumulator, |
Stan Iliev | 216b157 | 2018-03-26 14:29:50 -0400 | [diff] [blame^] | 50 | bool wideColorGamut, ErrorHandler* errorHandler) override; |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 51 | |
| 52 | void renderFrame(const LayerUpdateQueue& layers, const SkRect& clip, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 53 | const std::vector<sp<RenderNode>>& nodes, bool opaque, bool wideColorGamut, |
| 54 | const Rect& contentDrawBounds, sk_sp<SkSurface> surface); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 55 | |
Stan Iliev | 23c38a9 | 2017-03-23 00:12:50 -0400 | [diff] [blame] | 56 | std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; } |
| 57 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 58 | static void destroyLayer(RenderNode* node); |
| 59 | |
| 60 | static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap); |
| 61 | |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 62 | void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque, bool wideColorGamut); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 63 | |
| 64 | static float getLightRadius() { |
| 65 | if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) { |
| 66 | return Properties::overrideLightRadius; |
| 67 | } |
| 68 | return mLightRadius; |
| 69 | } |
| 70 | |
| 71 | static uint8_t getAmbientShadowAlpha() { |
| 72 | if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) { |
| 73 | return Properties::overrideAmbientShadowStrength; |
| 74 | } |
| 75 | return mAmbientShadowAlpha; |
| 76 | } |
| 77 | |
| 78 | static uint8_t getSpotShadowAlpha() { |
| 79 | if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) { |
| 80 | return Properties::overrideSpotShadowStrength; |
| 81 | } |
| 82 | return mSpotShadowAlpha; |
| 83 | } |
| 84 | |
| 85 | static Vector3 getLightCenter() { |
| 86 | if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) { |
| 87 | Vector3 adjustedLightCenter = mLightCenter; |
| 88 | if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) { |
| 89 | // negated since this shifts up |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 90 | adjustedLightCenter.y = -Properties::overrideLightPosY; |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 91 | } |
| 92 | if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) { |
| 93 | adjustedLightCenter.z = Properties::overrideLightPosZ; |
| 94 | } |
| 95 | return adjustedLightCenter; |
| 96 | } |
| 97 | return mLightCenter; |
| 98 | } |
| 99 | |
| 100 | static void updateLighting(const FrameBuilder::LightGeometry& lightGeometry, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 101 | const BakedOpRenderer::LightInfo& lightInfo) { |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 102 | mLightRadius = lightGeometry.radius; |
| 103 | mAmbientShadowAlpha = lightInfo.ambientShadowAlpha; |
| 104 | mSpotShadowAlpha = lightInfo.spotShadowAlpha; |
| 105 | mLightCenter = lightGeometry.center; |
| 106 | } |
Matt Sarett | 4bda6bf | 2016-11-07 15:43:41 -0500 | [diff] [blame] | 107 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 108 | protected: |
Matt Sarett | 4bda6bf | 2016-11-07 15:43:41 -0500 | [diff] [blame] | 109 | void dumpResourceCacheUsage() const; |
| 110 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 111 | renderthread::RenderThread& mRenderThread; |
| 112 | |
| 113 | private: |
Matt Sarett | f58cc92 | 2016-11-14 18:33:38 -0500 | [diff] [blame] | 114 | void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 115 | const std::vector<sp<RenderNode>>& nodes, bool opaque, bool wideColorGamut, |
| 116 | const Rect& contentDrawBounds, SkCanvas* canvas); |
Matt Sarett | f58cc92 | 2016-11-14 18:33:38 -0500 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * Debugging feature. Draws a semi-transparent overlay on each pixel, indicating |
| 120 | * how many times it has been drawn. |
| 121 | */ |
| 122 | void renderOverdraw(const LayerUpdateQueue& layers, const SkRect& clip, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 123 | const std::vector<sp<RenderNode>>& nodes, const Rect& contentDrawBounds, |
| 124 | sk_sp<SkSurface>); |
Matt Sarett | f58cc92 | 2016-11-14 18:33:38 -0500 | [diff] [blame] | 125 | |
Stan Iliev | 23c38a9 | 2017-03-23 00:12:50 -0400 | [diff] [blame] | 126 | /** |
| 127 | * Render mVectorDrawables into offscreen buffers. |
| 128 | */ |
| 129 | void renderVectorDrawableCache(); |
| 130 | |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 131 | SkCanvas* tryCapture(SkSurface* surface); |
| 132 | void endCapture(SkSurface* surface); |
| 133 | |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 134 | std::vector<sk_sp<SkImage>> mPinnedImages; |
Stan Iliev | 23c38a9 | 2017-03-23 00:12:50 -0400 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * populated by prepareTree with dirty VDs |
| 138 | */ |
| 139 | std::vector<VectorDrawableRoot*> mVectorDrawables; |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 140 | |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 141 | // Block of properties used only for debugging to record a SkPicture and save it in a file. |
| 142 | /** |
| 143 | * mCapturedFile is used to enforce we don't capture more than once for a given name (cause |
| 144 | * permissions don't allow to reset a property from render thread). |
| 145 | */ |
| 146 | std::string mCapturedFile; |
| 147 | /** |
| 148 | * mCaptureSequence counts how many frames are left to take in the sequence. |
| 149 | */ |
| 150 | int mCaptureSequence = 0; |
| 151 | /** |
| 152 | * mSavePictureProcessor is used to run the file saving code in a separate thread. |
| 153 | */ |
| 154 | class SavePictureProcessor; |
| 155 | sp<SavePictureProcessor> mSavePictureProcessor; |
| 156 | /** |
| 157 | * mRecorder holds the current picture recorder. We could store it on the stack to support |
| 158 | * parallel tryCapture calls (not really needed). |
| 159 | */ |
| 160 | std::unique_ptr<SkPictureRecorder> mRecorder; |
| 161 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 162 | static float mLightRadius; |
| 163 | static uint8_t mAmbientShadowAlpha; |
| 164 | static uint8_t mSpotShadowAlpha; |
| 165 | static Vector3 mLightCenter; |
| 166 | }; |
| 167 | |
| 168 | } /* namespace skiapipeline */ |
| 169 | } /* namespace uirenderer */ |
| 170 | } /* namespace android */ |