diff options
| author | 2019-11-15 10:24:08 -0800 | |
|---|---|---|
| committer | 2019-11-18 14:56:36 -0800 | |
| commit | b13bb952a8a529dccd54ac0f72073fe5676e3a7e (patch) | |
| tree | dc880e9030243ef8d95bc6d4118ac652c6672adc | |
| parent | 99bd5ce9b76c71b7be7f966c90de97124804f513 (diff) | |
[Shadows] Add api to set global shadow settings (4/n)
Bug: 136561771
Test: go/wm-smoke
Change-Id: Icdb9e2f2b79ac5d461a9a2a323792962da3d3e26
| -rw-r--r-- | libs/gui/ISurfaceComposer.cpp | 48 | ||||
| -rw-r--r-- | libs/gui/SurfaceComposerClient.cpp | 8 | ||||
| -rw-r--r-- | libs/gui/include/gui/ISurfaceComposer.h | 25 | ||||
| -rw-r--r-- | libs/gui/include/gui/SurfaceComposerClient.h | 21 | ||||
| -rw-r--r-- | libs/gui/tests/Surface_test.cpp | 6 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 9 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 3 |
7 files changed, 118 insertions, 2 deletions
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 580579759f..b9597db882 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -978,6 +978,35 @@ public: } return NO_ERROR; } + + virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, + float lightPosY, float lightPosZ, float lightRadius) { + Parcel data, reply; + status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); + if (error != NO_ERROR) { + ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error); + return error; + } + + std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b, + ambientColor.a, spotColor.r, spotColor.g, + spotColor.b, spotColor.a, lightPosY, + lightPosZ, lightRadius}; + + error = data.writeFloatVector(shadowConfig); + if (error != NO_ERROR) { + ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error); + return error; + } + + error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply, + IBinder::FLAG_ONEWAY); + if (error != NO_ERROR) { + ALOGE("setGlobalShadowSettings: failed to transact: %d", error); + return error; + } + return NO_ERROR; + } }; // Out-of-line virtual method definition to trigger vtable emission in this @@ -1593,6 +1622,25 @@ status_t BnSurfaceComposer::onTransact( } return notifyPowerHint(hintId); } + case SET_GLOBAL_SHADOW_SETTINGS: { + CHECK_INTERFACE(ISurfaceComposer, data, reply); + + std::vector<float> shadowConfig; + status_t error = data.readFloatVector(&shadowConfig); + if (error != NO_ERROR || shadowConfig.size() != 11) { + ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error); + return error; + } + + half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2], + shadowConfig[3]}; + half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]}; + float lightPosY = shadowConfig[8]; + float lightPosZ = shadowConfig[9]; + float lightRadius = shadowConfig[10]; + return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ, + lightRadius); + } default: { return BBinder::onTransact(code, data, reply, flags); } diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index a538e14dfc..2ab4d8ae8a 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1726,6 +1726,14 @@ status_t SurfaceComposerClient::notifyPowerHint(int32_t hintId) { return ComposerService::getComposerService()->notifyPowerHint(hintId); } +status_t SurfaceComposerClient::setGlobalShadowSettings(const half4& ambientColor, + const half4& spotColor, float lightPosY, + float lightPosZ, float lightRadius) { + return ComposerService::getComposerService()->setGlobalShadowSettings(ambientColor, spotColor, + lightPosY, lightPosZ, + lightRadius); +} + // ---------------------------------------------------------------------------- status_t ScreenshotClient::capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace, diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index f2bae98be2..514dfe2d82 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -25,6 +25,8 @@ #include <gui/ITransactionCompletedListener.h> +#include <math/vec4.h> + #include <ui/ConfigStoreTypes.h> #include <ui/DisplayedFrameStats.h> #include <ui/FrameStats.h> @@ -439,6 +441,28 @@ public: * Returns NO_ERROR upon success. */ virtual status_t notifyPowerHint(int32_t hintId) = 0; + + /* + * Sets the global configuration for all the shadows drawn by SurfaceFlinger. Shadow follows + * material design guidelines. + * + * ambientColor + * Color to the ambient shadow. The alpha is premultiplied. + * + * spotColor + * Color to the spot shadow. The alpha is premultiplied. The position of the spot shadow + * depends on the light position. + * + * lightPosY/lightPosZ + * Position of the light used to cast the spot shadow. The X value is always the display + * width / 2. + * + * lightRadius + * Radius of the light casting the shadow. + */ + virtual status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, + float lightPosY, float lightPosZ, + float lightRadius) = 0; }; // ---------------------------------------------------------------------------- @@ -492,6 +516,7 @@ public: SET_DISPLAY_BRIGHTNESS, CAPTURE_SCREEN_BY_ID, NOTIFY_POWER_HINT, + SET_GLOBAL_SHADOW_SETTINGS, // Always append new enum to the end. }; diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index 37387acfc6..d2183565c4 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -214,6 +214,27 @@ public: */ static status_t notifyPowerHint(int32_t hintId); + /* + * Sets the global configuration for all the shadows drawn by SurfaceFlinger. Shadow follows + * material design guidelines. + * + * ambientColor + * Color to the ambient shadow. The alpha is premultiplied. + * + * spotColor + * Color to the spot shadow. The alpha is premultiplied. The position of the spot shadow + * depends on the light position. + * + * lightPosY/lightPosZ + * Position of the light used to cast the spot shadow. The X value is always the display + * width / 2. + * + * lightRadius + * Radius of the light casting the shadow. + */ + static status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, + float lightPosY, float lightPosZ, float lightRadius); + // ------------------------------------------------------------------------ // surface creation / destruction diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index a4fdb35595..c4f35ae1c1 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -833,6 +833,12 @@ public: } status_t notifyPowerHint(int32_t /*hintId*/) override { return NO_ERROR; } + status_t setGlobalShadowSettings(const half4& /*ambientColor*/, const half4& /*spotColor*/, + float /*lightPosY*/, float /*lightPosZ*/, + float /*lightRadius*/) override { + return NO_ERROR; + } + protected: IBinder* onAsBinder() override { return nullptr; } diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index ec15bad456..2fbef0b59a 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -4384,7 +4384,8 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES: case SET_DISPLAY_CONTENT_SAMPLING_ENABLED: case GET_DISPLAYED_CONTENT_SAMPLE: - case NOTIFY_POWER_HINT: { + case NOTIFY_POWER_HINT: + case SET_GLOBAL_SHADOW_SETTINGS: { if (!callingThreadHasUnscopedSurfaceFlingerAccess()) { IPCThreadState* ipc = IPCThreadState::self(); ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", @@ -5501,6 +5502,12 @@ void SurfaceFlinger::bufferErased(const client_cache_t& clientCacheId) { getRenderEngine().unbindExternalTextureBuffer(clientCacheId.id); } +status_t SurfaceFlinger::setGlobalShadowSettings(const half4& /*ambientColor*/, + const half4& /*spotColor*/, float /*lightPosY*/, + float /*lightPosZ*/, float /*lightRadius*/) { + return NO_ERROR; +} + } // namespace android #if defined(__gl_h_) diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 50b3ae4ecd..1857838a80 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -470,7 +470,8 @@ private: bool* outSupport) const override; status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) const override; status_t notifyPowerHint(int32_t hintId) override; - + status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, + float lightPosY, float lightPosZ, float lightRadius) override; /* ------------------------------------------------------------------------ * DeathRecipient interface */ |