Skip to content

Commit c7d62b7

Browse files
ChrisCraikAndroid (Google) Code Review
authored andcommitted
Merge "Rework shadow interpolation" into lmp-dev
2 parents b3cca87 + bf75945 commit c7d62b7

File tree

5 files changed

+52
-28
lines changed

5 files changed

+52
-28
lines changed

core/res/res/values/styles.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,8 @@ please see styles_device_defaults.xml.
13591359
<item name="lightY">-200dp</item>
13601360
<item name="lightZ">800dp</item>
13611361
<item name="lightRadius">800dp</item>
1362-
<item name="ambientShadowAlpha">0.0471</item>
1363-
<item name="spotShadowAlpha">0.1765</item>
1362+
<item name="ambientShadowAlpha">0.06</item>
1363+
<item name="spotShadowAlpha">0.22</item>
13641364
</style>
13651365

13661366
</resources>

libs/hwui/OpenGLRenderer.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,8 +1641,9 @@ void OpenGLRenderer::setupDrawNoTexture() {
16411641
mCaches.disableTexCoordsVertexArray();
16421642
}
16431643

1644-
void OpenGLRenderer::setupDrawAA() {
1644+
void OpenGLRenderer::setupDrawAA(bool useShadowInterp) {
16451645
mDescription.isAA = true;
1646+
mDescription.isShadowAA = useShadowInterp;
16461647
}
16471648

16481649
void OpenGLRenderer::setupDrawColor(int color, int alpha) {
@@ -2365,7 +2366,7 @@ status_t OpenGLRenderer::drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry*
23652366
}
23662367

23672368
status_t OpenGLRenderer::drawVertexBuffer(float translateX, float translateY,
2368-
const VertexBuffer& vertexBuffer, const SkPaint* paint, bool useOffset) {
2369+
const VertexBuffer& vertexBuffer, const SkPaint* paint, int displayFlags) {
23692370
// not missing call to quickReject/dirtyLayer, always done at a higher level
23702371
if (!vertexBuffer.getVertexCount()) {
23712372
// no vertices to draw
@@ -2381,13 +2382,14 @@ status_t OpenGLRenderer::drawVertexBuffer(float translateX, float translateY,
23812382

23822383
setupDraw();
23832384
setupDrawNoTexture();
2384-
if (isAA) setupDrawAA();
2385+
if (isAA) setupDrawAA((displayFlags & kVertexBuffer_ShadowAA));
23852386
setupDrawColor(color, ((color >> 24) & 0xFF) * mSnapshot->alpha);
23862387
setupDrawColorFilter(getColorFilter(paint));
23872388
setupDrawShader(getShader(paint));
23882389
setupDrawBlending(paint, isAA);
23892390
setupDrawProgram();
2390-
setupDrawModelView(kModelViewMode_Translate, useOffset, translateX, translateY, 0, 0);
2391+
setupDrawModelView(kModelViewMode_Translate, (displayFlags & kVertexBuffer_Offset),
2392+
translateX, translateY, 0, 0);
23912393
setupDrawColorUniforms(getShader(paint));
23922394
setupDrawColorFilterUniforms(getColorFilter(paint));
23932395
setupDrawShaderUniforms(getShader(paint));
@@ -2397,7 +2399,6 @@ status_t OpenGLRenderer::drawVertexBuffer(float translateX, float translateY,
23972399
mCaches.bindPositionVertexPointer(true, vertices, isAA ? gAlphaVertexStride : gVertexStride);
23982400
mCaches.resetTexCoordsVertexPointer();
23992401

2400-
24012402
int alphaSlot = -1;
24022403
if (isAA) {
24032404
void* alphaCoords = ((GLbyte*) vertices) + gVertexAlphaOffset;
@@ -2466,8 +2467,8 @@ status_t OpenGLRenderer::drawLines(const float* points, int count, const SkPaint
24662467
return DrawGlInfo::kStatusDone;
24672468
}
24682469

2469-
bool useOffset = !paint->isAntiAlias();
2470-
return drawVertexBuffer(buffer, paint, useOffset);
2470+
int displayFlags = paint->isAntiAlias() ? 0 : kVertexBuffer_Offset;
2471+
return drawVertexBuffer(buffer, paint, displayFlags);
24712472
}
24722473

24732474
status_t OpenGLRenderer::drawPoints(const float* points, int count, const SkPaint* paint) {
@@ -2483,8 +2484,8 @@ status_t OpenGLRenderer::drawPoints(const float* points, int count, const SkPain
24832484
return DrawGlInfo::kStatusDone;
24842485
}
24852486

2486-
bool useOffset = !paint->isAntiAlias();
2487-
return drawVertexBuffer(buffer, paint, useOffset);
2487+
int displayFlags = paint->isAntiAlias() ? 0 : kVertexBuffer_Offset;
2488+
return drawVertexBuffer(buffer, paint, displayFlags);
24882489
}
24892490

24902491
status_t OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
@@ -3167,12 +3168,12 @@ status_t OpenGLRenderer::drawShadow(float casterAlpha,
31673168

31683169
if (ambientShadowVertexBuffer && mAmbientShadowAlpha > 0) {
31693170
paint.setARGB(casterAlpha * mAmbientShadowAlpha, 0, 0, 0);
3170-
drawVertexBuffer(*ambientShadowVertexBuffer, &paint);
3171+
drawVertexBuffer(*ambientShadowVertexBuffer, &paint, kVertexBuffer_ShadowAA);
31713172
}
31723173

31733174
if (spotShadowVertexBuffer && mSpotShadowAlpha > 0) {
31743175
paint.setARGB(casterAlpha * mSpotShadowAlpha, 0, 0, 0);
3175-
drawVertexBuffer(*spotShadowVertexBuffer, &paint);
3176+
drawVertexBuffer(*spotShadowVertexBuffer, &paint, kVertexBuffer_ShadowAA);
31763177
}
31773178

31783179
return DrawGlInfo::kStatusDrew;

libs/hwui/OpenGLRenderer.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ enum ClipSideFlags {
9494
kClipSide_ConservativeFull = 0x1F
9595
};
9696

97+
enum VertexBufferDisplayFlags {
98+
kVertexBuffer_Offset = 0x1,
99+
kVertexBuffer_ShadowAA = 0x2,
100+
};
101+
97102
/**
98103
* Defines additional transformation that should be applied by the model view matrix, beyond that of
99104
* the currentTransform()
@@ -656,17 +661,17 @@ class OpenGLRenderer : public StatefulBaseRenderer {
656661
*
657662
* @param vertexBuffer The VertexBuffer to be drawn
658663
* @param paint The paint to render with
659-
* @param useOffset Offset the vertexBuffer (used in drawing non-AA lines)
664+
* @param flags flags with which to draw
660665
*/
661666
status_t drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer,
662-
const SkPaint* paint, bool useOffset = false);
667+
const SkPaint* paint, int flags = 0);
663668

664669
/**
665670
* Convenience for translating method
666671
*/
667672
status_t drawVertexBuffer(const VertexBuffer& vertexBuffer,
668-
const SkPaint* paint, bool useOffset = false) {
669-
return drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, useOffset);
673+
const SkPaint* paint, int flags = 0) {
674+
return drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags);
670675
}
671676

672677
/**
@@ -842,7 +847,7 @@ class OpenGLRenderer : public StatefulBaseRenderer {
842847
void setupDrawWithTextureAndColor(bool isAlpha8 = false);
843848
void setupDrawWithExternalTexture();
844849
void setupDrawNoTexture();
845-
void setupDrawAA();
850+
void setupDrawAA(bool useShadowInterp);
846851
void setupDrawColor(int color, int alpha);
847852
void setupDrawColor(float r, float g, float b, float a);
848853
void setupDrawAlpha8Color(int color, int alpha);

libs/hwui/Program.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,20 @@ namespace uirenderer {
7272
#define PROGRAM_MODULATE_SHIFT 35
7373

7474
#define PROGRAM_HAS_AA_SHIFT 36
75+
#define PROGRAM_HAS_SHADOW_AA_SHIFT 37
7576

76-
#define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 37
77-
#define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 38
77+
#define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 38
78+
#define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 39
7879

79-
#define PROGRAM_HAS_GAMMA_CORRECTION 39
80+
#define PROGRAM_HAS_GAMMA_CORRECTION 40
8081

81-
#define PROGRAM_IS_SIMPLE_GRADIENT 40
82+
#define PROGRAM_IS_SIMPLE_GRADIENT 41
8283

83-
#define PROGRAM_HAS_COLORS 41
84+
#define PROGRAM_HAS_COLORS 42
8485

85-
#define PROGRAM_HAS_DEBUG_HIGHLIGHT 42
86-
#define PROGRAM_EMULATE_STENCIL 43
87-
#define PROGRAM_HAS_ROUND_RECT_CLIP 44
86+
#define PROGRAM_HAS_DEBUG_HIGHLIGHT 43
87+
#define PROGRAM_EMULATE_STENCIL 44
88+
#define PROGRAM_HAS_ROUND_RECT_CLIP 45
8889

8990
///////////////////////////////////////////////////////////////////////////////
9091
// Types
@@ -135,6 +136,7 @@ struct ProgramDescription {
135136
bool isBitmapNpot;
136137

137138
bool isAA; // drawing with a per-vertex alpha
139+
bool isShadowAA; // drawing per vertex alpha with shadow interpolation
138140

139141
bool hasGradient;
140142
Gradient gradientType;
@@ -175,6 +177,7 @@ struct ProgramDescription {
175177
hasColors = false;
176178

177179
isAA = false;
180+
isShadowAA = false;
178181

179182
modulate = false;
180183

@@ -262,6 +265,7 @@ struct ProgramDescription {
262265
if (swapSrcDst) key |= PROGRAM_KEY_SWAP_SRC_DST;
263266
if (modulate) key |= programid(0x1) << PROGRAM_MODULATE_SHIFT;
264267
if (isAA) key |= programid(0x1) << PROGRAM_HAS_AA_SHIFT;
268+
if (isShadowAA) key |= programid(0x1) << PROGRAM_HAS_SHADOW_AA_SHIFT;
265269
if (hasExternalTexture) key |= programid(0x1) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT;
266270
if (hasTextureTransform) key |= programid(0x1) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT;
267271
if (hasGammaCorrection) key |= programid(0x1) << PROGRAM_HAS_GAMMA_CORRECTION;

libs/hwui/ProgramCache.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ const char* gVS_Main_OutBitmapTexCoords =
121121
const char* gVS_Main_Position =
122122
" vec4 transformedPosition = projection * transform * position;\n"
123123
" gl_Position = transformedPosition;\n";
124+
125+
const char* gVS_Main_ShadowAAVertexShape =
126+
" alpha = pow(vtxAlpha, 0.667);\n";
124127
const char* gVS_Main_AAVertexShape =
125128
" alpha = vtxAlpha;\n";
129+
126130
const char* gVS_Main_HasRoundRectClip =
127131
" roundRectPos = (roundRectInvTransform * transformedPosition).xy;\n";
128132
const char* gVS_Footer =
@@ -237,6 +241,8 @@ const char* gFS_Main_ModulateColor =
237241
" fragColor *= color.a;\n";
238242
const char* gFS_Main_AccountForAAVertexShape =
239243
" fragColor *= alpha;\n";
244+
const char* gFS_Main_AccountForShadowAAVertexShape =
245+
" fragColor *= pow(alpha, 1.5);\n";
240246

241247
const char* gFS_Main_FetchTexture[2] = {
242248
// Don't modulate
@@ -515,7 +521,11 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description
515521
shader.append(gVS_Main_OutTexCoords);
516522
}
517523
if (description.isAA) {
518-
shader.append(gVS_Main_AAVertexShape);
524+
if (description.isShadowAA) {
525+
shader.append(gVS_Main_ShadowAAVertexShape);
526+
} else {
527+
shader.append(gVS_Main_AAVertexShape);
528+
}
519529
}
520530
if (description.hasColors) {
521531
shader.append(gVS_Main_OutColors);
@@ -750,7 +760,11 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti
750760
shader.append(gFS_Main_ApplyColorOp[description.colorOp]);
751761

752762
if (description.isAA) {
753-
shader.append(gFS_Main_AccountForAAVertexShape);
763+
if (description.isShadowAA) {
764+
shader.append(gFS_Main_AccountForShadowAAVertexShape);
765+
} else {
766+
shader.append(gFS_Main_AccountForAAVertexShape);
767+
}
754768
}
755769

756770
// Output the fragment

0 commit comments

Comments
 (0)