You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HCPP platform view overlays elements it shouldn't when native view is a SurfaceView #175546
This part of the video is correct behavior though, isn't it? If the video should be under the secondary toolbar (the one for display type), then the point where it's disappearing is when it scrolls exactly enough that it's fully obscured.
This part of the video is correct behavior though, isn't it? If the video should be under the secondary toolbar (the one for display type), then the point where it's disappearing is when it scrolls exactly enough that it's fully obscured.
Ah good point, yes that's probably correct! Updated title to reflect
changed the title [-]HCPP platform view overlays elements it shouldn't, and disappears before fully off screen[/-][+]HCPP platform view overlays elements it shouldn't[/+]on Sep 17, 2025
I've spent quite a while looking in to this - the problem here seems to be that HCPP does not currently respect (at least clipping) mutators when the native view is a SurfaceView (which is what the platform view implementation of video_player uses on Android).
// Copyright 2014 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.@file:Suppress("PackageName")
packagecom.example.android_engine_test.fixturesimportandroid.content.Contextimportandroid.graphics.Colorimportandroid.graphics.Paintimportandroid.view.SurfaceHolderimportandroid.view.SurfaceView// Changed from Viewimportandroid.view.Viewimportandroid.view.ViewGroupimportio.flutter.plugin.platform.PlatformViewimportio.flutter.plugin.platform.PlatformViewFactoryclassChangingColorButtonPlatformViewFactory : PlatformViewFactory(null) {
overridefuncreate(
context: Context,
viewId: Int,
args: Any?
): PlatformView = ChangingColorButtonPlatformView(context)
}
privateclassChangingColorButtonPlatformView(
context: Context
) : SurfaceView(context), // Extend SurfaceViewPlatformView,
SurfaceHolder.Callback { // Implement Callback to listen for surface availabilityprivatevalpaintRed =
Paint().apply {
color = Color.REDstyle = Paint.Style.FILL
}
privatevalpaintBlue =
Paint().apply {
color = Color.BLUEstyle = Paint.Style.FILL
}
privatevarisBlue = falseinit {
layoutParams =
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
contentDescription = "Change color"// Register the callback to know when the surface is createdholder.addCallback(this)
setOnClickListener {
isBlue = !isBluedrawSurface() // Manually trigger the draw routine
}
}
// Helper function to handle SurfaceView drawing mechanicsprivatefundrawSurface() {
// Ensure the surface is valid before trying to drawif (holder.surface.isValid) {
// 1. Lock the canvasvalcanvas = holder.lockCanvas()
// 2. Perform drawingif (canvas != null) {
canvas.drawColor(Color.WHITE) // Clear previous drawing (optional but recommended)canvas.drawRect(
0f,
0f,
width.toFloat(),
height.toFloat(),
if (isBlue) paintBlueelsepaintRed
)
// 3. Unlock and post the canvas to display itholder.unlockCanvasAndPost(canvas)
}
}
}
overridefungetView(): View = thisoverridefundispose() {
// Clean up callbacks to prevent memory leaksholder.removeCallback(this)
}
// --- SurfaceHolder.Callback Implementation ---overridefunsurfaceCreated(holder: SurfaceHolder) {
// The surface is ready, perform the initial drawdrawSurface()
}
overridefunsurfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
// If dimensions change, redraw to fit new boundsdrawSurface()
}
overridefunsurfaceDestroyed(holder: SurfaceHolder) {
// Surface is gone, stop any active rendering threads here if you had them
}
}
We can see that HC mode still clips properly (red is pv, green is content behind pv):
But HCPP does not
This is causing this bad overlay because the mechanism that the engine is using to prevent this overlay in this case is a clip rect, and it's not being respected (determined from logging).
Looks like we can fix this by applying the clip via a transaction in onDisplayPlatformView, extremely roughly:
if (Build.VERSION.SDK_INT >= API_LEVELS.API_29 && viewinstanceofSurfaceView) {
SurfaceViewsurfaceView = (SurfaceView) view;
SurfaceControlsc = surfaceView.getSurfaceControl();
if (sc != null && sc.isValid()) {
SurfaceControl.Transactiontx = newSurfaceControl.Transaction();
// 1. HANDLE OPACITY// Apply the accumulated opacity from the stack to the Surface layer.tx.setAlpha(sc, mutatorsStack.getFinalOpacity());
// 2. HANDLE CLIPPING (RECT, RRECT, PATH, TRANSFORM)// We start with the view's final on-screen bounds.RectFscreenRectF = newRectF(x, y, x+width, y+height);
RectscreenRect = newRect();
screenRectF.roundOut(screenRect);
List<Path> clippingPaths = mutatorsStack.getFinalClippingPaths();
if (clippingPaths != null && !clippingPaths.isEmpty()) {
RectFpathBounds = newRectF();
for (Pathpath : clippingPaths) {
// Compute the axis-aligned bounding box of the path.path.computeBounds(pathBounds, true);
// Round out to ensure we cover the pixels (ceil/floor logic).RectpathRectInt = newRect();
pathBounds.roundOut(pathRectInt);
// Intersect the current visible area with this clip.// If the path is a complex shape (star, rounded rect), this// constrains the surface to the bounding box of that shape.screenRect.intersect(pathRectInt);
}
}
// 3. CONVERT TO LOCAL SURFACE COORDINATES// SurfaceControl.setCrop expects coordinates relative to the Surface (0,0).// We shift the calculated screen-space rect by the view's origin (-x, -y).screenRect.offset(-x, -y);
if (screenRect.width() < 0 || screenRect.height() < 0) {
screenRect.setEmpty();
}
// Send the command to SurfaceFlinger.if (Build.VERSION.SDK_INT >= API_LEVELS.API_33) {
tx.setCrop(sc, screenRect);
Log.e("HI GRAY", "final computed screenrect is " + screenRect);
}
// 5. SYNC WITH FRAME// Apply this transaction as part of the ViewRoot's draw cycle to prevent// visual tearing/jitter during scrolling.if (Build.VERSION.SDK_INT >= API_LEVELS.API_33) {
flutterView.getRootSurfaceControl().applyTransactionOnDraw(tx);
}
}
}
Still want to know why the application of FlutterMutatorView.draw() is bypassed when the android view is a SurfaceView, but it certainly seems like that is what is happening here, and that we will need to mirror the application of those graphical modifications somehow. Unfortunately, while direct modification with transactions gives us access to opacity and cliprect, there don't seem to be apis that would apply non rect clipping. Not sure if this is a critical feature that the engine expects to be present outside of use of the specific ClipPath, etc, widgets.
changed the title [-]HCPP platform view overlays elements it shouldn't[/-][+]HCPP platform view overlays elements it shouldn't when native view is a `SurfaceView`[/+]on Mar 18, 2026
Some additional thoughts on the fix here, clipping as applied in my previous comment seems to not work exactly when it happens at the same time as a widget tree change - if, say, you apply a clip rect by adding it as a widget wrapping the platform view.
This is because the view has a null surfacecontrol because it just got deleted and recreated. We can fix this by applying a callback which applies the crop and then schedules a frame:
I think the code above might have an off by one error in the calculation of the rect, because I can see a tiny green line on the right where the widget behind the pv is peeking through
There is a visual flicker when the view gets destroyed and recreated by widget tree changes. This does not happen with HC actually, it does, but maybe it's less somehow? it seems harder to see... I think we are doing something wrong for one frame there, need to figure out what
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
stuartmorgan-g commentedon Sep 17, 2025
This part of the video is correct behavior though, isn't it? If the video should be under the secondary toolbar (the one for display type), then the point where it's disappearing is when it scrolls exactly enough that it's fully obscured.
gmackall commentedon Sep 17, 2025
Ah good point, yes that's probably correct! Updated title to reflect
[-]HCPP platform view overlays elements it shouldn't, and disappears before fully off screen[/-][+]HCPP platform view overlays elements it shouldn't[/+]gmackall commentedon Nov 25, 2025
I've spent quite a while looking in to this - the problem here seems to be that HCPP does not currently respect (at least clipping) mutators when the native view is a
SurfaceView(which is what the platform view implementation ofvideo_playeruses on Android).For example, modifying the native view used by the existing clippath integration test to use a
SurfaceViewCode
We can see that HC mode still clips properly (red is pv, green is content behind pv):

