Skip to content

Commit 631b370

Browse files
cairno-googleAndroid (Google) Code Review
authored andcommitted
Merge "Add border API to surface control" into main
2 parents e511fd4 + 65fb1c6 commit 631b370

31 files changed

+441
-13
lines changed

libs/gui/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ filegroup {
9393
"android/gui/StalledTransactionInfo.aidl",
9494
"android/**/TouchOcclusionMode.aidl",
9595
"android/gui/TrustedOverlay.aidl",
96+
"android/gui/BorderSettings.aidl",
9697
],
9798
}
9899

libs/gui/LayerState.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ status_t layer_state_t::write(Parcel& output) const
180180
SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
181181
}
182182
SAFE_PARCEL(output.writeFloat, shadowRadius);
183+
SAFE_PARCEL(output.writeParcelable, borderSettings);
183184
SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
184185
SAFE_PARCEL(output.writeFloat, frameRate);
185186
SAFE_PARCEL(output.writeByte, frameRateCompatibility);
@@ -328,6 +329,8 @@ status_t layer_state_t::read(const Parcel& input)
328329
listeners.emplace_back(listener, callbackIds);
329330
}
330331
SAFE_PARCEL(input.readFloat, &shadowRadius);
332+
SAFE_PARCEL(input.readParcelable, &borderSettings);
333+
331334
SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
332335
SAFE_PARCEL(input.readFloat, &frameRate);
333336
SAFE_PARCEL(input.readByte, &frameRateCompatibility);
@@ -727,6 +730,10 @@ void layer_state_t::merge(const layer_state_t& other) {
727730
what |= eShadowRadiusChanged;
728731
shadowRadius = other.shadowRadius;
729732
}
733+
if (other.what & eBorderSettingsChanged) {
734+
what |= eBorderSettingsChanged;
735+
borderSettings = other.borderSettings;
736+
}
730737
if (other.what & eLutsChanged) {
731738
what |= eLutsChanged;
732739
luts = other.luts;
@@ -881,6 +888,7 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const {
881888
CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
882889
if (other.what & eMetadataChanged) diff |= eMetadataChanged;
883890
CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
891+
CHECK_DIFF(diff, eBorderSettingsChanged, other, borderSettings);
884892
CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
885893
CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
886894
CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,

libs/gui/SurfaceComposerClient.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,19 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setShado
20252025
return *this;
20262026
}
20272027

2028+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBorderSettings(
2029+
const sp<SurfaceControl>& sc, gui::BorderSettings settings) {
2030+
layer_state_t* s = getLayerState(sc);
2031+
if (!s) {
2032+
mStatus = BAD_INDEX;
2033+
return *this;
2034+
}
2035+
2036+
s->what |= layer_state_t::eBorderSettingsChanged;
2037+
s->borderSettings = settings;
2038+
return *this;
2039+
}
2040+
20282041
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrameRate(
20292042
const sp<SurfaceControl>& sc, float frameRate, int8_t compatibility,
20302043
int8_t changeFrameRateStrategy) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2025, 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+
package android.gui;
18+
19+
/** @hide */
20+
parcelable BorderSettings {
21+
float strokeWidth;
22+
// Space is sRGB, not premultiplied, bit pattern is 0xAARRGGBB.
23+
int color;
24+
}

libs/gui/include/gui/LayerState.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sys/types.h>
2222
#include <span>
2323

24+
#include <android/gui/BorderSettings.h>
2425
#include <android/gui/DisplayCaptureArgs.h>
2526
#include <android/gui/IWindowInfosReportedListener.h>
2627
#include <android/gui/LayerCaptureArgs.h>
@@ -250,6 +251,7 @@ struct layer_state_t {
250251
ePictureProfileHandleChanged = 0x80000'00000000,
251252
eAppContentPriorityChanged = 0x100000'00000000,
252253
eClientDrawnCornerRadiusChanged = 0x200000'00000000,
254+
eBorderSettingsChanged = 0x400000'00000000,
253255
};
254256

255257
layer_state_t();
@@ -293,8 +295,8 @@ struct layer_state_t {
293295
layer_state_t::eColorSpaceAgnosticChanged | layer_state_t::eColorTransformChanged |
294296
layer_state_t::eCornerRadiusChanged | layer_state_t::eDimmingEnabledChanged |
295297
layer_state_t::eHdrMetadataChanged | layer_state_t::eShadowRadiusChanged |
296-
layer_state_t::eStretchChanged |
297-
layer_state_t::ePictureProfileHandleChanged | layer_state_t::eAppContentPriorityChanged;
298+
layer_state_t::eStretchChanged | layer_state_t::ePictureProfileHandleChanged |
299+
layer_state_t::eAppContentPriorityChanged | layer_state_t::eBorderSettingsChanged;
298300

299301
// Changes which invalidates the layer's visible region in CE.
300302
static constexpr uint64_t CONTENT_DIRTY = layer_state_t::CONTENT_CHANGES |
@@ -322,7 +324,8 @@ struct layer_state_t {
322324
// Changes that force GPU composition.
323325
static constexpr uint64_t COMPOSITION_EFFECTS = layer_state_t::eBackgroundBlurRadiusChanged |
324326
layer_state_t::eBlurRegionsChanged | layer_state_t::eCornerRadiusChanged |
325-
layer_state_t::eShadowRadiusChanged | layer_state_t::eStretchChanged;
327+
layer_state_t::eShadowRadiusChanged | layer_state_t::eStretchChanged |
328+
layer_state_t::eBorderSettingsChanged;
326329

327330
bool hasValidBuffer() const;
328331
void sanitize(int32_t permissions);
@@ -411,6 +414,9 @@ struct layer_state_t {
411414
// Draws a shadow around the surface.
412415
float shadowRadius;
413416

417+
// Draws an outline around the layer.
418+
gui::BorderSettings borderSettings;
419+
414420
// Priority of the layer assigned by Window Manager.
415421
int32_t frameRateSelectionPriority;
416422

libs/gui/include/gui/SurfaceComposerClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,8 @@ class SurfaceComposerClient : public RefBase
679679
const Rect& source, const Rect& dst, int transform);
680680
Transaction& setShadowRadius(const sp<SurfaceControl>& sc, float cornerRadius);
681681

682+
Transaction& setBorderSettings(const sp<SurfaceControl>& sc, gui::BorderSettings settings);
683+
682684
Transaction& setFrameRate(const sp<SurfaceControl>& sc, float frameRate,
683685
int8_t compatibility, int8_t changeFrameRateStrategy);
684686

libs/renderengine/Android.bp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ cc_defaults {
5252
"libtonemap",
5353
"libsurfaceflinger_common",
5454
"libsurfaceflingerflags",
55+
"libgui_window_info_static",
5556
],
5657
local_include_dirs: ["include"],
5758
export_include_dirs: ["include"],
@@ -122,7 +123,13 @@ cc_defaults {
122123
"skia_renderengine_deps",
123124
"libsurfaceflinger_common_deps",
124125
],
125-
static_libs: ["libskia_renderengine"],
126+
static_libs: [
127+
"libgui_window_info_static",
128+
"libskia_renderengine",
129+
],
130+
shared_libs: [
131+
"libbinder",
132+
],
126133
}
127134

128135
// Note: if compilation fails when adding librenderengine as a dependency, try adding

libs/renderengine/include/renderengine/LayerSettings.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include <android/gui/BorderSettings.h>
1920
#include <gui/DisplayLuts.h>
2021
#include <math/mat4.h>
2122
#include <math/vec3.h>
@@ -71,6 +72,10 @@ struct Geometry {
7172
// Boundaries of the layer.
7273
FloatRect boundaries = FloatRect();
7374

75+
// Boundaries of the layer before transparent region hint is subtracted.
76+
// Effects like shadows and outline ignore the transparent region hint.
77+
FloatRect originalBounds = FloatRect();
78+
7479
// Transform matrix to apply to mesh coordinates.
7580
mat4 positionTransform = mat4();
7681

@@ -127,6 +132,8 @@ struct LayerSettings {
127132

128133
ShadowSettings shadow;
129134

135+
gui::BorderSettings borderSettings;
136+
130137
int backgroundBlurRadius = 0;
131138

132139
std::vector<BlurRegion> blurRegions;

libs/renderengine/skia/SkiaRenderEngine.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,30 @@ void SkiaRenderEngine::drawLayersInternal(
986986
drawShadow(canvas, rrect, layer.shadow);
987987
}
988988

989+
// Similar to shadows, do the rendering before the clip is applied because even when the
990+
// layer is occluded it should have an outline.
991+
if (layer.borderSettings.strokeWidth > 0) {
992+
// TODO(b/367464660): Move this code to the parent scope and
993+
// update shadow rendering above to use these bounds since they should be
994+
// identical.
995+
SkRRect originalBounds, originalClip;
996+
std::tie(originalBounds, originalClip) =
997+
getBoundsAndClip(layer.geometry.boundaries, layer.geometry.roundedCornersCrop,
998+
layer.geometry.roundedCornersRadius);
999+
const SkRRect& preferredOriginalBounds =
1000+
originalBounds.isRect() && !originalClip.isEmpty() ? originalClip
1001+
: originalBounds;
1002+
1003+
SkRRect outlineRect = preferredOriginalBounds;
1004+
outlineRect.outset(layer.borderSettings.strokeWidth, layer.borderSettings.strokeWidth);
1005+
1006+
SkPaint paint;
1007+
paint.setAntiAlias(true);
1008+
paint.setColor(layer.borderSettings.color);
1009+
paint.setStyle(SkPaint::kFill_Style);
1010+
canvas->drawDRRect(outlineRect, preferredOriginalBounds, paint);
1011+
}
1012+
9891013
const float layerDimmingRatio = layer.whitePointNits <= 0.f
9901014
? displayDimmingRatio
9911015
: (layer.whitePointNits / maxLayerWhitePoint) * displayDimmingRatio;

services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <cstdint>
2020

21+
#include <android/gui/BorderSettings.h>
2122
#include <android/gui/CachingHint.h>
2223
#include <gui/DisplayLuts.h>
2324
#include <gui/HdrMetadata.h>
@@ -141,6 +142,9 @@ struct LayerFECompositionState {
141142

142143
ShadowSettings shadowSettings;
143144

145+
// The settings to configure the outline of a layer.
146+
gui::BorderSettings borderSettings;
147+
144148
// List of regions that require blur
145149
std::vector<BlurRegion> blurRegions;
146150

0 commit comments

Comments
 (0)