skia2/tests/DeviceTest.cpp
Brian Salomon 3a2cc2c2ec Revert "Revert "Revert "Revert "Revert "Redefine the meaning of sample counts in GPU backend."""""
This reverts commit 5bb82cbecd.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> Revert "Revert "Revert "Revert "Redefine the meaning of sample counts in GPU backend.""""
> 
> This reverts commit 18c52a7b52.
> 
> Also relands "More sample count cleanup:" and "Add new GrContext queries for imagability, surfacability, and max sample count of color types"
> 
> 
> Bug: skia:
> Change-Id: I4028105a3a1f16ce3944e134619eb6245af6b947
> Reviewed-on: https://skia-review.googlesource.com/102940
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>

TBR=egdaniel@google.com,bsalomon@google.com

Change-Id: Idee23be2f1719f0bdc9305043e95a2d589bee8d1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/103220
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2018-02-03 00:25:20 +00:00

128 lines
4.6 KiB
C++

/*
* 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<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);
sk_sp<SkBaseDevice> bmDev(SkBitmapDevice::Create(ii));
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
#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<SkBaseDevice> gpuDev(SkGpuDevice::Make(context, SkBudgeted::kNo, ii,
0, kBottomLeft_GrSurfaceOrigin, nullptr,
GrMipMapped::kNo,
SkGpuDevice::kClear_InitContents));
SkBitmap bm;
SkAssertResult(bm.tryAllocN32Pixels(kWidth, kHeight));
// Create a gpu-backed special image from a raster-backed SkBitmap
sk_sp<SkSpecialImage> 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<SkImage> 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
SkColorSpace* legacyColorSpace = nullptr;
image = image->makeTextureImage(context, legacyColorSpace);
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