From 6451a0cea6007aff54565ec82e2f86cb1d32ecc7 Mon Sep 17 00:00:00 2001 From: robertphillips Date: Mon, 18 Jul 2016 08:31:31 -0700 Subject: Add makeSpecial calls to SkGpuDevice GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2161533003 Review-Url: https://codereview.chromium.org/2161533003 --- tests/DeviceTest.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 tests/DeviceTest.cpp (limited to 'tests/DeviceTest.cpp') diff --git a/tests/DeviceTest.cpp b/tests/DeviceTest.cpp new file mode 100644 index 0000000000..d6bd1bfe47 --- /dev/null +++ b/tests/DeviceTest.cpp @@ -0,0 +1,124 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkBitmapDevice.h" +#include "SkDevice.h" +#include "SkSpecialImage.h" + +#if SK_SUPPORT_GPU +#include "SkGpuDevice.h" +#endif + +#include "Test.h" + +class DeviceTestingAccess { +public: + static sk_sp MakeSpecial(SkBaseDevice* dev, const SkBitmap& bm) { + return dev->makeSpecial(bm); + } + + static sk_sp MakeSpecial(SkBaseDevice* dev, SkImage* img) { + return dev->makeSpecial(img); + } + + static sk_sp SnapSpecial(SkBaseDevice* dev) { + return dev->snapSpecial(); + } +}; + +// TODO: re-enable this when Raster methods are implemented +#if 0 +DEF_TEST(SpecialImage_BitmapDevice, reporter) { + static const int kWidth = 100; + static const int kHeight = 90; + + SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight); + + SkAutoTUnref bmDev(SkBitmapDevice::Create(ii)); + + SkBitmap bm; + bm.tryAllocN32Pixels(kWidth, kHeight); + + // Create a raster-backed special image from a raster-backed SkBitmap + sk_sp special = DeviceTestingAccess::MakeSpecial(bmDev.get(), bm); + SkASSERT(!special->isTextureBacked()); + SkASSERT(kWidth == special->width()); + SkASSERT(kHeight == special->height()); + SkASSERT(bm.getGenerationID() == special->uniqueID()); + SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset()); + + // Create a raster-backed special image from a raster-backed SkImage + sk_sp image(SkImage::MakeFromBitmap(bm)); + special = DeviceTestingAccess::MakeSpecial(bmDev.get(), image.get()); + SkASSERT(!special->isTextureBacked()); + SkASSERT(kWidth == special->width()); + SkASSERT(kHeight == special->height()); + SkASSERT(bm.getGenerationID() == special->uniqueID()); + SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset()); + + // Snap the device as a raster-backed special image + special = DeviceTestingAccess::SnapSpecial(bmDev.get()); + SkASSERT(!special->isTextureBacked()); + SkASSERT(2*kWidth == special->width()); + SkASSERT(2*kHeight == special->height()); + SkASSERT(SkIRect::MakeWH(2*kWidth, 2*kHeight) == special->subset()); +} +#endif + + +#if SK_SUPPORT_GPU + +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_GPUDevice, reporter, ctxInfo) { + GrContext* context = ctxInfo.grContext(); + + static const int kWidth = 100; + static const int kHeight = 90; + + SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight); + + sk_sp gpuDev(SkGpuDevice::Make(context, SkBudgeted::kNo, ii, + 0, nullptr, SkGpuDevice::kClear_InitContents)); + + SkBitmap bm; + SkAssertResult(bm.tryAllocN32Pixels(kWidth, kHeight)); + + // Create a gpu-backed special image from a raster-backed SkBitmap + sk_sp special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), bm); + SkASSERT(special->isTextureBacked()); + SkASSERT(kWidth == special->width()); + SkASSERT(kHeight == special->height()); + SkASSERT(bm.getGenerationID() == special->uniqueID()); + SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset()); + + // Create a gpu-backed special image from a raster-backed SkImage + sk_sp image(SkImage::MakeFromBitmap(bm)); + special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), image.get()); + SkASSERT(special->isTextureBacked()); + SkASSERT(kWidth == special->width()); + SkASSERT(kHeight == special->height()); + // TODO: Hmmm, this is a bit unexpected + SkASSERT(image->uniqueID() != special->uniqueID()); + SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset()); + + // Create a gpu-backed special image from a gpu-backed SkImage + image = image->makeTextureImage(context); + special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), image.get()); + SkASSERT(special->isTextureBacked()); + SkASSERT(kWidth == special->width()); + SkASSERT(kHeight == special->height()); + SkASSERT(image->uniqueID() == special->uniqueID()); + SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset()); + + // Snap the device as a gpu-backed special image + special = DeviceTestingAccess::SnapSpecial(gpuDev.get()); + SkASSERT(special->isTextureBacked()); + SkASSERT(2*kWidth == special->width()); + SkASSERT(2*kHeight == special->height()); + SkASSERT(SkIRect::MakeWH(2*kWidth, 2*kHeight) == special->subset()); +} + +#endif -- cgit v1.2.3