Skip to content

Commit

Permalink
Restore old SurfaceTextureExternal drawing code (flutter#44979)
Browse files Browse the repository at this point in the history
The simpler version I committed last week doesn't work correctly when
the texture has been transformed. This CL restores the old painting code
that properly handles this case.

Fixes internal b/296916021
  • Loading branch information
johnmccutchan authored Aug 22, 2023
1 parent 56b1c6d commit c5cf722
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions shell/platform/android/surface_texture_external_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,27 @@ void SurfaceTextureExternalTexture::Paint(PaintContext& context,
FML_CHECK(state_ == AttachmentState::kAttached);

if (dl_image_) {
context.canvas->DrawImageRect(
dl_image_, // image
SkRect::Make(dl_image_->bounds()), // source rect
bounds, // destination rect
sampling, // sampling
context.paint, // paint
flutter::DlCanvas::SrcRectConstraint::kStrict // enforce edges
);
DlAutoCanvasRestore autoRestore(context.canvas, true);

// The incoming texture is vertically flipped, so we flip it
// back. OpenGL's coordinate system has Positive Y equivalent to up, while
// Skia's coordinate system has Negative Y equvalent to up.
context.canvas->Translate(bounds.x(), bounds.y() + bounds.height());
context.canvas->Scale(bounds.width(), -bounds.height());

if (!transform_.isIdentity()) {
DlImageColorSource source(dl_image_, DlTileMode::kRepeat,
DlTileMode::kRepeat, sampling, &transform_);

DlPaint paintWithShader;
if (context.paint) {
paintWithShader = *context.paint;
}
paintWithShader.setColorSource(&source);
context.canvas->DrawRect(SkRect::MakeWH(1, 1), paintWithShader);
} else {
context.canvas->DrawImage(dl_image_, {0, 0}, sampling, context.paint);
}
} else {
FML_LOG(WARNING)
<< "No DlImage available for SurfaceTextureExternalTexture to paint.";
Expand Down

0 comments on commit c5cf722

Please sign in to comment.