Fix crash when drawing a GPU-backed surface onto raster.
We now null-check the result of recordingContext() before using it. Thanks cqjjjzr2@gmail.com for the initial discovery and suggested fix. Change-Id: Iafcf306f8cd9deb7147ef9c5c71a21907eedc01f Bug: skia:12214 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/429098 Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
b18c1e2c27
commit
f2de1b8b4d
@ -271,6 +271,7 @@ tests_sources = [
|
||||
"$_tests/SkUTFTest.cpp",
|
||||
"$_tests/SkVMTest.cpp",
|
||||
"$_tests/SkVxTest.cpp",
|
||||
"$_tests/Skbug12214.cpp",
|
||||
"$_tests/Skbug5221.cpp",
|
||||
"$_tests/Skbug6389.cpp",
|
||||
"$_tests/Skbug6653.cpp",
|
||||
|
@ -275,7 +275,7 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
|
||||
// onDraw) since that may not always perform the copy-on-write optimization.
|
||||
auto tryDraw = [&] {
|
||||
auto surfaceContext = fDevice->recordingContext();
|
||||
auto canvasContext = canvas->recordingContext()->asDirectContext();
|
||||
auto canvasContext = GrAsDirectContext(canvas->recordingContext());
|
||||
if (!canvasContext) {
|
||||
return false;
|
||||
}
|
||||
|
23
tests/Skbug12214.cpp
Normal file
23
tests/Skbug12214.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2021 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "tests/Test.h"
|
||||
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
|
||||
DEF_GPUTEST_FOR_ALL_CONTEXTS(skbug12214, r, contextInfo) {
|
||||
auto imageInfo = SkImageInfo::Make(/*width=*/32, /*height=*/32, kRGBA_8888_SkColorType,
|
||||
kPremul_SkAlphaType);
|
||||
sk_sp<SkSurface> surface1 = SkSurface::MakeRenderTarget(contextInfo.directContext(),
|
||||
SkBudgeted::kNo, imageInfo);
|
||||
sk_sp<SkSurface> surface2 = SkSurface::MakeRaster(imageInfo);
|
||||
|
||||
// The test succeeds if this draw does not crash. (See skia:12214)
|
||||
surface1->draw(surface2->getCanvas(), /*x=*/0, /*y=*/0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user