2013-03-28 13:49:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-01-10 22:08:27 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkOverdrawCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-05-24 14:16:35 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
2020-12-23 14:16:59 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkDevice.h"
|
|
|
|
#include "src/core/SkUtils.h"
|
2021-07-06 16:21:37 +00:00
|
|
|
#include "src/gpu/BaseDevice.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/gpu/GrGpuResourcePriv.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.h"
|
2020-05-26 21:00:32 +00:00
|
|
|
#include "src/gpu/GrRenderTarget.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
2021-08-04 17:27:43 +00:00
|
|
|
#include "src/gpu/SurfaceFillContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/image/SkImage_Base.h"
|
|
|
|
#include "src/image/SkImage_Gpu.h"
|
|
|
|
#include "src/image/SkSurface_Gpu.h"
|
|
|
|
#include "tests/Test.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2020-10-06 14:07:38 +00:00
|
|
|
#include "tools/gpu/BackendSurfaceFactory.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2013-03-28 13:49:22 +00:00
|
|
|
|
2018-09-19 15:31:27 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <vector>
|
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
static void release_direct_surface_storage(void* pixels, void* context) {
|
2014-06-27 13:48:14 +00:00
|
|
|
SkASSERT(pixels == context);
|
|
|
|
sk_free(pixels);
|
|
|
|
}
|
2016-03-24 01:59:25 +00:00
|
|
|
static sk_sp<SkSurface> create_surface(SkAlphaType at = kPremul_SkAlphaType,
|
|
|
|
SkImageInfo* requestedInfo = nullptr) {
|
2015-06-23 21:38:48 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
|
2014-02-13 17:14:46 +00:00
|
|
|
if (requestedInfo) {
|
|
|
|
*requestedInfo = info;
|
|
|
|
}
|
2016-03-24 01:59:25 +00:00
|
|
|
return SkSurface::MakeRaster(info);
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2016-03-24 01:59:25 +00:00
|
|
|
static sk_sp<SkSurface> create_direct_surface(SkAlphaType at = kPremul_SkAlphaType,
|
|
|
|
SkImageInfo* requestedInfo = nullptr) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
|
|
|
|
if (requestedInfo) {
|
|
|
|
*requestedInfo = info;
|
|
|
|
}
|
|
|
|
const size_t rowBytes = info.minRowBytes();
|
2017-10-03 18:47:21 +00:00
|
|
|
void* storage = sk_malloc_throw(info.computeByteSize(rowBytes));
|
2016-03-24 01:59:25 +00:00
|
|
|
return SkSurface::MakeRasterDirectReleaseProc(info, storage, rowBytes,
|
|
|
|
release_direct_surface_storage,
|
|
|
|
storage);
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2020-07-20 19:00:36 +00:00
|
|
|
static sk_sp<SkSurface> create_gpu_surface(GrRecordingContext* rContext,
|
|
|
|
SkAlphaType at = kPremul_SkAlphaType,
|
2016-03-24 01:59:25 +00:00
|
|
|
SkImageInfo* requestedInfo = nullptr) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
|
|
|
|
if (requestedInfo) {
|
|
|
|
*requestedInfo = info;
|
|
|
|
}
|
2020-07-20 19:00:36 +00:00
|
|
|
return SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info);
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2020-07-20 19:00:36 +00:00
|
|
|
static sk_sp<SkSurface> create_gpu_scratch_surface(GrRecordingContext* rContext,
|
2016-03-24 01:59:25 +00:00
|
|
|
SkAlphaType at = kPremul_SkAlphaType,
|
|
|
|
SkImageInfo* requestedInfo = nullptr) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at);
|
|
|
|
if (requestedInfo) {
|
|
|
|
*requestedInfo = info;
|
2013-03-28 13:49:22 +00:00
|
|
|
}
|
2020-07-20 19:00:36 +00:00
|
|
|
return SkSurface::MakeRenderTarget(rContext, SkBudgeted::kYes, info);
|
2013-03-28 13:49:22 +00:00
|
|
|
}
|
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
DEF_TEST(SurfaceEmpty, reporter) {
|
2014-12-31 20:31:43 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
|
2016-03-24 01:59:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info));
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullptr, 0));
|
2014-12-31 20:31:43 +00:00
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
|
|
|
|
REPORTER_ASSERT(reporter, nullptr ==
|
2020-07-06 14:56:46 +00:00
|
|
|
SkSurface::MakeRenderTarget(ctxInfo.directContext(), SkBudgeted::kNo, info));
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2015-06-16 15:07:16 +00:00
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-05-17 14:01:21 +00:00
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
|
|
|
|
static constexpr int kSize = 10;
|
|
|
|
|
|
|
|
SkColorType colorType = static_cast<SkColorType>(ct);
|
|
|
|
auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr);
|
|
|
|
|
2019-09-11 21:03:28 +00:00
|
|
|
{
|
|
|
|
bool can = context->colorTypeSupportedAsSurface(colorType);
|
|
|
|
auto surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 1, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
|
|
|
|
colorType, can, SkToBool(surf));
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
surf = sk_gpu_test::MakeBackendTextureSurface(context,
|
|
|
|
{kSize, kSize},
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
/*sample cnt*/ 1,
|
|
|
|
colorType);
|
2019-09-11 21:03:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
|
|
|
|
colorType, can, SkToBool(surf));
|
2018-02-03 01:32:49 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 21:03:28 +00:00
|
|
|
// The MSAA test only makes sense if the colorType is renderable to begin with.
|
|
|
|
if (context->colorTypeSupportedAsSurface(colorType)) {
|
|
|
|
static constexpr int kSampleCnt = 2;
|
|
|
|
|
|
|
|
bool can = context->maxSurfaceSampleCountForColorType(colorType) >= kSampleCnt;
|
|
|
|
auto surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, kSampleCnt,
|
|
|
|
nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d",
|
|
|
|
colorType, can, SkToBool(surf));
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
surf = sk_gpu_test::MakeBackendTextureSurface(
|
|
|
|
context, {kSize, kSize}, kTopLeft_GrSurfaceOrigin, kSampleCnt, colorType);
|
2019-09-11 21:03:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, can == SkToBool(surf),
|
|
|
|
"colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf),
|
|
|
|
colorType);
|
|
|
|
// Ensure that the sample count stored on the resulting SkSurface is a valid value.
|
|
|
|
if (surf) {
|
2021-06-03 15:58:43 +00:00
|
|
|
auto rtp = SkCanvasPriv::TopDeviceTargetProxy(surf->getCanvas());
|
|
|
|
int storedCnt = rtp->numSamples();
|
|
|
|
const GrBackendFormat& format = rtp->backendFormat();
|
2020-10-13 00:45:06 +00:00
|
|
|
int allowedCnt =
|
|
|
|
context->priv().caps()->getRenderTargetSampleCount(storedCnt, format);
|
2019-09-11 21:03:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
|
|
|
|
"Should store an allowed sample count (%d vs %d)", allowedCnt,
|
|
|
|
storedCnt);
|
|
|
|
}
|
2020-10-06 14:07:38 +00:00
|
|
|
}
|
2019-09-11 21:03:28 +00:00
|
|
|
|
2020-10-06 14:07:38 +00:00
|
|
|
for (int sampleCnt : {1, 2}) {
|
2020-10-08 20:00:14 +00:00
|
|
|
auto surf = sk_gpu_test::MakeBackendRenderTargetSurface(context,
|
|
|
|
{16, 16},
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
sampleCnt,
|
|
|
|
colorType);
|
2020-10-06 14:07:38 +00:00
|
|
|
bool can = context->colorTypeSupportedAsSurface(colorType) &&
|
|
|
|
context->maxSurfaceSampleCountForColorType(colorType) >= sampleCnt;
|
|
|
|
if (!surf && can && colorType == kBGRA_8888_SkColorType && sampleCnt > 1 &&
|
|
|
|
context->backend() == GrBackendApi::kOpenGL) {
|
|
|
|
// This is an execeptional case. On iOS GLES we support MSAA BGRA for internally-
|
|
|
|
// created render targets by using a MSAA RGBA8 renderbuffer that resolves to a
|
|
|
|
// BGRA8 texture. However, the GL_APPLE_texture_format_BGRA8888 extension does not
|
|
|
|
// allow creation of BGRA8 renderbuffers and we don't support multisampled textures.
|
|
|
|
// So this is expected to fail. As of 10/5/2020 it actually seems to work to create
|
|
|
|
// a MSAA BGRA8 renderbuffer (at least in the simulator) but we don't want to rely
|
|
|
|
// on this undocumented behavior.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, sc: %d, can: %d, surf: %d",
|
|
|
|
colorType, sampleCnt, can, SkToBool(surf));
|
2019-09-11 21:03:28 +00:00
|
|
|
if (surf) {
|
2021-06-03 15:58:43 +00:00
|
|
|
auto rtp = SkCanvasPriv::TopDeviceTargetProxy(surf->getCanvas());
|
|
|
|
int storedCnt = rtp->numSamples();
|
|
|
|
const GrBackendFormat& backendFormat = rtp->backendFormat();
|
2020-10-06 14:07:38 +00:00
|
|
|
int allowedCnt = context->priv().caps()->getRenderTargetSampleCount(storedCnt,
|
|
|
|
backendFormat);
|
2019-09-11 21:03:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, storedCnt == allowedCnt,
|
|
|
|
"Should store an allowed sample count (%d vs %d)", allowedCnt,
|
|
|
|
storedCnt);
|
|
|
|
}
|
2018-08-29 16:56:23 +00:00
|
|
|
}
|
2018-02-03 01:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_maxSurfaceSamplesForColorType, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-05-17 14:01:21 +00:00
|
|
|
|
|
|
|
static constexpr int kSize = 10;
|
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
|
|
|
|
|
|
|
|
SkColorType colorType = static_cast<SkColorType>(ct);
|
2020-10-13 00:45:06 +00:00
|
|
|
int maxSampleCnt = context->maxSurfaceSampleCountForColorType(colorType);
|
|
|
|
if (!maxSampleCnt) {
|
2018-02-03 01:32:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-09-11 21:03:28 +00:00
|
|
|
if (!context->colorTypeSupportedAsSurface(colorType)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr);
|
2020-10-13 00:45:06 +00:00
|
|
|
auto surf = sk_gpu_test::MakeBackendTextureSurface(
|
|
|
|
context, info, kTopLeft_GrSurfaceOrigin, maxSampleCnt);
|
2018-02-03 01:32:49 +00:00
|
|
|
if (!surf) {
|
2020-10-13 00:45:06 +00:00
|
|
|
ERRORF(reporter, "Could not make surface of color type %d.", colorType);
|
2018-02-03 01:32:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-24 19:35:08 +00:00
|
|
|
int sampleCnt =
|
|
|
|
((SkSurface_Gpu*)(surf.get()))->getDevice()->targetProxy()->numSamples();
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, sampleCnt == maxSampleCnt, "Exected: %d, actual: %d",
|
|
|
|
maxSampleCnt, sampleCnt);
|
2018-02-03 01:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
static void test_canvas_peek(skiatest::Reporter* reporter,
|
2016-03-24 01:59:25 +00:00
|
|
|
sk_sp<SkSurface>& surface,
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
const SkImageInfo& requestInfo,
|
|
|
|
bool expectPeekSuccess) {
|
2014-02-13 17:14:46 +00:00
|
|
|
const SkColor color = SK_ColorRED;
|
|
|
|
const SkPMColor pmcolor = SkPreMultiplyColor(color);
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
surface->getCanvas()->clear(color);
|
|
|
|
|
2016-03-09 22:26:26 +00:00
|
|
|
SkPixmap pmap;
|
|
|
|
bool success = surface->getCanvas()->peekPixels(&pmap);
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectPeekSuccess == success);
|
|
|
|
|
2016-03-09 22:26:26 +00:00
|
|
|
SkPixmap pmap2;
|
|
|
|
const void* addr2 = surface->peekPixels(&pmap2) ? pmap2.addr() : nullptr;
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
|
|
|
|
if (success) {
|
2016-03-09 22:26:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, requestInfo == pmap.info());
|
|
|
|
REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= pmap.rowBytes());
|
|
|
|
REPORTER_ASSERT(reporter, pmcolor == *pmap.addr32());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
|
2016-03-09 22:26:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, pmap.addr() == pmap2.addr());
|
|
|
|
REPORTER_ASSERT(reporter, pmap.info() == pmap2.info());
|
|
|
|
REPORTER_ASSERT(reporter, pmap.rowBytes() == pmap2.rowBytes());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == addr2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEF_TEST(SurfaceCanvasPeek, reporter) {
|
|
|
|
for (auto& surface_func : { &create_surface, &create_direct_surface }) {
|
|
|
|
SkImageInfo requestInfo;
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(surface_func(kPremul_SkAlphaType, &requestInfo));
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
test_canvas_peek(reporter, surface, requestInfo, true);
|
|
|
|
}
|
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
|
|
|
SkImageInfo requestInfo;
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, &requestInfo));
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
test_canvas_peek(reporter, surface, requestInfo, false);
|
2014-02-13 17:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface,
|
2016-08-17 21:01:05 +00:00
|
|
|
SkAlphaType expectedAlphaType) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, surface);
|
|
|
|
if (surface) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, image);
|
|
|
|
if (image) {
|
2016-08-17 21:01:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->alphaType() == expectedAlphaType);
|
2015-06-09 19:16:53 +00:00
|
|
|
}
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DEF_TEST(SurfaceSnapshotAlphaType, reporter) {
|
|
|
|
for (auto& surface_func : { &create_surface, &create_direct_surface }) {
|
2016-08-17 21:01:05 +00:00
|
|
|
for (auto& at: { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType }) {
|
|
|
|
auto surface(surface_func(at, nullptr));
|
|
|
|
test_snapshot_alphatype(reporter, surface, at);
|
2015-06-09 19:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
2016-08-17 21:01:05 +00:00
|
|
|
// GPU doesn't support creating unpremul surfaces, so only test opaque + premul
|
|
|
|
for (auto& at : { kOpaque_SkAlphaType, kPremul_SkAlphaType }) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), at, nullptr));
|
2016-08-17 21:01:05 +00:00
|
|
|
test_snapshot_alphatype(reporter, surface, at);
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2015-06-23 21:38:48 +00:00
|
|
|
}
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 13:30:38 +00:00
|
|
|
static void test_backend_texture_access_copy_on_write(
|
|
|
|
skiatest::Reporter* reporter, SkSurface* surface, SkSurface::BackendHandleAccess access) {
|
|
|
|
GrBackendTexture tex1 = surface->getBackendTexture(access);
|
|
|
|
sk_sp<SkImage> snap1(surface->makeImageSnapshot());
|
|
|
|
|
|
|
|
GrBackendTexture tex2 = surface->getBackendTexture(access);
|
|
|
|
sk_sp<SkImage> snap2(surface->makeImageSnapshot());
|
|
|
|
|
|
|
|
// If the access mode triggers CoW, then the backend objects should reflect it.
|
|
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(tex1, tex2) == (snap1 == snap2));
|
2015-06-23 21:38:48 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 13:30:38 +00:00
|
|
|
static void test_backend_rendertarget_access_copy_on_write(
|
|
|
|
skiatest::Reporter* reporter, SkSurface* surface, SkSurface::BackendHandleAccess access) {
|
|
|
|
GrBackendRenderTarget rt1 = surface->getBackendRenderTarget(access);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> snap1(surface->makeImageSnapshot());
|
2015-08-06 14:04:51 +00:00
|
|
|
|
2018-04-05 13:30:38 +00:00
|
|
|
GrBackendRenderTarget rt2 = surface->getBackendRenderTarget(access);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> snap2(surface->makeImageSnapshot());
|
2015-08-06 14:04:51 +00:00
|
|
|
|
|
|
|
// If the access mode triggers CoW, then the backend objects should reflect it.
|
2018-04-05 13:30:38 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrBackendRenderTarget::TestingOnly_Equals(rt1, rt2) ==
|
|
|
|
(snap1 == snap2));
|
2015-08-06 14:04:51 +00:00
|
|
|
}
|
2018-04-05 13:30:38 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendSurfaceAccessCopyOnWrite_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
const SkSurface::BackendHandleAccess accessModes[] = {
|
|
|
|
SkSurface::kFlushRead_BackendHandleAccess,
|
|
|
|
SkSurface::kFlushWrite_BackendHandleAccess,
|
|
|
|
SkSurface::kDiscardWrite_BackendHandleAccess,
|
|
|
|
};
|
2018-04-05 13:30:38 +00:00
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
2018-04-05 13:30:38 +00:00
|
|
|
for (auto& accessMode : accessModes) {
|
|
|
|
{
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2018-04-05 13:30:38 +00:00
|
|
|
test_backend_texture_access_copy_on_write(reporter, surface.get(), accessMode);
|
|
|
|
}
|
|
|
|
{
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2018-04-05 13:30:38 +00:00
|
|
|
test_backend_rendertarget_access_copy_on_write(reporter, surface.get(), accessMode);
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-21 14:17:54 +00:00
|
|
|
|
2018-04-05 13:30:38 +00:00
|
|
|
template<typename Type, Type(SkSurface::*func)(SkSurface::BackendHandleAccess)>
|
|
|
|
static void test_backend_unique_id(skiatest::Reporter* reporter, SkSurface* surface) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image0(surface->makeImageSnapshot());
|
2018-04-05 13:30:38 +00:00
|
|
|
|
|
|
|
Type obj = (surface->*func)(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
REPORTER_ASSERT(reporter, obj.isValid());
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image1(surface->makeImageSnapshot());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
// just read access should not affect the snapshot
|
|
|
|
REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID());
|
|
|
|
|
2018-04-05 13:30:38 +00:00
|
|
|
obj = (surface->*func)(SkSurface::kFlushWrite_BackendHandleAccess);
|
|
|
|
REPORTER_ASSERT(reporter, obj.isValid());
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image2(surface->makeImageSnapshot());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
// expect a new image, since we claimed we would write
|
|
|
|
REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID());
|
|
|
|
|
2018-04-05 13:30:38 +00:00
|
|
|
obj = (surface->*func)(SkSurface::kDiscardWrite_BackendHandleAccess);
|
|
|
|
REPORTER_ASSERT(reporter, obj.isValid());
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image3(surface->makeImageSnapshot());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
// expect a new(er) image, since we claimed we would write
|
|
|
|
REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID());
|
|
|
|
REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID());
|
|
|
|
}
|
2018-04-05 13:30:38 +00:00
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
// No CPU test.
|
2016-04-12 16:59:58 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
2018-04-05 13:30:38 +00:00
|
|
|
{
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2018-04-05 13:30:38 +00:00
|
|
|
test_backend_unique_id<GrBackendTexture, &SkSurface::getBackendTexture>(reporter,
|
|
|
|
surface.get());
|
|
|
|
}
|
|
|
|
{
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2018-04-05 13:30:38 +00:00
|
|
|
test_backend_unique_id<GrBackendRenderTarget, &SkSurface::getBackendRenderTarget>(
|
|
|
|
reporter, surface.get());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 17:45:36 +00:00
|
|
|
// No CPU test.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAbandonPostFlush_Gpu, reporter, ctxInfo) {
|
|
|
|
auto direct = ctxInfo.directContext();
|
|
|
|
sk_sp<SkSurface> surface = create_gpu_surface(direct, kPremul_SkAlphaType, nullptr);
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// This flush can put command buffer refs on the GrGpuResource for the surface.
|
|
|
|
surface->flush();
|
|
|
|
direct->abandonContext();
|
|
|
|
// We pass the test if we don't hit any asserts or crashes when the ref on the surface goes away
|
|
|
|
// after we abanonded the context. One thing specifically this checks is to make sure we're
|
|
|
|
// correctly handling the mix of normal refs and command buffer refs, and correctly deleting
|
|
|
|
// the object at the right time.
|
|
|
|
}
|
|
|
|
|
2021-03-10 21:17:21 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendAccessAbandoned_Gpu, reporter, ctxInfo) {
|
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
sk_sp<SkSurface> surface = create_gpu_surface(dContext, kPremul_SkAlphaType, nullptr);
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrBackendRenderTarget beRT =
|
|
|
|
surface->getBackendRenderTarget(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
REPORTER_ASSERT(reporter, beRT.isValid());
|
|
|
|
GrBackendTexture beTex =
|
|
|
|
surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
REPORTER_ASSERT(reporter, beTex.isValid());
|
|
|
|
|
|
|
|
surface->flush();
|
|
|
|
dContext->abandonContext();
|
|
|
|
|
|
|
|
// After abandoning the context none of the backend surfaces should be valid.
|
|
|
|
beRT = surface->getBackendRenderTarget(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
REPORTER_ASSERT(reporter, !beRT.isValid());
|
|
|
|
beTex = surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
REPORTER_ASSERT(reporter, !beTex.isValid());
|
|
|
|
}
|
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
// Verify that the right canvas commands trigger a copy on write.
|
|
|
|
static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface) {
|
2013-03-28 13:49:22 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
|
|
|
const SkRect testRect =
|
|
|
|
SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(4), SkIntToScalar(5));
|
|
|
|
SkPath testPath;
|
|
|
|
testPath.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(2), SkIntToScalar(1)));
|
|
|
|
|
|
|
|
const SkIRect testIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
|
|
|
|
|
|
|
|
SkRegion testRegion;
|
|
|
|
testRegion.setRect(testIRect);
|
|
|
|
|
|
|
|
|
|
|
|
const SkColor testColor = 0x01020304;
|
|
|
|
const SkPaint testPaint;
|
|
|
|
const SkPoint testPoints[3] = {
|
|
|
|
{SkIntToScalar(0), SkIntToScalar(0)},
|
|
|
|
{SkIntToScalar(2), SkIntToScalar(1)},
|
|
|
|
{SkIntToScalar(0), SkIntToScalar(2)}
|
|
|
|
};
|
|
|
|
const size_t testPointCount = 3;
|
|
|
|
|
|
|
|
SkBitmap testBitmap;
|
2014-02-13 14:41:43 +00:00
|
|
|
testBitmap.allocN32Pixels(10, 10);
|
2013-10-09 12:51:09 +00:00
|
|
|
testBitmap.eraseColor(0);
|
2013-03-28 13:49:22 +00:00
|
|
|
|
|
|
|
SkRRect testRRect;
|
|
|
|
testRRect.setRectXY(testRect, SK_Scalar1, SK_Scalar1);
|
|
|
|
|
|
|
|
SkString testText("Hello World");
|
|
|
|
|
|
|
|
#define EXPECT_COPY_ON_WRITE(command) \
|
|
|
|
{ \
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> imageBefore = surface->makeImageSnapshot(); \
|
2020-08-07 21:35:54 +00:00
|
|
|
sk_sp<SkImage> aur_before(imageBefore); /*NOLINT*/ \
|
2013-03-28 13:49:22 +00:00
|
|
|
canvas-> command ; \
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> imageAfter = surface->makeImageSnapshot(); \
|
2020-08-07 21:35:54 +00:00
|
|
|
sk_sp<SkImage> aur_after(imageAfter); /*NOLINT*/ \
|
2013-03-28 13:49:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, imageBefore != imageAfter); \
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_COPY_ON_WRITE(clear(testColor))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawPaint(testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawPoints(SkCanvas::kPoints_PointMode, testPointCount, testPoints, \
|
|
|
|
testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawOval(testRect, testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawRect(testRect, testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawRRect(testRRect, testPaint))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
|
2021-01-25 22:49:32 +00:00
|
|
|
EXPECT_COPY_ON_WRITE(drawImage(testBitmap.asImage(), 0, 0))
|
|
|
|
EXPECT_COPY_ON_WRITE(drawImageRect(testBitmap.asImage(), testRect, SkSamplingOptions()))
|
2019-01-07 14:36:09 +00:00
|
|
|
EXPECT_COPY_ON_WRITE(drawString(testText, 0, 1, SkFont(), testPaint))
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
|
|
|
DEF_TEST(SurfaceCopyOnWrite, reporter) {
|
2016-03-24 01:59:25 +00:00
|
|
|
test_copy_on_write(reporter, create_surface().get());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2016-03-24 01:59:25 +00:00
|
|
|
test_copy_on_write(reporter, surface.get());
|
2015-08-06 14:04:51 +00:00
|
|
|
}
|
2013-03-28 13:49:22 +00:00
|
|
|
}
|
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
static void test_writable_after_snapshot_release(skiatest::Reporter* reporter,
|
|
|
|
SkSurface* surface) {
|
2013-04-03 15:03:26 +00:00
|
|
|
// This test succeeds by not triggering an assertion.
|
|
|
|
// The test verifies that the surface remains writable (usable) after
|
|
|
|
// acquiring and releasing a snapshot without triggering a copy on write.
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
canvas->clear(1);
|
2016-03-17 17:51:11 +00:00
|
|
|
surface->makeImageSnapshot(); // Create and destroy SkImage
|
2013-07-25 23:29:40 +00:00
|
|
|
canvas->clear(2); // Must not assert internally
|
2013-03-28 13:49:22 +00:00
|
|
|
}
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) {
|
2016-03-24 01:59:25 +00:00
|
|
|
test_writable_after_snapshot_release(reporter, create_surface().get());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2016-03-24 01:59:25 +00:00
|
|
|
test_writable_after_snapshot_release(reporter, surface.get());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-01 22:38:16 +00:00
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
static void test_crbug263329(skiatest::Reporter* reporter,
|
|
|
|
SkSurface* surface1,
|
|
|
|
SkSurface* surface2) {
|
2013-07-25 23:29:40 +00:00
|
|
|
// This is a regression test for crbug.com/263329
|
|
|
|
// Bug was caused by onCopyOnWrite releasing the old surface texture
|
|
|
|
// back to the scratch texture pool even though the texture is used
|
|
|
|
// by and active SkImage_Gpu.
|
|
|
|
SkCanvas* canvas1 = surface1->getCanvas();
|
|
|
|
SkCanvas* canvas2 = surface2->getCanvas();
|
|
|
|
canvas1->clear(1);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image1(surface1->makeImageSnapshot());
|
2013-07-25 23:29:40 +00:00
|
|
|
// Trigger copy on write, new backing is a scratch texture
|
|
|
|
canvas1->clear(2);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image2(surface1->makeImageSnapshot());
|
2013-07-25 23:29:40 +00:00
|
|
|
// Trigger copy on write, old backing should not be returned to scratch
|
|
|
|
// pool because it is held by image2
|
|
|
|
canvas1->clear(3);
|
|
|
|
|
|
|
|
canvas2->clear(4);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image3(surface2->makeImageSnapshot());
|
2013-07-25 23:29:40 +00:00
|
|
|
// Trigger copy on write on surface2. The new backing store should not
|
|
|
|
// be recycling a texture that is held by an existing image.
|
|
|
|
canvas2->clear(5);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image4(surface2->makeImageSnapshot());
|
2020-03-06 18:07:10 +00:00
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
auto imageProxy = [ctx = surface1->recordingContext()](SkImage* img) {
|
|
|
|
GrTextureProxy* proxy = sk_gpu_test::GetTextureImageProxy(img, ctx);
|
|
|
|
SkASSERT(proxy);
|
|
|
|
return proxy;
|
|
|
|
};
|
2020-03-06 18:07:10 +00:00
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, imageProxy(image4.get()) != imageProxy(image3.get()));
|
2013-07-25 23:29:40 +00:00
|
|
|
// The following assertion checks crbug.com/263329
|
2021-02-23 15:45:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, imageProxy(image4.get()) != imageProxy(image2.get()));
|
|
|
|
REPORTER_ASSERT(reporter, imageProxy(image4.get()) != imageProxy(image1.get()));
|
|
|
|
REPORTER_ASSERT(reporter, imageProxy(image3.get()) != imageProxy(image2.get()));
|
|
|
|
REPORTER_ASSERT(reporter, imageProxy(image3.get()) != imageProxy(image1.get()));
|
|
|
|
REPORTER_ASSERT(reporter, imageProxy(image2.get()) != imageProxy(image1.get()));
|
2013-07-25 23:29:40 +00:00
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface1(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
|
|
|
auto surface2(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2016-03-24 01:59:25 +00:00
|
|
|
test_crbug263329(reporter, surface1.get(), surface2.get());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-25 23:29:40 +00:00
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
DEF_TEST(SurfaceGetTexture, reporter) {
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(create_surface());
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
2017-01-31 16:31:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
|
2017-01-31 16:31:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
2017-01-31 16:31:39 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
|
2018-04-04 19:54:55 +00:00
|
|
|
GrBackendTexture backendTex = image->getBackendTexture(false);
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.isValid());
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
|
2017-01-31 16:31:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
|
2018-04-04 19:54:55 +00:00
|
|
|
GrBackendTexture backendTex2 = image->getBackendTexture(false);
|
|
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTex2));
|
2013-05-01 22:38:16 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-23 16:08:04 +00:00
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
static SkBudgeted is_budgeted(const sk_sp<SkSurface>& surf) {
|
|
|
|
SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get();
|
2017-01-31 16:31:39 +00:00
|
|
|
|
2021-05-24 19:35:08 +00:00
|
|
|
GrRenderTargetProxy* proxy = gsurf->getDevice()->targetProxy();
|
2017-01-31 16:31:39 +00:00
|
|
|
return proxy->isBudgeted();
|
2015-01-23 16:08:04 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
static SkBudgeted is_budgeted(SkImage* image, GrRecordingContext* rc) {
|
|
|
|
return sk_gpu_test::GetTextureImageProxy(image, rc)->isBudgeted();
|
2016-03-17 17:51:11 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) {
|
2015-01-23 16:08:04 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(8,8);
|
2021-02-23 15:45:39 +00:00
|
|
|
GrDirectContext* dContext = ctxInfo.directContext();
|
2017-03-20 12:38:50 +00:00
|
|
|
for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
|
2021-02-23 15:45:39 +00:00
|
|
|
auto surface(SkSurface::MakeRenderTarget(dContext, budgeted, info));
|
2017-03-20 12:38:50 +00:00
|
|
|
SkASSERT(surface);
|
|
|
|
REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
|
|
|
|
|
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
|
|
|
|
|
|
|
// Initially the image shares a texture with the surface, and the
|
|
|
|
// the budgets should always match.
|
|
|
|
REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
|
2021-02-23 15:45:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, budgeted == is_budgeted(image.get(), dContext));
|
2017-03-20 12:38:50 +00:00
|
|
|
|
|
|
|
// Now trigger copy-on-write
|
|
|
|
surface->getCanvas()->clear(SK_ColorBLUE);
|
|
|
|
|
|
|
|
// They don't share a texture anymore but the budgets should still match.
|
|
|
|
REPORTER_ASSERT(reporter, budgeted == is_budgeted(surface));
|
2021-02-23 15:45:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, budgeted == is_budgeted(image.get(), dContext));
|
2015-01-23 16:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-01 22:38:16 +00:00
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
static void test_no_canvas1(skiatest::Reporter* reporter,
|
|
|
|
SkSurface* surface,
|
|
|
|
SkSurface::ContentChangeMode mode) {
|
|
|
|
// Test passes by not asserting
|
|
|
|
surface->notifyContentWillChange(mode);
|
|
|
|
}
|
|
|
|
static void test_no_canvas2(skiatest::Reporter* reporter,
|
|
|
|
SkSurface* surface,
|
|
|
|
SkSurface::ContentChangeMode mode) {
|
2013-04-16 19:41:09 +00:00
|
|
|
// Verifies the robustness of SkSurface for handling use cases where calls
|
|
|
|
// are made before a canvas is created.
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image1 = surface->makeImageSnapshot();
|
2020-08-07 21:35:54 +00:00
|
|
|
sk_sp<SkImage> aur_image1(image1); // NOLINT(performance-unnecessary-copy-initialization)
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
surface->notifyContentWillChange(mode);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image2 = surface->makeImageSnapshot();
|
2020-08-07 21:35:54 +00:00
|
|
|
sk_sp<SkImage> aur_image2(image2); // NOLINT(performance-unnecessary-copy-initialization)
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, image1 != image2);
|
|
|
|
}
|
|
|
|
DEF_TEST(SurfaceNoCanvas, reporter) {
|
|
|
|
SkSurface::ContentChangeMode modes[] =
|
|
|
|
{ SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode};
|
|
|
|
for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
|
|
|
|
for (auto& mode : modes) {
|
2016-03-24 01:59:25 +00:00
|
|
|
test_func(reporter, create_surface().get(), mode);
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
}
|
2013-04-16 19:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) {
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
SkSurface::ContentChangeMode modes[] =
|
|
|
|
{ SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode};
|
|
|
|
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
|
|
|
|
for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
|
|
|
|
for (auto& mode : modes) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface(surface_func(ctxInfo.directContext(), kPremul_SkAlphaType, nullptr));
|
2016-03-24 01:59:25 +00:00
|
|
|
test_func(reporter, surface.get(), mode);
|
2014-07-17 17:50:59 +00:00
|
|
|
}
|
2013-11-12 13:51:03 +00:00
|
|
|
}
|
2013-04-03 15:03:26 +00:00
|
|
|
}
|
2013-03-28 13:49:22 +00:00
|
|
|
}
|
2016-01-30 18:01:06 +00:00
|
|
|
|
|
|
|
static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Reporter* reporter) {
|
2016-03-09 22:26:26 +00:00
|
|
|
SkPixmap surfacePM;
|
|
|
|
REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM));
|
2016-01-30 18:01:06 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
2016-03-09 22:26:26 +00:00
|
|
|
SkPixmap pm;
|
|
|
|
REPORTER_ASSERT(reporter, image->peekPixels(&pm));
|
2016-01-30 18:01:06 +00:00
|
|
|
|
2016-03-09 22:26:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, surfacePM.rowBytes() == pm.rowBytes());
|
2016-01-30 18:01:06 +00:00
|
|
|
|
|
|
|
// trigger a copy-on-write
|
|
|
|
surface->getCanvas()->drawPaint(SkPaint());
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image2(surface->makeImageSnapshot());
|
2016-01-30 18:01:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID());
|
|
|
|
|
2016-03-09 22:26:26 +00:00
|
|
|
SkPixmap pm2;
|
|
|
|
REPORTER_ASSERT(reporter, image2->peekPixels(&pm2));
|
|
|
|
REPORTER_ASSERT(reporter, pm2.rowBytes() == pm.rowBytes());
|
2016-01-30 18:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(surface_rowbytes, reporter) {
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
|
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surf0(SkSurface::MakeRaster(info));
|
|
|
|
check_rowbytes_remain_consistent(surf0.get(), reporter);
|
2016-01-30 18:01:06 +00:00
|
|
|
|
|
|
|
// specify a larger rowbytes
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surf1(SkSurface::MakeRaster(info, 500, nullptr));
|
|
|
|
check_rowbytes_remain_consistent(surf1.get(), reporter);
|
2016-01-30 18:01:06 +00:00
|
|
|
|
|
|
|
// Try some illegal rowByte values
|
2016-03-24 01:59:25 +00:00
|
|
|
auto s = SkSurface::MakeRaster(info, 396, nullptr); // needs to be at least 400
|
2016-01-30 18:01:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == s);
|
2017-10-03 18:47:21 +00:00
|
|
|
s = SkSurface::MakeRaster(info, std::numeric_limits<size_t>::max(), nullptr);
|
2016-01-30 18:01:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == s);
|
|
|
|
}
|
2016-02-05 15:17:34 +00:00
|
|
|
|
2016-07-06 13:22:06 +00:00
|
|
|
DEF_TEST(surface_raster_zeroinitialized, reporter) {
|
|
|
|
sk_sp<SkSurface> s(SkSurface::MakeRasterN32Premul(100, 100));
|
|
|
|
SkPixmap pixmap;
|
|
|
|
REPORTER_ASSERT(reporter, s->peekPixels(&pixmap));
|
|
|
|
|
|
|
|
for (int i = 0; i < pixmap.info().width(); ++i) {
|
|
|
|
for (int j = 0; j < pixmap.info().height(); ++j) {
|
|
|
|
REPORTER_ASSERT(reporter, *pixmap.addr32(i, j) == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-20 19:00:36 +00:00
|
|
|
static sk_sp<SkSurface> create_gpu_surface_backend_texture(GrDirectContext* dContext,
|
|
|
|
int sampleCnt,
|
2020-10-13 00:45:06 +00:00
|
|
|
const SkColor4f& color) {
|
2018-12-10 17:43:36 +00:00
|
|
|
// On Pixel and Pixel2XL's with Adreno 530 and 540s, setting width and height to 10s reliably
|
|
|
|
// triggers what appears to be a driver race condition where the 10x10 surface from the
|
|
|
|
// OverdrawSurface_gpu test is reused(?) for this surface created by the SurfacePartialDraw_gpu
|
|
|
|
// test.
|
|
|
|
//
|
|
|
|
// Immediately after creation of this surface, readback shows the correct initial solid color.
|
|
|
|
// However, sometime before content is rendered into the upper half of the surface, the driver
|
|
|
|
// presumably cleans up the OverdrawSurface_gpu's memory which corrupts this color buffer. The
|
|
|
|
// top half of the surface is fine after the partially-covering rectangle is drawn, but the
|
|
|
|
// untouched bottom half contains random pixel values that trigger asserts in the
|
|
|
|
// SurfacePartialDraw_gpu test for no longer matching the initial color. Running the
|
|
|
|
// SurfacePartialDraw_gpu test without the OverdrawSurface_gpu test completes successfully.
|
|
|
|
//
|
|
|
|
// Requesting a much larger backend texture size seems to prevent it from reusing the same
|
|
|
|
// memory and avoids the issue.
|
|
|
|
#if defined(SK_BUILD_FOR_SKQP)
|
2016-05-04 19:01:58 +00:00
|
|
|
const int kWidth = 10;
|
|
|
|
const int kHeight = 10;
|
2018-12-10 17:43:36 +00:00
|
|
|
#else
|
|
|
|
const int kWidth = 100;
|
|
|
|
const int kHeight = 100;
|
|
|
|
#endif
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto surf = sk_gpu_test::MakeBackendTextureSurface(dContext,
|
|
|
|
{kWidth, kHeight},
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
sampleCnt,
|
|
|
|
kRGBA_8888_SkColorType);
|
|
|
|
if (!surf) {
|
2020-10-12 21:30:00 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-13 00:45:06 +00:00
|
|
|
surf->getCanvas()->clear(color);
|
|
|
|
return surf;
|
2016-05-04 19:01:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 21:00:32 +00:00
|
|
|
static bool supports_readpixels(const GrCaps* caps, SkSurface* surface) {
|
|
|
|
auto surfaceGpu = static_cast<SkSurface_Gpu*>(surface);
|
2021-05-24 19:35:08 +00:00
|
|
|
GrRenderTarget* rt = surfaceGpu->getDevice()->targetProxy()->peekRenderTarget();
|
2020-05-26 21:00:32 +00:00
|
|
|
if (!rt) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return caps->surfaceSupportsReadPixels(rt) == GrCaps::SurfaceReadPixelsSupport::kSupported;
|
|
|
|
}
|
|
|
|
|
2020-10-06 14:07:38 +00:00
|
|
|
static sk_sp<SkSurface> create_gpu_surface_backend_render_target(GrDirectContext* dContext,
|
|
|
|
int sampleCnt,
|
2020-10-13 00:45:06 +00:00
|
|
|
const SkColor4f& color) {
|
2016-05-04 19:01:58 +00:00
|
|
|
const int kWidth = 10;
|
|
|
|
const int kHeight = 10;
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
auto surf = sk_gpu_test::MakeBackendRenderTargetSurface(dContext,
|
|
|
|
{kWidth, kHeight},
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
sampleCnt,
|
2020-10-13 00:45:06 +00:00
|
|
|
kRGBA_8888_SkColorType);
|
2020-10-06 14:07:38 +00:00
|
|
|
if (!surf) {
|
2016-05-04 19:01:58 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-06 14:07:38 +00:00
|
|
|
surf->getCanvas()->clear(color);
|
|
|
|
return surf;
|
2016-05-04 19:01:58 +00:00
|
|
|
}
|
2016-02-05 15:17:34 +00:00
|
|
|
|
2019-08-21 13:38:10 +00:00
|
|
|
static void test_surface_context_clear(skiatest::Reporter* reporter,
|
2020-08-11 16:02:22 +00:00
|
|
|
GrDirectContext* dContext,
|
2021-08-10 17:49:51 +00:00
|
|
|
skgpu::SurfaceContext* surfaceContext,
|
2021-07-22 19:11:03 +00:00
|
|
|
uint32_t expectedValue) {
|
2019-08-21 13:38:10 +00:00
|
|
|
int w = surfaceContext->width();
|
|
|
|
int h = surfaceContext->height();
|
2019-08-02 16:26:22 +00:00
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
|
|
|
SkAutoPixmapStorage readback;
|
|
|
|
readback.alloc(ii);
|
2016-02-05 15:17:34 +00:00
|
|
|
|
2019-08-02 16:26:22 +00:00
|
|
|
readback.erase(~expectedValue);
|
2020-12-24 01:36:44 +00:00
|
|
|
surfaceContext->readPixels(dContext, readback, {0, 0});
|
2016-02-05 15:17:34 +00:00
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
2019-08-02 16:26:22 +00:00
|
|
|
uint32_t pixel = readback.addr32()[y * w + x];
|
2016-02-05 15:17:34 +00:00
|
|
|
if (pixel != expectedValue) {
|
|
|
|
SkString msg;
|
|
|
|
if (expectedValue) {
|
|
|
|
msg = "SkSurface should have left render target unmodified";
|
|
|
|
} else {
|
|
|
|
msg = "SkSurface should have cleared the render target";
|
|
|
|
}
|
|
|
|
ERRORF(reporter,
|
|
|
|
"%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_str(), pixel,
|
|
|
|
expectedValue, x, y);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 21:02:39 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
|
2020-08-11 16:02:22 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2021-08-10 17:49:51 +00:00
|
|
|
// Snaps an image from a surface and then makes a SurfaceContext from the image's texture.
|
2020-08-11 16:02:22 +00:00
|
|
|
auto makeImageSurfaceContext = [dContext](SkSurface* surface) {
|
2019-08-21 13:38:10 +00:00
|
|
|
sk_sp<SkImage> i(surface->makeImageSnapshot());
|
2021-02-03 15:15:31 +00:00
|
|
|
auto gpuImage = static_cast<SkImage_Gpu*>(as_IB(i));
|
|
|
|
auto [view, ct] = gpuImage->asView(dContext, GrMipmapped::kNo);
|
|
|
|
GrColorInfo colorInfo(ct, i->alphaType(), i->refColorSpace());
|
2021-08-02 15:14:38 +00:00
|
|
|
return dContext->priv().makeSC(view, std::move(colorInfo));
|
2019-08-21 13:38:10 +00:00
|
|
|
};
|
2016-05-04 19:01:58 +00:00
|
|
|
|
2019-08-21 13:38:10 +00:00
|
|
|
// Test that non-wrapped RTs are created clear.
|
|
|
|
for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surface}) {
|
2020-08-11 16:02:22 +00:00
|
|
|
auto surface = surface_func(dContext, kPremul_SkAlphaType, nullptr);
|
2019-08-21 13:38:10 +00:00
|
|
|
if (!surface) {
|
|
|
|
ERRORF(reporter, "Could not create GPU SkSurface.");
|
|
|
|
return;
|
2017-01-18 15:08:39 +00:00
|
|
|
}
|
2021-07-22 19:11:03 +00:00
|
|
|
auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(surface->getCanvas());
|
|
|
|
if (!sfc) {
|
2019-08-21 13:38:10 +00:00
|
|
|
ERRORF(reporter, "Could access surface context of GPU SkSurface.");
|
|
|
|
return;
|
|
|
|
}
|
2021-07-22 19:11:03 +00:00
|
|
|
test_surface_context_clear(reporter, dContext, sfc, 0x0);
|
2019-08-21 13:38:10 +00:00
|
|
|
auto imageSurfaceCtx = makeImageSurfaceContext(surface.get());
|
2020-08-11 16:02:22 +00:00
|
|
|
test_surface_context_clear(reporter, dContext, imageSurfaceCtx.get(), 0x0);
|
2019-08-21 13:38:10 +00:00
|
|
|
}
|
2016-05-04 19:01:58 +00:00
|
|
|
|
2019-08-21 13:38:10 +00:00
|
|
|
// Wrapped RTs are *not* supposed to clear (to allow client to partially update a surface).
|
|
|
|
const SkColor4f kOrigColor{.67f, .67f, .67f, 1};
|
2020-10-06 14:07:38 +00:00
|
|
|
for (auto& surfaceFunc :
|
|
|
|
{&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) {
|
2020-10-13 00:45:06 +00:00
|
|
|
auto surface = surfaceFunc(dContext, 1, kOrigColor);
|
2019-08-21 13:38:10 +00:00
|
|
|
if (!surface) {
|
|
|
|
ERRORF(reporter, "Could not create GPU SkSurface.");
|
|
|
|
return;
|
2016-02-05 15:17:34 +00:00
|
|
|
}
|
2021-07-22 19:11:03 +00:00
|
|
|
auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(surface->getCanvas());
|
|
|
|
if (!sfc) {
|
2019-08-21 13:38:10 +00:00
|
|
|
ERRORF(reporter, "Could access surface context of GPU SkSurface.");
|
|
|
|
return;
|
2016-05-04 19:01:58 +00:00
|
|
|
}
|
2021-07-22 19:11:03 +00:00
|
|
|
test_surface_context_clear(reporter, dContext, sfc, kOrigColor.toSkColor());
|
2019-08-21 13:38:10 +00:00
|
|
|
auto imageSurfaceCtx = makeImageSurfaceContext(surface.get());
|
2020-08-11 16:02:22 +00:00
|
|
|
test_surface_context_clear(reporter, dContext, imageSurfaceCtx.get(),
|
|
|
|
kOrigColor.toSkColor());
|
2016-05-04 19:01:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_surface_draw_partially(
|
2019-09-30 17:21:25 +00:00
|
|
|
skiatest::Reporter* reporter, sk_sp<SkSurface> surface, SkColor origColor) {
|
2016-05-04 19:01:58 +00:00
|
|
|
const int kW = surface->width();
|
|
|
|
const int kH = surface->height();
|
|
|
|
SkPaint paint;
|
|
|
|
const SkColor kRectColor = ~origColor | 0xFF000000;
|
|
|
|
paint.setColor(kRectColor);
|
2019-08-02 16:26:22 +00:00
|
|
|
surface->getCanvas()->drawRect(SkRect::MakeIWH(kW, kH/2), paint);
|
|
|
|
|
2016-05-04 19:01:58 +00:00
|
|
|
// Read back RGBA to avoid format conversions that may not be supported on all platforms.
|
|
|
|
SkImageInfo readInfo = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2019-08-02 16:26:22 +00:00
|
|
|
|
|
|
|
SkAutoPixmapStorage readback;
|
|
|
|
readback.alloc(readInfo);
|
|
|
|
|
|
|
|
readback.erase(~origColor);
|
2020-05-13 21:55:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, surface->readPixels(readback.info(), readback.writable_addr(),
|
|
|
|
readback.rowBytes(), 0, 0));
|
2016-05-04 19:01:58 +00:00
|
|
|
bool stop = false;
|
2019-07-23 17:44:16 +00:00
|
|
|
|
2019-09-30 17:21:25 +00:00
|
|
|
SkPMColor origColorPM = SkPackARGB_as_RGBA(SkColorGetA(origColor),
|
|
|
|
SkColorGetR(origColor),
|
|
|
|
SkColorGetG(origColor),
|
|
|
|
SkColorGetB(origColor));
|
|
|
|
SkPMColor rectColorPM = SkPackARGB_as_RGBA(SkColorGetA(kRectColor),
|
|
|
|
SkColorGetR(kRectColor),
|
|
|
|
SkColorGetG(kRectColor),
|
|
|
|
SkColorGetB(kRectColor));
|
2019-07-23 17:44:16 +00:00
|
|
|
|
2016-05-04 19:01:58 +00:00
|
|
|
for (int y = 0; y < kH/2 && !stop; ++y) {
|
|
|
|
for (int x = 0; x < kW && !stop; ++x) {
|
2019-08-02 16:26:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, rectColorPM == readback.addr32()[x + y * kW]);
|
|
|
|
if (rectColorPM != readback.addr32()[x + y * kW]) {
|
2019-07-23 17:44:16 +00:00
|
|
|
SkDebugf("--- got [%x] expected [%x], x = %d, y = %d\n",
|
2019-08-02 16:26:22 +00:00
|
|
|
readback.addr32()[x + y * kW], rectColorPM, x, y);
|
2016-05-04 19:01:58 +00:00
|
|
|
stop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stop = false;
|
|
|
|
for (int y = kH/2; y < kH && !stop; ++y) {
|
|
|
|
for (int x = 0; x < kW && !stop; ++x) {
|
2019-08-02 16:26:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, origColorPM == readback.addr32()[x + y * kW]);
|
|
|
|
if (origColorPM != readback.addr32()[x + y * kW]) {
|
2019-07-23 17:44:16 +00:00
|
|
|
SkDebugf("--- got [%x] expected [%x], x = %d, y = %d\n",
|
2019-08-02 16:26:22 +00:00
|
|
|
readback.addr32()[x + y * kW], origColorPM, x, y);
|
2016-05-04 19:01:58 +00:00
|
|
|
stop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-05 15:17:34 +00:00
|
|
|
|
2016-06-28 15:07:26 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-05-17 14:01:21 +00:00
|
|
|
|
2019-07-23 17:44:16 +00:00
|
|
|
static const SkColor4f kOrigColor { 0.667f, 0.733f, 0.8f, 1 };
|
2016-05-04 00:14:07 +00:00
|
|
|
|
2020-10-06 14:07:38 +00:00
|
|
|
for (auto& surfaceFunc :
|
|
|
|
{&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) {
|
2016-05-04 19:01:58 +00:00
|
|
|
// Validate that we can draw to the canvas and that the original texture color is
|
|
|
|
// preserved in pixels that aren't rendered to via the surface.
|
|
|
|
// This works only for non-multisampled case.
|
2020-10-13 00:45:06 +00:00
|
|
|
auto surface = surfaceFunc(context, 1, kOrigColor);
|
|
|
|
if (surface && supports_readpixels(context->priv().caps(), surface.get())) {
|
2019-07-23 17:44:16 +00:00
|
|
|
test_surface_draw_partially(reporter, surface, kOrigColor.toSkColor());
|
2016-05-04 19:01:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-04 00:14:07 +00:00
|
|
|
|
2019-02-05 15:08:43 +00:00
|
|
|
struct ReleaseChecker {
|
|
|
|
ReleaseChecker() : fReleaseCount(0) {}
|
|
|
|
int fReleaseCount;
|
|
|
|
static void Release(void* self) {
|
|
|
|
static_cast<ReleaseChecker*>(self)->fReleaseCount++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedWithRelease_Gpu, reporter, ctxInfo) {
|
|
|
|
const int kWidth = 10;
|
|
|
|
const int kHeight = 10;
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
auto ctx = ctxInfo.directContext();
|
2019-02-05 15:08:43 +00:00
|
|
|
GrGpu* gpu = ctx->priv().getGpu();
|
|
|
|
|
|
|
|
for (bool useTexture : {false, true}) {
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<sk_gpu_test::ManagedBackendTexture> mbet;
|
2019-02-05 15:08:43 +00:00
|
|
|
GrBackendRenderTarget backendRT;
|
|
|
|
sk_sp<SkSurface> surface;
|
|
|
|
|
|
|
|
ReleaseChecker releaseChecker;
|
|
|
|
GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin;
|
|
|
|
|
|
|
|
if (useTexture) {
|
2019-05-07 17:29:22 +00:00
|
|
|
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
2021-01-26 22:46:50 +00:00
|
|
|
mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(ctx, ii, GrMipmapped::kNo,
|
2020-10-13 00:45:06 +00:00
|
|
|
GrRenderable::kYes);
|
|
|
|
if (!mbet) {
|
2019-02-05 15:08:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
surface = SkSurface::MakeFromBackendTexture(
|
|
|
|
ctx,
|
|
|
|
mbet->texture(),
|
|
|
|
texOrigin,
|
|
|
|
/*sample count*/ 1,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
/*color space*/ nullptr,
|
|
|
|
/*surface props*/ nullptr,
|
|
|
|
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext(ReleaseChecker::Release, &releaseChecker));
|
2019-02-05 15:08:43 +00:00
|
|
|
} else {
|
2020-10-06 14:07:38 +00:00
|
|
|
backendRT = gpu->createTestingOnlyBackendRenderTarget({kWidth, kHeight},
|
2019-02-05 15:08:43 +00:00
|
|
|
GrColorType::kRGBA_8888);
|
|
|
|
if (!backendRT.isValid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
surface = SkSurface::MakeFromBackendRenderTarget(ctx, backendRT, texOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
nullptr, nullptr,
|
|
|
|
ReleaseChecker::Release,
|
|
|
|
&releaseChecker);
|
|
|
|
}
|
|
|
|
if (!surface) {
|
|
|
|
ERRORF(reporter, "Failed to create surface");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->getCanvas()->clear(SK_ColorRED);
|
2020-06-30 17:42:46 +00:00
|
|
|
surface->flush();
|
2020-05-14 19:45:44 +00:00
|
|
|
ctx->submit(true);
|
2019-02-05 15:08:43 +00:00
|
|
|
|
|
|
|
// Now exercise the release proc
|
|
|
|
REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
|
|
|
|
surface.reset(nullptr); // force a release of the surface
|
|
|
|
REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
if (!useTexture) {
|
2019-02-05 15:08:43 +00:00
|
|
|
gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-04 19:01:58 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-05-17 14:01:21 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
|
|
|
|
if (caps->avoidStencilBuffers()) {
|
2017-05-08 19:02:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-05-17 14:01:21 +00:00
|
|
|
|
2019-07-23 17:44:16 +00:00
|
|
|
static const SkColor4f kOrigColor { 0.667f, 0.733f, 0.8f, 1 };
|
2016-05-04 19:01:58 +00:00
|
|
|
|
2019-05-17 14:01:21 +00:00
|
|
|
auto resourceProvider = context->priv().resourceProvider();
|
2018-01-16 20:07:54 +00:00
|
|
|
|
2020-10-06 14:07:38 +00:00
|
|
|
for (auto& surfaceFunc :
|
|
|
|
{&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) {
|
2018-02-03 01:32:49 +00:00
|
|
|
for (int sampleCnt : {1, 4, 8}) {
|
2020-10-13 00:45:06 +00:00
|
|
|
auto surface = surfaceFunc(context, sampleCnt, kOrigColor);
|
2016-05-04 19:01:58 +00:00
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
if (!surface && sampleCnt > 1) {
|
2017-12-12 18:01:25 +00:00
|
|
|
// Certain platforms don't support MSAA, skip these.
|
|
|
|
continue;
|
2016-05-04 19:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate that we can attach a stencil buffer to an SkSurface created by either of
|
|
|
|
// our surface functions.
|
2021-06-03 15:58:43 +00:00
|
|
|
auto rtp = SkCanvasPriv::TopDeviceTargetProxy(surface->getCanvas());
|
|
|
|
GrRenderTarget* rt = rtp->peekRenderTarget();
|
2021-04-23 19:11:44 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
resourceProvider->attachStencilAttachment(rt, rt->numSamples() > 1));
|
2016-05-04 19:01:58 +00:00
|
|
|
}
|
2016-02-05 15:17:34 +00:00
|
|
|
}
|
2016-08-30 14:07:59 +00:00
|
|
|
}
|
2016-11-22 16:31:41 +00:00
|
|
|
|
2019-05-24 14:16:35 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-05-24 14:16:35 +00:00
|
|
|
|
|
|
|
for (int sampleCnt : {1, 2}) {
|
|
|
|
auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet1 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
|
|
|
|
context, ii, GrMipmapped::kNo, GrRenderable::kYes);
|
|
|
|
if (!mbet1) {
|
2019-05-24 14:16:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet2 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
|
|
|
|
context, ii, GrMipmapped::kNo, GrRenderable::kYes);
|
|
|
|
if (!mbet2) {
|
2019-05-24 14:16:35 +00:00
|
|
|
ERRORF(reporter, "Expected to be able to make second texture");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto ii2 = ii.makeWH(8, 8);
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet3 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(
|
|
|
|
context, ii2, GrMipmapped::kNo, GrRenderable::kYes);
|
2019-05-24 14:16:35 +00:00
|
|
|
GrBackendTexture backendTexture3;
|
2020-10-13 00:45:06 +00:00
|
|
|
if (!mbet3) {
|
2019-05-24 14:16:35 +00:00
|
|
|
ERRORF(reporter, "Couldn't create different sized texture.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto surf = SkSurface::MakeFromBackendTexture(
|
2020-10-13 00:45:06 +00:00
|
|
|
context, mbet1->texture(), kTopLeft_GrSurfaceOrigin, sampleCnt,
|
2019-05-24 14:16:35 +00:00
|
|
|
kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr);
|
|
|
|
if (!surf) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
surf->getCanvas()->clear(SK_ColorBLUE);
|
|
|
|
// Change matrix, layer, and clip state before swapping out the backing texture.
|
|
|
|
surf->getCanvas()->translate(5, 5);
|
|
|
|
surf->getCanvas()->saveLayer(nullptr, nullptr);
|
|
|
|
surf->getCanvas()->clipRect(SkRect::MakeXYWH(0, 0, 1, 1));
|
|
|
|
// switch origin while we're at it.
|
2020-10-13 00:45:06 +00:00
|
|
|
bool replaced = surf->replaceBackendTexture(mbet2->texture(), kBottomLeft_GrSurfaceOrigin);
|
2019-05-24 14:16:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, replaced);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
surf->getCanvas()->drawRect(SkRect::MakeWH(5, 5), paint);
|
|
|
|
surf->getCanvas()->restore();
|
|
|
|
|
|
|
|
// Check that the replacement texture got the right color values.
|
|
|
|
SkAutoPixmapStorage pm;
|
|
|
|
pm.alloc(ii);
|
|
|
|
bool bad = !surf->readPixels(pm, 0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, !bad, "Could not read surface.");
|
|
|
|
for (int y = 0; y < ii.height() && !bad; ++y) {
|
|
|
|
for (int x = 0; x < ii.width() && !bad; ++x) {
|
|
|
|
auto expected = (x == 5 && y == 5) ? 0xFF0000FF : 0xFFFF0000;
|
|
|
|
auto found = *pm.addr32(x, y);
|
|
|
|
if (found != expected) {
|
|
|
|
bad = true;
|
|
|
|
ERRORF(reporter, "Expected color 0x%08x, found color 0x%08x at %d, %d.",
|
|
|
|
expected, found, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The original texture should still be all blue.
|
|
|
|
surf = SkSurface::MakeFromBackendTexture(
|
2020-10-13 00:45:06 +00:00
|
|
|
context, mbet1->texture(), kBottomLeft_GrSurfaceOrigin, sampleCnt,
|
2019-05-24 14:16:35 +00:00
|
|
|
kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr);
|
|
|
|
if (!surf) {
|
|
|
|
ERRORF(reporter, "Could not create second surface.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bad = !surf->readPixels(pm, 0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, !bad, "Could not read second surface.");
|
|
|
|
for (int y = 0; y < ii.height() && !bad; ++y) {
|
|
|
|
for (int x = 0; x < ii.width() && !bad; ++x) {
|
|
|
|
auto expected = 0xFFFF0000;
|
|
|
|
auto found = *pm.addr32(x, y);
|
|
|
|
if (found != expected) {
|
|
|
|
bad = true;
|
|
|
|
ERRORF(reporter, "Expected color 0x%08x, found color 0x%08x at %d, %d.",
|
|
|
|
expected, found, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't replace with the same texture
|
|
|
|
REPORTER_ASSERT(reporter,
|
2020-10-13 00:45:06 +00:00
|
|
|
!surf->replaceBackendTexture(mbet1->texture(), kTopLeft_GrSurfaceOrigin));
|
2019-05-24 14:16:35 +00:00
|
|
|
// Can't replace with invalid texture
|
|
|
|
REPORTER_ASSERT(reporter, !surf->replaceBackendTexture({}, kTopLeft_GrSurfaceOrigin));
|
|
|
|
// Can't replace with different size texture.
|
|
|
|
REPORTER_ASSERT(reporter,
|
2020-10-13 00:45:06 +00:00
|
|
|
!surf->replaceBackendTexture(mbet3->texture(), kTopLeft_GrSurfaceOrigin));
|
2019-05-24 14:16:35 +00:00
|
|
|
// Can't replace texture of non-wrapped SkSurface.
|
|
|
|
surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii, sampleCnt, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, surf);
|
|
|
|
if (surf) {
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, !surf->replaceBackendTexture(mbet1->texture(),
|
2019-05-24 14:16:35 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 16:31:41 +00:00
|
|
|
static void test_overdraw_surface(skiatest::Reporter* r, SkSurface* surface) {
|
2016-11-28 23:28:07 +00:00
|
|
|
SkOverdrawCanvas canvas(surface->getCanvas());
|
|
|
|
canvas.drawPaint(SkPaint());
|
2016-11-22 16:31:41 +00:00
|
|
|
sk_sp<SkImage> image = surface->makeImageSnapshot();
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
2018-02-07 20:51:00 +00:00
|
|
|
image->asLegacyBitmap(&bitmap);
|
2016-11-22 16:31:41 +00:00
|
|
|
for (int y = 0; y < 10; y++) {
|
|
|
|
for (int x = 0; x < 10; x++) {
|
|
|
|
REPORTER_ASSERT(r, 1 == SkGetPackedA32(*bitmap.getAddr32(x, y)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(OverdrawSurface_Raster, r) {
|
|
|
|
sk_sp<SkSurface> surface = create_surface();
|
|
|
|
test_overdraw_surface(r, surface.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(OverdrawSurface_Gpu, r, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2016-11-22 16:31:41 +00:00
|
|
|
sk_sp<SkSurface> surface = create_gpu_surface(context);
|
|
|
|
test_overdraw_surface(r, surface.get());
|
|
|
|
}
|
2017-06-28 23:57:21 +00:00
|
|
|
|
|
|
|
DEF_TEST(Surface_null, r) {
|
|
|
|
REPORTER_ASSERT(r, SkSurface::MakeNull(0, 0) == nullptr);
|
|
|
|
|
|
|
|
const int w = 37;
|
|
|
|
const int h = 1000;
|
|
|
|
auto surf = SkSurface::MakeNull(w, h);
|
|
|
|
auto canvas = surf->getCanvas();
|
|
|
|
|
|
|
|
canvas->drawPaint(SkPaint()); // should not crash, but don't expect anything to draw
|
|
|
|
REPORTER_ASSERT(r, surf->makeImageSnapshot() == nullptr);
|
|
|
|
}
|
2018-02-07 21:05:29 +00:00
|
|
|
|
|
|
|
// assert: if a given imageinfo is valid for a surface, then it must be valid for an image
|
|
|
|
// (so the snapshot can succeed)
|
|
|
|
DEF_TEST(surface_image_unity, reporter) {
|
|
|
|
auto do_test = [reporter](const SkImageInfo& info) {
|
|
|
|
size_t rowBytes = info.minRowBytes();
|
|
|
|
auto surf = SkSurface::MakeRaster(info, rowBytes, nullptr);
|
|
|
|
if (surf) {
|
|
|
|
auto img = surf->makeImageSnapshot();
|
2022-02-04 21:09:04 +00:00
|
|
|
if ((false)) { // change to true to document the differences
|
|
|
|
if (!img) {
|
|
|
|
SkDebugf("image failed: [%08X %08X] %14s %s\n",
|
|
|
|
info.width(),
|
|
|
|
info.height(),
|
|
|
|
ToolUtils::colortype_name(info.colorType()),
|
|
|
|
ToolUtils::alphatype_name(info.alphaType()));
|
|
|
|
return;
|
|
|
|
}
|
2018-02-07 21:05:29 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, img != nullptr);
|
|
|
|
|
2021-06-16 19:28:00 +00:00
|
|
|
char tempPixel = 0; // just need a valid address (not a valid size)
|
|
|
|
SkPixmap pmap = { info, &tempPixel, rowBytes };
|
2018-02-07 21:05:29 +00:00
|
|
|
img = SkImage::MakeFromRaster(pmap, nullptr, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, img != nullptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-29 15:29:58 +00:00
|
|
|
const int32_t sizes[] = { -1, 0, 1, 1 << 18 };
|
2018-02-16 15:08:10 +00:00
|
|
|
for (int cti = 0; cti <= kLastEnum_SkColorType; ++cti) {
|
2018-02-07 21:05:29 +00:00
|
|
|
SkColorType ct = static_cast<SkColorType>(cti);
|
2018-02-16 15:08:10 +00:00
|
|
|
for (int ati = 0; ati <= kLastEnum_SkAlphaType; ++ati) {
|
2018-02-07 21:05:29 +00:00
|
|
|
SkAlphaType at = static_cast<SkAlphaType>(ati);
|
|
|
|
for (int32_t size : sizes) {
|
|
|
|
do_test(SkImageInfo::Make(1, size, ct, at));
|
|
|
|
do_test(SkImageInfo::Make(size, 1, ct, at));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|