skia2/tests/Skbug12214.cpp
John Stiles f2de1b8b4d 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>
2021-07-16 15:12:43 +00:00

24 lines
873 B
C++

/*
* 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);
}