2020-07-10 18:33:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
DEF_GPUTEST(GrDDLImage_MakeSubset, reporter, options) {
|
|
|
|
sk_gpu_test::GrContextFactory factory(options);
|
|
|
|
for (int ct = 0; ct < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++ct) {
|
|
|
|
auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(ct);
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = factory.get(contextType);
|
|
|
|
if (!dContext) {
|
2020-07-10 18:33:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkIRect subsetBounds = SkIRect::MakeLTRB(4,4,8,8);
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(16, 16, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
|
|
|
// Raster image:
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.setInfo(ii);
|
|
|
|
bm.allocPixels();
|
|
|
|
bm.eraseColor(SK_ColorBLACK);
|
|
|
|
bm.setImmutable();
|
|
|
|
auto rasterImg = SkImage::MakeFromBitmap(bm);
|
|
|
|
REPORTER_ASSERT(reporter, rasterImg->isValid(static_cast<GrRecordingContext*>(nullptr)));
|
|
|
|
|
|
|
|
// raster + context:
|
2020-08-11 15:48:49 +00:00
|
|
|
auto subImg1 = rasterImg->makeSubset(subsetBounds, dContext);
|
|
|
|
REPORTER_ASSERT(reporter, subImg1->isValid(dContext));
|
2020-07-10 18:33:22 +00:00
|
|
|
|
|
|
|
// raster + no context:
|
|
|
|
auto subImg2 = rasterImg->makeSubset(subsetBounds, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, subImg2->isValid(static_cast<GrRecordingContext*>(nullptr)));
|
|
|
|
|
|
|
|
// Texture image:
|
2020-08-11 15:48:49 +00:00
|
|
|
auto surf = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii);
|
2020-07-10 18:33:22 +00:00
|
|
|
SkSurfaceCharacterization sc;
|
|
|
|
REPORTER_ASSERT(reporter, surf->characterize(&sc));
|
2020-08-26 20:33:54 +00:00
|
|
|
GrBackendTexture tex =
|
|
|
|
dContext->createBackendTexture(ii.width(), ii.height(), ii.colorType(),
|
|
|
|
GrMipmapped(sc.isMipMapped()), GrRenderable::kYes);
|
2020-08-11 15:48:49 +00:00
|
|
|
auto gpuImage = SkImage::MakeFromTexture(dContext, tex, kTopLeft_GrSurfaceOrigin,
|
2020-07-10 18:33:22 +00:00
|
|
|
ii.colorType(), ii.alphaType(),
|
|
|
|
ii.refColorSpace());
|
2020-08-11 15:48:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, gpuImage->isValid(dContext));
|
2020-07-10 18:33:22 +00:00
|
|
|
|
|
|
|
// gpu image + context:
|
2020-08-11 15:48:49 +00:00
|
|
|
auto subImg5 = gpuImage->makeSubset(subsetBounds, dContext);
|
|
|
|
REPORTER_ASSERT(reporter, subImg5->isValid(dContext));
|
2020-07-10 18:33:22 +00:00
|
|
|
|
|
|
|
// gpu image + nullptr:
|
|
|
|
REPORTER_ASSERT(reporter, !gpuImage->makeSubset(subsetBounds, nullptr));
|
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
dContext->flush();
|
|
|
|
dContext->submit(true);
|
|
|
|
dContext->deleteBackendTexture(tex);
|
2020-07-10 18:33:22 +00:00
|
|
|
}
|
|
|
|
}
|