aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ImageTest.cpp
diff options
context:
space:
mode:
authorGravatar kkinnunen <kkinnunen@nvidia.com>2015-11-20 13:32:24 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-20 13:32:25 -0800
commit179a8f5f7feab052e24596d0d04ab5cf2ccab5e0 (patch)
tree2166ef66f2ac9a543cbd7ede7dd6c53f8f8f2e04 /tests/ImageTest.cpp
parent211df380655d3fd0c76b9b7f8be399040ca0b7a5 (diff)
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
Diffstat (limited to 'tests/ImageTest.cpp')
-rw-r--r--tests/ImageTest.cpp70
1 files changed, 0 insertions, 70 deletions
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index d139ca7075..7bce8e5a5d 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -415,60 +415,6 @@ struct ReleaseDataContext {
}
};
-// May we (soon) eliminate the need to keep testing this, by hiding the bloody device!
-#include "SkDevice.h"
-static uint32_t get_legacy_gen_id(SkSurface* surf) {
- SkBaseDevice* device = surf->getCanvas()->getDevice_just_for_deprecated_compatibility_testing();
- return device->accessBitmap(false).getGenerationID();
-}
-
-/*
- * Test legacy behavor of bumping the surface's device's bitmap's genID when we access its
- * texture handle for writing.
- *
- * Note: this needs to be tested separately from checking newImageSnapshot, as calling that
- * can also incidentally bump the genID (when a new backing surface is created).
- */
-template <class F>
-static void test_texture_handle_genID(skiatest::Reporter* reporter, SkSurface* surf, F f) {
- const uint32_t gen0 = get_legacy_gen_id(surf);
- f(surf, SkSurface::kFlushRead_BackendHandleAccess);
- const uint32_t gen1 = get_legacy_gen_id(surf);
- REPORTER_ASSERT(reporter, gen0 == gen1);
-
- f(surf, SkSurface::kFlushWrite_BackendHandleAccess);
- const uint32_t gen2 = get_legacy_gen_id(surf);
- REPORTER_ASSERT(reporter, gen0 != gen2);
-
- f(surf, SkSurface::kDiscardWrite_BackendHandleAccess);
- const uint32_t gen3 = get_legacy_gen_id(surf);
- REPORTER_ASSERT(reporter, gen0 != gen3);
- REPORTER_ASSERT(reporter, gen2 != gen3);
-}
-
-template <class F>
-static void test_backend_handle(skiatest::Reporter* reporter, SkSurface* surf, F f) {
- SkAutoTUnref<SkImage> image0(surf->newImageSnapshot());
- GrBackendObject obj = f(surf, SkSurface::kFlushRead_BackendHandleAccess);
- REPORTER_ASSERT(reporter, obj != 0);
- SkAutoTUnref<SkImage> image1(surf->newImageSnapshot());
- // just read access should not affect the snapshot
- REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID());
-
- obj = f(surf, SkSurface::kFlushWrite_BackendHandleAccess);
- REPORTER_ASSERT(reporter, obj != 0);
- SkAutoTUnref<SkImage> image2(surf->newImageSnapshot());
- // expect a new image, since we claimed we would write
- REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID());
-
- obj = f(surf, SkSurface::kDiscardWrite_BackendHandleAccess);
- REPORTER_ASSERT(reporter, obj != 0);
- SkAutoTUnref<SkImage> image3(surf->newImageSnapshot());
- // 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());
-}
-
static SkImage* create_image(skiatest::Reporter* reporter,
ImageType imageType, GrContext* context, SkColor color,
ReleaseDataContext* releaseContext) {
@@ -495,22 +441,6 @@ static SkImage* create_image(skiatest::Reporter* reporter,
SkAutoTUnref<SkSurface> surf(
SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0));
surf->getCanvas()->clear(color);
- // test our backing texture / rendertarget while were here...
- auto textureAccessorFunc =
- [](SkSurface* surf, SkSurface::BackendHandleAccess access) -> GrBackendObject {
- return surf->getTextureHandle(access); };
- auto renderTargetAccessorFunc =
- [](SkSurface* surf, SkSurface::BackendHandleAccess access) -> GrBackendObject {
- GrBackendObject obj;
- SkAssertResult(surf->getRenderTargetHandle(&obj, access));
- return obj; };
- test_backend_handle(reporter, surf, textureAccessorFunc);
- test_backend_handle(reporter, surf, renderTargetAccessorFunc);
- test_texture_handle_genID(reporter, surf, textureAccessorFunc);
- test_texture_handle_genID(reporter, surf, renderTargetAccessorFunc);
-
- // redraw so our returned image looks as expected.
- surf->getCanvas()->clear(color);
return surf->newImageSnapshot();
}
case kCodec_ImageType: {