But HCPP does not
This is causing this bad overlay because the mechanism that the engine is using to prevent this overlay in this case is a clip rect, and it's not being respected (determined from logging).
gmackall commentedon Nov 25, 2025
Looks like we can fix this by applying the clip via a transaction in
onDisplayPlatformView, extremely roughly:Still want to know why the application of
FlutterMutatorView.draw()is bypassed when the android view is aSurfaceView, but it certainly seems like that is what is happening here, and that we will need to mirror the application of those graphical modifications somehow. Unfortunately, while direct modification with transactions gives us access to opacity and cliprect, there don't seem to be apis that would apply non rect clipping. Not sure if this is a critical feature that the engine expects to be present outside of use of the specificClipPath, etc, widgets.[-]HCPP platform view overlays elements it shouldn't[/-][+]HCPP platform view overlays elements it shouldn't when native view is a `SurfaceView`[/+]gmackall commentedon Apr 1, 2026
Some additional thoughts on the fix here, clipping as applied in my previous comment seems to not work exactly when it happens at the same time as a widget tree change - if, say, you apply a clip rect by adding it as a widget wrapping the platform view.
This is because the view has a null surfacecontrol because it just got deleted and recreated. We can fix this by applying a callback which applies the crop and then schedules a frame:
Some more thoughts from working on the repro:
This does not happen with HCactually, it does, but maybe it's less somehow? it seems harder to see... I think we are doing something wrong for one frame there, need to figure out whatApply rect clipping to surface views (#184471)
Apply rect clipping to surface views (flutter#184471)
github-actions commentedon Apr 20, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.Apply rect clipping to surface views (#184471)