diff options
-rw-r--r-- | libs/hwui/Android.bp | 1 | ||||
-rw-r--r-- | libs/hwui/LightingInfo.cpp | 31 | ||||
-rw-r--r-- | libs/hwui/LightingInfo.h | 86 | ||||
-rw-r--r-- | libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp | 10 | ||||
-rw-r--r-- | libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp | 3 | ||||
-rw-r--r-- | libs/hwui/pipeline/skia/SkiaPipeline.cpp | 19 | ||||
-rw-r--r-- | libs/hwui/pipeline/skia/SkiaPipeline.h | 48 | ||||
-rw-r--r-- | libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp | 3 |
8 files changed, 136 insertions, 65 deletions
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp index 82bcf9e9afa4..354a4b323f41 100644 --- a/libs/hwui/Android.bp +++ b/libs/hwui/Android.bp @@ -241,6 +241,7 @@ cc_defaults { "JankTracker.cpp", "Layer.cpp", "LayerUpdateQueue.cpp", + "LightingInfo.cpp", "ProfileData.cpp", "ProfileDataContainer.cpp", "Readback.cpp", diff --git a/libs/hwui/LightingInfo.cpp b/libs/hwui/LightingInfo.cpp new file mode 100644 index 000000000000..83bb255f3c3b --- /dev/null +++ b/libs/hwui/LightingInfo.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LightingInfo.h" + +#include <float.h> + +namespace android { +namespace uirenderer { + +float LightingInfo::mLightRadius = 0; +uint8_t LightingInfo::mAmbientShadowAlpha = 0; +uint8_t LightingInfo::mSpotShadowAlpha = 0; + +Vector3 LightingInfo::mLightCenter = {FLT_MIN, FLT_MIN, FLT_MIN}; + +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/LightingInfo.h b/libs/hwui/LightingInfo.h new file mode 100644 index 000000000000..3112eb3e0d73 --- /dev/null +++ b/libs/hwui/LightingInfo.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "Lighting.h" +#include "Properties.h" + +namespace android { +namespace uirenderer { + +class LightingInfo { +public: + + static float getLightRadius() { + if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) { + return Properties::overrideLightRadius; + } + return mLightRadius; + } + + static uint8_t getAmbientShadowAlpha() { + if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) { + return Properties::overrideAmbientShadowStrength; + } + return mAmbientShadowAlpha; + } + + static uint8_t getSpotShadowAlpha() { + if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) { + return Properties::overrideSpotShadowStrength; + } + return mSpotShadowAlpha; + } + + static Vector3 getLightCenter() { + if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) { + Vector3 adjustedLightCenter = mLightCenter; + if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) { + // negated since this shifts up + adjustedLightCenter.y = -Properties::overrideLightPosY; + } + if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) { + adjustedLightCenter.z = Properties::overrideLightPosZ; + } + return adjustedLightCenter; + } + return mLightCenter; + } + + static Vector3 getLightCenterRaw() { + return mLightCenter; + } + + static void setLightCenterRaw(const Vector3& lightCenter) { + mLightCenter = lightCenter; + } + + static void updateLighting(const LightGeometry& lightGeometry, const LightInfo& lightInfo) { + mLightRadius = lightGeometry.radius; + mAmbientShadowAlpha = lightInfo.ambientShadowAlpha; + mSpotShadowAlpha = lightInfo.spotShadowAlpha; + mLightCenter = lightGeometry.center; + } +private: + static float mLightRadius; + static uint8_t mAmbientShadowAlpha; + static uint8_t mSpotShadowAlpha; + static Vector3 mLightCenter; +}; + +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp index 0a3c8f4347eb..5133baebae18 100644 --- a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp +++ b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp @@ -17,7 +17,7 @@ #include "ReorderBarrierDrawables.h" #include "RenderNode.h" #include "SkiaDisplayList.h" -#include "SkiaPipeline.h" +#include "LightingInfo.h" #include <SkPathOps.h> #include <SkShadowUtils.h> @@ -139,8 +139,8 @@ void EndReorderBarrierDrawable::drawShadow(SkCanvas* canvas, RenderNodeDrawable* return; } - float ambientAlpha = (SkiaPipeline::getAmbientShadowAlpha() / 255.f) * casterAlpha; - float spotAlpha = (SkiaPipeline::getSpotShadowAlpha() / 255.f) * casterAlpha; + float ambientAlpha = (LightingInfo::getAmbientShadowAlpha() / 255.f) * casterAlpha; + float spotAlpha = (LightingInfo::getSpotShadowAlpha() / 255.f) * casterAlpha; const RevealClip& revealClip = casterProperties.getRevealClip(); const SkPath* revealClipPath = revealClip.getPath(); @@ -192,7 +192,7 @@ void EndReorderBarrierDrawable::drawShadow(SkCanvas* canvas, RenderNodeDrawable* casterPath = &tmpPath; } - const Vector3 lightPos = SkiaPipeline::getLightCenter(); + const Vector3 lightPos = LightingInfo::getLightCenter(); SkPoint3 skiaLightPos = SkPoint3::Make(lightPos.x, lightPos.y, lightPos.z); SkPoint3 zParams; if (shadowMatrix.hasPerspective()) { @@ -206,7 +206,7 @@ void EndReorderBarrierDrawable::drawShadow(SkCanvas* canvas, RenderNodeDrawable* SkColor ambientColor = multiplyAlpha(casterProperties.getAmbientShadowColor(), ambientAlpha); SkColor spotColor = multiplyAlpha(casterProperties.getSpotShadowColor(), spotAlpha); SkShadowUtils::DrawShadow( - canvas, *casterPath, zParams, skiaLightPos, SkiaPipeline::getLightRadius(), + canvas, *casterPath, zParams, skiaLightPos, LightingInfo::getLightRadius(), ambientColor, spotColor, casterAlpha < 1.0f ? SkShadowFlags::kTransparentOccluder_ShadowFlag : 0); } diff --git a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp index 8092b1d10659..e7efe2ff798b 100644 --- a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp @@ -18,6 +18,7 @@ #include "DeferredLayerUpdater.h" #include "LayerDrawable.h" +#include "LightingInfo.h" #include "SkiaPipeline.h" #include "SkiaProfileRenderer.h" #include "hwui/Bitmap.h" @@ -99,7 +100,7 @@ bool SkiaOpenGLPipeline::draw(const Frame& frame, const SkRect& screenDirty, con mRenderThread.getGrContext(), backendRT, this->getSurfaceOrigin(), colorType, mSurfaceColorSpace, &props)); - SkiaPipeline::updateLighting(lightGeometry, lightInfo); + LightingInfo::updateLighting(lightGeometry, lightInfo); renderFrame(*layerUpdateQueue, dirty, renderNodes, opaque, contentDrawBounds, surface, SkMatrix::I()); layerUpdateQueue->clear(); diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.cpp b/libs/hwui/pipeline/skia/SkiaPipeline.cpp index 066828190627..ff29a5b9e352 100644 --- a/libs/hwui/pipeline/skia/SkiaPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaPipeline.cpp @@ -23,6 +23,7 @@ #include <SkOverdrawColorFilter.h> #include <SkPicture.h> #include <SkPictureRecorder.h> +#include "LightingInfo.h" #include "TreeInfo.h" #include "VectorDrawable.h" #include "thread/CommonPool.h" @@ -38,12 +39,6 @@ namespace android { namespace uirenderer { namespace skiapipeline { -float SkiaPipeline::mLightRadius = 0; -uint8_t SkiaPipeline::mAmbientShadowAlpha = 0; -uint8_t SkiaPipeline::mSpotShadowAlpha = 0; - -Vector3 SkiaPipeline::mLightCenter = {FLT_MIN, FLT_MIN, FLT_MIN}; - SkiaPipeline::SkiaPipeline(RenderThread& thread) : mRenderThread(thread) { mVectorDrawables.reserve(30); } @@ -84,7 +79,7 @@ void SkiaPipeline::onPrepareTree() { void SkiaPipeline::renderLayers(const LightGeometry& lightGeometry, LayerUpdateQueue* layerUpdateQueue, bool opaque, const LightInfo& lightInfo) { - updateLighting(lightGeometry, lightInfo); + LightingInfo::updateLighting(lightGeometry, lightInfo); ATRACE_NAME("draw layers"); renderVectorDrawableCache(); renderLayersImpl(*layerUpdateQueue, opaque); @@ -117,9 +112,13 @@ void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque) layerCanvas->androidFramework_setDeviceClipRestriction(layerDamage.toSkIRect()); - auto savedLightCenter = mLightCenter; + // TODO: put localized light center calculation and storage to a drawable related code. + // It does not seem right to store something localized in a global state + const Vector3 savedLightCenter(LightingInfo::getLightCenterRaw()); + Vector3 transformedLightCenter(savedLightCenter); // map current light center into RenderNode's coordinate space - layerNode->getSkiaLayer()->inverseTransformInWindow.mapPoint3d(mLightCenter); + layerNode->getSkiaLayer()->inverseTransformInWindow.mapPoint3d(transformedLightCenter); + LightingInfo::setLightCenterRaw(transformedLightCenter); const RenderProperties& properties = layerNode->properties(); const SkRect bounds = SkRect::MakeWH(properties.getWidth(), properties.getHeight()); @@ -136,7 +135,7 @@ void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque) RenderNodeDrawable root(layerNode, layerCanvas, false); root.forceDraw(layerCanvas); layerCanvas->restoreToCount(saveCount); - mLightCenter = savedLightCenter; + LightingInfo::setLightCenterRaw(savedLightCenter); // cache the current context so that we can defer flushing it until // either all the layers have been rendered or the context changes diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.h b/libs/hwui/pipeline/skia/SkiaPipeline.h index 41d864653b67..5fc1d6169d4a 100644 --- a/libs/hwui/pipeline/skia/SkiaPipeline.h +++ b/libs/hwui/pipeline/skia/SkiaPipeline.h @@ -60,49 +60,6 @@ public: void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque); - static float getLightRadius() { - if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) { - return Properties::overrideLightRadius; - } - return mLightRadius; - } - - static uint8_t getAmbientShadowAlpha() { - if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) { - return Properties::overrideAmbientShadowStrength; - } - return mAmbientShadowAlpha; - } - - static uint8_t getSpotShadowAlpha() { - if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) { - return Properties::overrideSpotShadowStrength; - } - return mSpotShadowAlpha; - } - - static Vector3 getLightCenter() { - if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) { - Vector3 adjustedLightCenter = mLightCenter; - if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) { - // negated since this shifts up - adjustedLightCenter.y = -Properties::overrideLightPosY; - } - if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) { - adjustedLightCenter.z = Properties::overrideLightPosZ; - } - return adjustedLightCenter; - } - return mLightCenter; - } - - static void updateLighting(const LightGeometry& lightGeometry, const LightInfo& lightInfo) { - mLightRadius = lightGeometry.radius; - mAmbientShadowAlpha = lightInfo.ambientShadowAlpha; - mSpotShadowAlpha = lightInfo.spotShadowAlpha; - mLightCenter = lightGeometry.center; - } - void setPictureCapturedCallback( const std::function<void(sk_sp<SkPicture>&&)>& callback) override { mPictureCapturedCallback = callback; @@ -163,11 +120,6 @@ private: std::unique_ptr<SkPictureRecorder> mRecorder; std::unique_ptr<SkNWayCanvas> mNwayCanvas; std::function<void(sk_sp<SkPicture>&&)> mPictureCapturedCallback; - - static float mLightRadius; - static uint8_t mAmbientShadowAlpha; - static uint8_t mSpotShadowAlpha; - static Vector3 mLightCenter; }; } /* namespace skiapipeline */ diff --git a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp index e8cb219db320..ad7c70614239 100644 --- a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp @@ -19,6 +19,7 @@ #include "DeferredLayerUpdater.h" #include "Readback.h" #include "ShaderCache.h" +#include "LightingInfo.h" #include "SkiaPipeline.h" #include "SkiaProfileRenderer.h" #include "VkInteropFunctorDrawable.h" @@ -69,7 +70,7 @@ bool SkiaVulkanPipeline::draw(const Frame& frame, const SkRect& screenDirty, con if (backBuffer.get() == nullptr) { return false; } - SkiaPipeline::updateLighting(lightGeometry, lightInfo); + LightingInfo::updateLighting(lightGeometry, lightInfo); renderFrame(*layerUpdateQueue, dirty, renderNodes, opaque, contentDrawBounds, backBuffer, mVkSurface->getCurrentPreTransform()); ShaderCache::get().onVkFrameFlushed(mRenderThread.getGrContext()); |