2016-07-18 15:31:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
|
|
|
#include "src/core/SkDevice.h"
|
|
|
|
#include "src/core/SkSpecialImage.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2016-07-18 15:31:31 +00:00
|
|
|
|
2018-09-19 15:31:27 +00:00
|
|
|
class SkColorSpace;
|
2016-07-18 15:31:31 +00:00
|
|
|
|
|
|
|
class DeviceTestingAccess {
|
|
|
|
public:
|
|
|
|
static sk_sp<SkSpecialImage> MakeSpecial(SkBaseDevice* dev, const SkBitmap& bm) {
|
|
|
|
return dev->makeSpecial(bm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkSpecialImage> MakeSpecial(SkBaseDevice* dev, SkImage* img) {
|
|
|
|
return dev->makeSpecial(img);
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkSpecialImage> 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);
|
|
|
|
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<SkBaseDevice> bmDev(SkBitmapDevice::Create(ii));
|
2016-07-18 15:31:31 +00:00
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.tryAllocN32Pixels(kWidth, kHeight);
|
|
|
|
|
|
|
|
// Create a raster-backed special image from a raster-backed SkBitmap
|
|
|
|
sk_sp<SkSpecialImage> 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<SkImage> 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
|
|
|
|
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_GPUDevice, reporter, ctxInfo) {
|
2021-06-04 20:37:30 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2016-07-18 15:31:31 +00:00
|
|
|
|
|
|
|
static const int kWidth = 100;
|
|
|
|
static const int kHeight = 90;
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight);
|
|
|
|
|
2021-06-04 20:37:30 +00:00
|
|
|
auto device = dContext->priv().createDevice(SkBudgeted::kNo, ii, SkBackingFit::kExact,
|
|
|
|
1, GrMipmapped::kNo, GrProtected::kNo,
|
|
|
|
kBottomLeft_GrSurfaceOrigin, SkSurfaceProps(),
|
2021-09-07 20:10:34 +00:00
|
|
|
skgpu::BaseDevice::InitContents::kClear);
|
2016-07-18 15:31:31 +00:00
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
SkAssertResult(bm.tryAllocN32Pixels(kWidth, kHeight));
|
|
|
|
|
|
|
|
// Create a gpu-backed special image from a raster-backed SkBitmap
|
2021-06-04 20:37:30 +00:00
|
|
|
sk_sp<SkSpecialImage> special = DeviceTestingAccess::MakeSpecial(device.get(), bm);
|
2016-07-18 15:31:31 +00:00
|
|
|
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
|
2020-12-23 16:50:36 +00:00
|
|
|
sk_sp<SkImage> image(bm.asImage());
|
2021-06-04 20:37:30 +00:00
|
|
|
special = DeviceTestingAccess::MakeSpecial(device.get(), image.get());
|
2016-07-18 15:31:31 +00:00
|
|
|
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
|
2021-06-04 20:37:30 +00:00
|
|
|
image = image->makeTextureImage(dContext);
|
|
|
|
special = DeviceTestingAccess::MakeSpecial(device.get(), image.get());
|
2016-07-18 15:31:31 +00:00
|
|
|
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
|
2021-06-04 20:37:30 +00:00
|
|
|
special = DeviceTestingAccess::SnapSpecial(device.get());
|
2016-07-18 15:31:31 +00:00
|
|
|
SkASSERT(special->isTextureBacked());
|
|
|
|
SkASSERT(2*kWidth == special->width());
|
|
|
|
SkASSERT(2*kHeight == special->height());
|
|
|
|
SkASSERT(SkIRect::MakeWH(2*kWidth, 2*kHeight) == special->subset());
|
|
|
|
}
|