From 914e75086755f7be427d2b6a1ed96662a0a7049e Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Mon, 8 Aug 2022 23:58:59 +0000 Subject: Support alpha for SurfaceView Basically, this removes an excuse for apps to use TextureView for video playback or one-off HDR images prior to HDR UI being ready everywhere. The idea is that for Z-above, applying alpha is easy, because the surface just needs to be have alpha modulated. Z-below is a little bit more creative - the alpha is applied to the hole punch and drawn using DST_OUT blending semantics. This allows for views underneath the SurfaceView to blend with surface, while being occluded by views on top of the SurfaceView. There may need to be some complex view hierarchies that would be useful to test, but simple view layouts seem to work. Note that this is guarded with a target SDK check, to defend against applications that are propagated alpha to child views while expecting opaque SurfaceViews. Bug: 241474646 Test: HWAccelerationTest doesn't look broken Change-Id: Ibc14b18f1ce6f25250318db50275c6b8c972bade --- libs/hwui/SkiaCanvas.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libs/hwui/SkiaCanvas.cpp') diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index 023d6bf0b673..20c6d6846fa2 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -18,6 +18,7 @@ #include "CanvasProperty.h" #include "NinePatchUtils.h" +#include "SkBlendMode.h" #include "VectorDrawable.h" #include "hwui/Bitmap.h" #include "hwui/MinikinUtils.h" @@ -251,10 +252,11 @@ const SkiaCanvas::SaveRec* SkiaCanvas::currentSaveRec() const { return (rec && rec->saveCount == currentSaveCount) ? rec : nullptr; } -void SkiaCanvas::punchHole(const SkRRect& rect) { +void SkiaCanvas::punchHole(const SkRRect& rect, float alpha) { SkPaint paint = SkPaint(); - paint.setColor(0); - paint.setBlendMode(SkBlendMode::kClear); + paint.setColor(SkColors::kBlack); + paint.setAlphaf(alpha); + paint.setBlendMode(SkBlendMode::kDstOut); mCanvas->drawRRect(rect, paint); } -- cgit v1.2.3-59-g8ed1b