Make GrSurfaceContext take GrColorInfo rather than its components.
Bug: skia:11019 Change-Id: I0446e3565c892cddaaeb13d9a8379e144c0ea8ea Reviewed-on: https://skia-review.googlesource.com/c/skia/+/341419 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
4159ecbca9
commit
14f99fc2f3
@ -551,9 +551,10 @@ std::unique_ptr<GrRenderTargetContext> GaussianBlur(GrRecordingContext* context,
|
||||
sigmaX *= scaleX;
|
||||
sigmaY *= scaleY;
|
||||
|
||||
auto srcCtx = GrSurfaceContext::Make(context, srcView, srcColorType, srcAlphaType, colorSpace);
|
||||
GrColorInfo colorInfo(srcColorType, srcAlphaType, colorSpace);
|
||||
auto srcCtx = GrSurfaceContext::Make(context, srcView, colorInfo);
|
||||
SkASSERT(srcCtx);
|
||||
GrImageInfo rescaledII(srcColorType, srcAlphaType, colorSpace, rescaledSize);
|
||||
GrImageInfo rescaledII(colorInfo, rescaledSize);
|
||||
srcCtx = srcCtx->rescale(rescaledII, srcCtx->origin(), srcBounds, SkSurface::RescaleGamma::kSrc,
|
||||
kLow_SkFilterQuality);
|
||||
if (!srcCtx) {
|
||||
|
@ -328,8 +328,9 @@ GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context,
|
||||
sk_sp<SkColorSpace> colorSpace,
|
||||
const SkSurfaceProps* surfaceProps,
|
||||
bool flushTimeOpsTask)
|
||||
: GrSurfaceContext(context, std::move(readView), colorType, kPremul_SkAlphaType,
|
||||
std::move(colorSpace))
|
||||
: GrSurfaceContext(context,
|
||||
std::move(readView),
|
||||
{colorType, kPremul_SkAlphaType, std::move(colorSpace)})
|
||||
, fWriteView(std::move(writeView))
|
||||
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
|
||||
, fFlushTimeOpsTask(flushTimeOpsTask)
|
||||
|
@ -31,9 +31,7 @@
|
||||
|
||||
std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
|
||||
GrSurfaceProxyView readView,
|
||||
GrColorType colorType,
|
||||
SkAlphaType alphaType,
|
||||
sk_sp<SkColorSpace> colorSpace) {
|
||||
const GrColorInfo& info) {
|
||||
// It is probably not necessary to check if the context is abandoned here since uses of the
|
||||
// GrSurfaceContext which need the context will mostly likely fail later on without an issue.
|
||||
// However having this hear adds some reassurance in case there is a path doesn't handle an
|
||||
@ -46,54 +44,87 @@ std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* con
|
||||
|
||||
std::unique_ptr<GrSurfaceContext> surfaceContext;
|
||||
if (proxy->asRenderTargetProxy()) {
|
||||
SkASSERT(kPremul_SkAlphaType == alphaType || kOpaque_SkAlphaType == alphaType);
|
||||
SkASSERT(info.alphaType() == kPremul_SkAlphaType ||
|
||||
info.alphaType() == kOpaque_SkAlphaType);
|
||||
// Will we ever want a swizzle that is not the default write swizzle for the format and
|
||||
// colorType here? If so we will need to manually pass that in.
|
||||
GrSwizzle writeSwizzle;
|
||||
if (colorType != GrColorType::kUnknown) {
|
||||
writeSwizzle =
|
||||
context->priv().caps()->getWriteSwizzle(proxy->backendFormat(), colorType);
|
||||
if (info.colorType() != GrColorType::kUnknown) {
|
||||
writeSwizzle = context->priv().caps()->getWriteSwizzle(proxy->backendFormat(),
|
||||
info.colorType());
|
||||
}
|
||||
GrSurfaceProxyView writeView(readView.refProxy(), readView.origin(), writeSwizzle);
|
||||
surfaceContext = std::make_unique<GrRenderTargetContext>(context, std::move(readView),
|
||||
std::move(writeView), colorType,
|
||||
std::move(colorSpace), nullptr);
|
||||
surfaceContext = std::make_unique<GrRenderTargetContext>(context,
|
||||
std::move(readView),
|
||||
std::move(writeView),
|
||||
info.colorType(),
|
||||
info.refColorSpace(),
|
||||
/*surface props*/ nullptr);
|
||||
} else {
|
||||
surfaceContext = std::make_unique<GrSurfaceContext>(context, std::move(readView), colorType,
|
||||
alphaType, std::move(colorSpace));
|
||||
surfaceContext = std::make_unique<GrSurfaceContext>(context, std::move(readView), info);
|
||||
}
|
||||
SkDEBUGCODE(surfaceContext->validate();)
|
||||
return surfaceContext;
|
||||
}
|
||||
|
||||
std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
|
||||
SkISize dimensions,
|
||||
const GrImageInfo& info,
|
||||
const GrBackendFormat& format,
|
||||
GrRenderable renderable,
|
||||
int renderTargetSampleCnt,
|
||||
GrMipmapped mipMapped,
|
||||
GrProtected isProtected,
|
||||
GrSurfaceOrigin origin,
|
||||
GrColorType colorType,
|
||||
SkAlphaType alphaType,
|
||||
sk_sp<SkColorSpace> colorSpace,
|
||||
SkBackingFit fit,
|
||||
GrSurfaceOrigin origin,
|
||||
GrRenderable renderable,
|
||||
int sampleCount,
|
||||
GrMipmapped mipmapped,
|
||||
GrProtected isProtected,
|
||||
SkBudgeted budgeted) {
|
||||
GrSwizzle swizzle;
|
||||
if (colorType != GrColorType::kUnknown && !context->priv().caps()->isFormatCompressed(format)) {
|
||||
swizzle = context->priv().caps()->getReadSwizzle(format, colorType);
|
||||
SkASSERT(context);
|
||||
SkASSERT(renderable == GrRenderable::kYes || sampleCount == 1);
|
||||
if (context->abandoned()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy(
|
||||
format, dimensions, renderable, renderTargetSampleCnt, mipMapped, fit, budgeted,
|
||||
isProtected);
|
||||
sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy(format,
|
||||
info.dimensions(),
|
||||
renderable,
|
||||
sampleCount,
|
||||
mipmapped,
|
||||
fit,
|
||||
budgeted,
|
||||
isProtected);
|
||||
if (!proxy) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrSwizzle swizzle;
|
||||
if (info.colorType() != GrColorType::kUnknown &&
|
||||
!context->priv().caps()->isFormatCompressed(format)) {
|
||||
swizzle = context->priv().caps()->getReadSwizzle(format, info.colorType());
|
||||
}
|
||||
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
return GrSurfaceContext::Make(context, std::move(view), colorType, alphaType,
|
||||
std::move(colorSpace));
|
||||
return GrSurfaceContext::Make(context, std::move(view), info.colorInfo());
|
||||
}
|
||||
|
||||
std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
|
||||
const GrImageInfo& info,
|
||||
SkBackingFit fit,
|
||||
GrSurfaceOrigin origin,
|
||||
GrRenderable renderable,
|
||||
int sampleCount,
|
||||
GrMipmapped mipmapped,
|
||||
GrProtected isProtected,
|
||||
SkBudgeted budgeted) {
|
||||
GrBackendFormat format = context->priv().caps()->getDefaultBackendFormat(info.colorType(),
|
||||
renderable);
|
||||
return Make(context,
|
||||
info,
|
||||
format,
|
||||
fit,
|
||||
origin,
|
||||
renderable,
|
||||
sampleCount,
|
||||
mipmapped,
|
||||
isProtected,
|
||||
budgeted);
|
||||
}
|
||||
|
||||
// In MDB mode the reffing of the 'getLastOpsTask' call's result allows in-progress
|
||||
@ -102,12 +133,8 @@ std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* con
|
||||
// when the renderTargetContext attempts to use it (via getOpsTask).
|
||||
GrSurfaceContext::GrSurfaceContext(GrRecordingContext* context,
|
||||
GrSurfaceProxyView readView,
|
||||
GrColorType colorType,
|
||||
SkAlphaType alphaType,
|
||||
sk_sp<SkColorSpace> colorSpace)
|
||||
: fContext(context)
|
||||
, fReadView(std::move(readView))
|
||||
, fColorInfo(colorType, alphaType, std::move(colorSpace)) {
|
||||
const GrColorInfo& info)
|
||||
: fContext(context), fReadView(std::move(readView)), fColorInfo(info) {
|
||||
SkASSERT(!context->abandoned());
|
||||
}
|
||||
|
||||
@ -264,11 +291,7 @@ bool GrSurfaceContext::readPixels(GrDirectContext* dContext, const GrImageInfo&
|
||||
return false;
|
||||
}
|
||||
GrSurfaceProxyView view{std::move(copy), this->origin(), this->readSwizzle()};
|
||||
tempCtx = GrSurfaceContext::Make(dContext,
|
||||
std::move(view),
|
||||
this->colorInfo().colorType(),
|
||||
this->colorInfo().alphaType(),
|
||||
this->colorInfo().refColorSpace());
|
||||
tempCtx = GrSurfaceContext::Make(dContext, std::move(view), this->colorInfo());
|
||||
SkASSERT(tempCtx);
|
||||
}
|
||||
return tempCtx->readPixels(dContext, dstInfo, dst, rowBytes, pt);
|
||||
@ -387,22 +410,20 @@ bool GrSurfaceContext::writePixels(GrDirectContext* dContext, const GrImageInfo&
|
||||
dContext->priv().validPMUPMConversionExists();
|
||||
|
||||
if (!caps->surfaceSupportsWritePixels(dstSurface) || canvas2DFastPath) {
|
||||
GrColorType colorType;
|
||||
|
||||
GrColorInfo tempColorInfo;
|
||||
GrBackendFormat format;
|
||||
SkAlphaType alphaType;
|
||||
GrSwizzle tempReadSwizzle;
|
||||
if (canvas2DFastPath) {
|
||||
colorType = GrColorType::kRGBA_8888;
|
||||
tempColorInfo = {GrColorType::kRGBA_8888,
|
||||
kUnpremul_SkAlphaType,
|
||||
this->colorInfo().refColorSpace()};
|
||||
format = rgbaDefaultFormat;
|
||||
alphaType = kUnpremul_SkAlphaType;
|
||||
} else {
|
||||
colorType = this->colorInfo().colorType();
|
||||
tempColorInfo = this->colorInfo();
|
||||
format = dstProxy->backendFormat().makeTexture2D();
|
||||
if (!format.isValid()) {
|
||||
return false;
|
||||
}
|
||||
alphaType = this->colorInfo().alphaType();
|
||||
tempReadSwizzle = this->readSwizzle();
|
||||
}
|
||||
|
||||
@ -420,8 +441,7 @@ bool GrSurfaceContext::writePixels(GrDirectContext* dContext, const GrImageInfo&
|
||||
return false;
|
||||
}
|
||||
GrSurfaceProxyView tempView(tempProxy, tempOrigin, tempReadSwizzle);
|
||||
GrSurfaceContext tempCtx(dContext, tempView, colorType, alphaType,
|
||||
this->colorInfo().refColorSpace());
|
||||
GrSurfaceContext tempCtx(dContext, tempView, tempColorInfo);
|
||||
|
||||
// In the fast path we always write the srcData to the temp context as though it were RGBA.
|
||||
// When the data is really BGRA the write will cause the R and B channels to be swapped in
|
||||
@ -438,13 +458,13 @@ bool GrSurfaceContext::writePixels(GrDirectContext* dContext, const GrImageInfo&
|
||||
std::unique_ptr<GrFragmentProcessor> fp;
|
||||
if (canvas2DFastPath) {
|
||||
fp = dContext->priv().createUPMToPMEffect(
|
||||
GrTextureEffect::Make(std::move(tempView), alphaType));
|
||||
GrTextureEffect::Make(std::move(tempView), tempColorInfo.alphaType()));
|
||||
// Important: check the original src color type here!
|
||||
if (origSrcInfo.colorType() == GrColorType::kBGRA_8888) {
|
||||
fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA());
|
||||
}
|
||||
} else {
|
||||
fp = GrTextureEffect::Make(std::move(tempView), alphaType);
|
||||
fp = GrTextureEffect::Make(std::move(tempView), tempColorInfo.alphaType());
|
||||
}
|
||||
if (!fp) {
|
||||
return false;
|
||||
|
@ -41,19 +41,33 @@ public:
|
||||
// otherwise it will return a GrSurfaceContext.
|
||||
static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*,
|
||||
GrSurfaceProxyView readView,
|
||||
GrColorType, SkAlphaType, sk_sp<SkColorSpace>);
|
||||
const GrColorInfo&);
|
||||
|
||||
static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*, SkISize dimensions,
|
||||
const GrBackendFormat&, GrRenderable,
|
||||
int renderTargetSampleCnt, GrMipmapped,
|
||||
GrProtected, GrSurfaceOrigin, GrColorType,
|
||||
SkAlphaType, sk_sp<SkColorSpace>, SkBackingFit,
|
||||
SkBudgeted);
|
||||
// Makes either a GrSurfaceContext or a GrRenderTargetContext, depending on GrRenderable.
|
||||
static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*,
|
||||
const GrImageInfo&,
|
||||
const GrBackendFormat&,
|
||||
SkBackingFit = SkBackingFit::kExact,
|
||||
GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
|
||||
GrRenderable = GrRenderable::kNo,
|
||||
int renderTargetSampleCnt = 1,
|
||||
GrMipmapped = GrMipmapped::kNo,
|
||||
GrProtected = GrProtected::kNo,
|
||||
SkBudgeted = SkBudgeted::kYes);
|
||||
|
||||
static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*,
|
||||
const GrImageInfo&,
|
||||
SkBackingFit = SkBackingFit::kExact,
|
||||
GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
|
||||
GrRenderable = GrRenderable::kNo,
|
||||
int renderTargetSampleCnt = 1,
|
||||
GrMipmapped = GrMipmapped::kNo,
|
||||
GrProtected = GrProtected::kNo,
|
||||
SkBudgeted = SkBudgeted::kYes);
|
||||
|
||||
// If it is known that the GrSurfaceProxy is not renderable, you can directly call the the ctor
|
||||
// here to make a GrSurfaceContext on the stack.
|
||||
GrSurfaceContext(GrRecordingContext*, GrSurfaceProxyView readView, GrColorType, SkAlphaType,
|
||||
sk_sp<SkColorSpace>);
|
||||
GrSurfaceContext(GrRecordingContext*, GrSurfaceProxyView readView, const GrColorInfo&);
|
||||
|
||||
virtual ~GrSurfaceContext() = default;
|
||||
|
||||
|
@ -275,10 +275,17 @@ sk_sp<GrSurfaceProxy> GrSurfaceProxy::Copy(GrRecordingContext* context,
|
||||
SkASSERT(format.isValid());
|
||||
|
||||
if (src->backendFormat().textureType() != GrTextureType::kExternal) {
|
||||
auto dstContext =
|
||||
GrSurfaceContext::Make(context, {width, height}, format, GrRenderable::kNo, 1,
|
||||
mipMapped, src->isProtected(), origin, GrColorType::kUnknown,
|
||||
kUnknown_SkAlphaType, nullptr, fit, budgeted);
|
||||
GrImageInfo info(GrColorType::kUnknown, kUnknown_SkAlphaType, nullptr, {width, height});
|
||||
auto dstContext = GrSurfaceContext::Make(context,
|
||||
info,
|
||||
format,
|
||||
fit,
|
||||
origin,
|
||||
GrRenderable::kNo,
|
||||
1,
|
||||
mipMapped,
|
||||
src->isProtected(),
|
||||
budgeted);
|
||||
if (dstContext && dstContext->copy(src, srcRect, dstPoint)) {
|
||||
return dstContext->asSurfaceProxyRef();
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ public:
|
||||
*/
|
||||
GrSurfaceProxyView view(GrMipmapped);
|
||||
|
||||
const GrColorInfo& colorInfo() const { return fImageInfo.colorInfo(); }
|
||||
int width() const { return fImageInfo.width(); }
|
||||
int height() const { return fImageInfo.height(); }
|
||||
SkISize dimensions() const { return fImageInfo.dimensions(); }
|
||||
|
@ -234,8 +234,9 @@ static bool save_pixels(GrDirectContext* dContext, GrSurfaceProxyView view, GrCo
|
||||
return false;
|
||||
}
|
||||
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), colorType,
|
||||
kUnknown_SkAlphaType, nullptr);
|
||||
auto sContext = GrSurfaceContext::Make(dContext,
|
||||
std::move(view),
|
||||
{colorType, kUnknown_SkAlphaType, nullptr});
|
||||
if (!sContext || !sContext->asTextureProxy()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -135,9 +135,7 @@ void SkImage_Gpu::onAsyncRescaleAndReadPixels(const SkImageInfo& info,
|
||||
callback(context, nullptr);
|
||||
return;
|
||||
}
|
||||
GrColorType ct = SkColorTypeToGrColorType(this->colorType());
|
||||
auto ctx = GrSurfaceContext::Make(dContext, fView, ct, this->alphaType(),
|
||||
this->refColorSpace());
|
||||
auto ctx = GrSurfaceContext::Make(dContext, fView, this->imageInfo().colorInfo());
|
||||
if (!ctx) {
|
||||
callback(context, nullptr);
|
||||
return;
|
||||
@ -160,9 +158,7 @@ void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpac
|
||||
callback(context, nullptr);
|
||||
return;
|
||||
}
|
||||
GrColorType ct = SkColorTypeToGrColorType(this->colorType());
|
||||
auto ctx = GrSurfaceContext::Make(dContext, fView, ct, this->alphaType(),
|
||||
this->refColorSpace());
|
||||
auto ctx = GrSurfaceContext::Make(dContext, fView, this->imageInfo().colorInfo());
|
||||
if (!ctx) {
|
||||
callback(context, nullptr);
|
||||
return;
|
||||
@ -609,13 +605,14 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrDirectContext* dContex
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<SkColorSpace> cs = pixmap.refColorSpace();
|
||||
SkAlphaType at = pixmap.alphaType();
|
||||
|
||||
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(backendFormat, grColorType);
|
||||
GrSurfaceProxyView view(std::move(proxy), surfaceOrigin, swizzle);
|
||||
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext), kNeedNewImageUniqueID, view,
|
||||
colorType, at, cs);
|
||||
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext),
|
||||
kNeedNewImageUniqueID,
|
||||
view,
|
||||
colorType,
|
||||
pixmap.alphaType(),
|
||||
pixmap.refColorSpace());
|
||||
if (!image) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -625,13 +622,9 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrDirectContext* dContex
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrSurfaceContext surfaceContext(dContext, std::move(view),
|
||||
SkColorTypeToGrColorType(pixmap.colorType()),
|
||||
pixmap.alphaType(), cs);
|
||||
GrSurfaceContext surfaceContext(dContext, std::move(view), image->imageInfo().colorInfo());
|
||||
|
||||
SkImageInfo srcInfo = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, at,
|
||||
std::move(cs));
|
||||
surfaceContext.writePixels(dContext, srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
|
||||
surfaceContext.writePixels(dContext, pixmap.info(), pixmap.addr(), pixmap.rowBytes(), {0, 0});
|
||||
|
||||
GrSurfaceProxy* p[1] = {surfaceContext.asSurfaceProxy()};
|
||||
drawingManager->flush(p, SkSurface::BackendSurfaceAccess::kNoAccess, {}, nullptr);
|
||||
|
@ -118,8 +118,9 @@ bool SkImage_GpuBase::getROPixels(GrDirectContext* dContext,
|
||||
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
|
||||
fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
|
||||
|
||||
auto sContext = GrSurfaceContext::Make(dContext, *view, grColorType, this->alphaType(),
|
||||
this->refColorSpace());
|
||||
auto sContext = GrSurfaceContext::Make(dContext,
|
||||
*view,
|
||||
{grColorType, this->alphaType(), this->refColorSpace()});
|
||||
if (!sContext) {
|
||||
return false;
|
||||
}
|
||||
@ -174,8 +175,8 @@ bool SkImage_GpuBase::onReadPixels(GrDirectContext* dContext,
|
||||
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
|
||||
dContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
|
||||
|
||||
auto sContext = GrSurfaceContext::Make(dContext, *view, grColorType, this->alphaType(),
|
||||
this->refColorSpace());
|
||||
GrColorInfo colorInfo(grColorType, this->alphaType(), this->refColorSpace());
|
||||
auto sContext = GrSurfaceContext::Make(dContext, *view, colorInfo);
|
||||
if (!sContext) {
|
||||
return false;
|
||||
}
|
||||
|
@ -105,11 +105,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType());
|
||||
auto dstContext = GrSurfaceContext::Make(dContext,
|
||||
std::move(dstView),
|
||||
grColorType,
|
||||
ii.alphaType(), nullptr);
|
||||
ii.colorInfo());
|
||||
|
||||
bool result = false;
|
||||
if (sOrigin == dOrigin) {
|
||||
|
@ -151,8 +151,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
|
||||
// Wrap this texture ID in a GrTexture
|
||||
GrBackendTexture backendTex(kSize, kSize, GrMipmapped::kNo, externalTexture);
|
||||
|
||||
GrColorType colorType = GrColorType::kRGBA_8888;
|
||||
SkAlphaType alphaType = kPremul_SkAlphaType;
|
||||
GrColorInfo colorInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr);
|
||||
// TODO: If I make this TopLeft origin to match resolve_origin calls for kDefault, this test
|
||||
// fails on the Nexus5. Why?
|
||||
GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin;
|
||||
@ -163,11 +162,10 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
|
||||
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image);
|
||||
return;
|
||||
}
|
||||
GrSwizzle swizzle =
|
||||
context0->priv().caps()->getReadSwizzle(texProxy->backendFormat(), colorType);
|
||||
GrSwizzle swizzle = context0->priv().caps()->getReadSwizzle(texProxy->backendFormat(),
|
||||
colorInfo.colorType());
|
||||
GrSurfaceProxyView view(std::move(texProxy), origin, swizzle);
|
||||
auto surfaceContext =
|
||||
GrSurfaceContext::Make(context0, std::move(view), colorType, alphaType, nullptr);
|
||||
auto surfaceContext = GrSurfaceContext::Make(context0, std::move(view), colorInfo);
|
||||
|
||||
if (!surfaceContext) {
|
||||
ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext.");
|
||||
@ -186,8 +184,14 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
|
||||
|
||||
// Should not be able to wrap as a RT
|
||||
{
|
||||
auto temp = GrRenderTargetContext::MakeFromBackendTexture(
|
||||
context0, colorType, nullptr, backendTex, 1, origin, nullptr, nullptr);
|
||||
auto temp = GrRenderTargetContext::MakeFromBackendTexture(context0,
|
||||
colorInfo.colorType(),
|
||||
/*color space*/ nullptr,
|
||||
backendTex,
|
||||
1,
|
||||
origin,
|
||||
/*surface props*/ nullptr,
|
||||
/*release helper*/ nullptr);
|
||||
if (temp) {
|
||||
ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT.");
|
||||
}
|
||||
@ -200,8 +204,13 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
|
||||
|
||||
// Only test RT-config
|
||||
// TODO: why do we always need to draw to copy from an external texture?
|
||||
TestCopyFromSurface(reporter, context0, surfaceContext->asSurfaceProxy(),
|
||||
surfaceContext->origin(), colorType, pixels.get(), "EGLImageTest-copy");
|
||||
TestCopyFromSurface(reporter,
|
||||
context0,
|
||||
surfaceContext->asSurfaceProxy(),
|
||||
surfaceContext->origin(),
|
||||
colorInfo.colorType(),
|
||||
pixels.get(),
|
||||
"EGLImageTest-copy");
|
||||
|
||||
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image);
|
||||
}
|
||||
|
@ -49,22 +49,18 @@ void runFPTest(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
||||
}
|
||||
|
||||
for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
|
||||
GrImageInfo info(colorType, kPremul_SkAlphaType, nullptr, {DEV_W, DEV_H});
|
||||
auto fpView = sk_gpu_test::MakeTextureProxyViewFromData(
|
||||
dContext, GrRenderable::kYes, origin,
|
||||
{colorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H}, controlPixelData.begin(),
|
||||
0);
|
||||
dContext, GrRenderable::kYes, origin, info, controlPixelData.begin(), 0);
|
||||
// Floating point textures are NOT supported everywhere
|
||||
if (!fpView) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(fpView), colorType,
|
||||
kPremul_SkAlphaType, nullptr);
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(fpView), info.colorInfo());
|
||||
REPORTER_ASSERT(reporter, sContext);
|
||||
|
||||
bool result = sContext->readPixels(dContext,
|
||||
{colorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H},
|
||||
readBuffer.begin(), 0, {0, 0});
|
||||
bool result = sContext->readPixels(dContext, info, readBuffer.begin(), 0, {0, 0});
|
||||
REPORTER_ASSERT(reporter, result);
|
||||
REPORTER_ASSERT(reporter,
|
||||
!memcmp(readBuffer.begin(), controlPixelData.begin(), readBuffer.bytes()));
|
||||
|
@ -267,9 +267,8 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) {
|
||||
combo.fColorType);
|
||||
GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin,
|
||||
swizzle);
|
||||
auto texCtx = GrSurfaceContext::Make(dContext, std::move(view),
|
||||
combo.fColorType,
|
||||
kPremul_SkAlphaType, nullptr);
|
||||
GrColorInfo info(combo.fColorType, kPremul_SkAlphaType, nullptr);
|
||||
auto texCtx = GrSurfaceContext::Make(dContext, std::move(view), info);
|
||||
|
||||
readback.erase(kClearColor);
|
||||
if (texCtx->readPixels(
|
||||
@ -295,11 +294,11 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) {
|
||||
{desc.fWidth, desc.fHeight}, 1, GrMipmapped::kNo,
|
||||
GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
|
||||
} else {
|
||||
surfCtx = GrSurfaceContext::Make(
|
||||
dContext, {desc.fWidth, desc.fHeight}, combo.fFormat,
|
||||
GrRenderable::kNo, 1, GrMipmapped::kNo, GrProtected::kNo,
|
||||
kTopLeft_GrSurfaceOrigin, combo.fColorType,
|
||||
kUnknown_SkAlphaType, nullptr, fit, SkBudgeted::kYes);
|
||||
GrImageInfo info(combo.fColorType,
|
||||
kUnknown_SkAlphaType,
|
||||
nullptr,
|
||||
{desc.fHeight, desc.fHeight});
|
||||
surfCtx = GrSurfaceContext::Make(dContext, info, combo.fFormat, fit);
|
||||
}
|
||||
if (!surfCtx) {
|
||||
continue;
|
||||
@ -371,9 +370,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
|
||||
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
|
||||
GrColorType::kRGBA_8888);
|
||||
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
|
||||
auto surfContext = GrSurfaceContext::Make(dContext, std::move(view), GrColorType::kRGBA_8888,
|
||||
kPremul_SkAlphaType, nullptr);
|
||||
|
||||
auto surfContext = GrSurfaceContext::Make(dContext, std::move(view), ii.colorInfo());
|
||||
// Read pixels should work with a read-only texture.
|
||||
{
|
||||
SkAutoPixmapStorage read;
|
||||
|
@ -31,14 +31,16 @@ void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
||||
|
||||
FillPixelData(kWidth, kHeight, srcBuffer.get());
|
||||
|
||||
auto grCT = SkColorTypeToGrColorType(ct);
|
||||
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
|
||||
dContext, renderable, kTopLeft_GrSurfaceOrigin,
|
||||
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
|
||||
auto info = SkImageInfo::Make({kWidth, kHeight}, ct, kPremul_SkAlphaType, nullptr);
|
||||
auto view = sk_gpu_test::MakeTextureProxyViewFromData(dContext,
|
||||
renderable,
|
||||
kTopLeft_GrSurfaceOrigin,
|
||||
info,
|
||||
srcBuffer,
|
||||
/*row bytes*/ 0);
|
||||
REPORTER_ASSERT(reporter, view);
|
||||
if (view) {
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType,
|
||||
nullptr);
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), info.colorInfo());
|
||||
|
||||
SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);
|
||||
|
||||
@ -59,13 +61,15 @@ void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
||||
REPORTER_ASSERT(reporter, DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, 10, 2));
|
||||
}
|
||||
|
||||
view = sk_gpu_test::MakeTextureProxyViewFromData(
|
||||
dContext, renderable, kBottomLeft_GrSurfaceOrigin,
|
||||
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
|
||||
view = sk_gpu_test::MakeTextureProxyViewFromData(dContext,
|
||||
renderable,
|
||||
kBottomLeft_GrSurfaceOrigin,
|
||||
info,
|
||||
srcBuffer,
|
||||
0);
|
||||
REPORTER_ASSERT(reporter, view);
|
||||
if (view) {
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType,
|
||||
nullptr);
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), info.colorInfo());
|
||||
|
||||
SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);
|
||||
|
||||
|
@ -114,15 +114,16 @@ static void run_test(skiatest::Reporter* reporter, GrDirectContext* dContext, in
|
||||
SkImageInfo::Make(DEV_W, DEV_H, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
||||
|
||||
for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
|
||||
auto grColorType = SkColorTypeToGrColorType(colorType);
|
||||
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
|
||||
dContext, GrRenderable::kNo, origin,
|
||||
{grColorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H}, controlPixelData.begin(),
|
||||
0);
|
||||
auto info = SkImageInfo::Make({DEV_W, DEV_H}, colorType, kPremul_SkAlphaType, nullptr);
|
||||
auto view = sk_gpu_test::MakeTextureProxyViewFromData(dContext,
|
||||
GrRenderable::kNo,
|
||||
origin,
|
||||
info,
|
||||
controlPixelData.begin(),
|
||||
0);
|
||||
SkASSERT(view);
|
||||
|
||||
GrSurfaceContext sContext(dContext, std::move(view), grColorType, kPremul_SkAlphaType,
|
||||
nullptr);
|
||||
GrSurfaceContext sContext(dContext, std::move(view), info.colorInfo());
|
||||
|
||||
if (!sContext.readPixels(dContext, dstInfo, readBuffer.begin(), 0, {0, 0})) {
|
||||
// We only require this to succeed if the format is renderable.
|
||||
|
@ -410,8 +410,7 @@ bool log_texture_view(GrDirectContext* dContext, GrSurfaceProxyView src, SkStrin
|
||||
SkImageInfo ii = SkImageInfo::Make(src.proxy()->dimensions(), kRGBA_8888_SkColorType,
|
||||
kLogAlphaType);
|
||||
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(src), GrColorType::kRGBA_8888,
|
||||
kLogAlphaType, nullptr);
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(src), ii.colorInfo());
|
||||
SkBitmap bm;
|
||||
SkAssertResult(bm.tryAllocPixels(ii));
|
||||
SkAssertResult(sContext->readPixels(dContext, ii, bm.getPixels(), bm.rowBytes(), {0, 0}));
|
||||
|
@ -433,11 +433,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
|
||||
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
|
||||
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
|
||||
dContext, renderable, origin, bmp.info(), bmp.getPixels(), bmp.rowBytes());
|
||||
GrColorType grColorType = SkColorTypeToGrColorType(bmp.colorType());
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view),
|
||||
grColorType, kPremul_SkAlphaType, nullptr);
|
||||
auto info = SkImageInfo::Make(DEV_W, DEV_H, kN32_SkColorType, kPremul_SkAlphaType);
|
||||
test_readpixels_texture(reporter, dContext, std::move(sContext), info);
|
||||
auto sContext = GrSurfaceContext::Make(dContext,
|
||||
std::move(view),
|
||||
bmp.info().colorInfo());
|
||||
test_readpixels_texture(reporter, dContext, std::move(sContext), bmp.info());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,8 +74,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), maker.colorType(),
|
||||
kPremul_SkAlphaType, nullptr);
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), maker.colorInfo());
|
||||
|
||||
sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii));
|
||||
|
||||
@ -168,9 +167,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
const SkImageInfo dstInfo = SkImageInfo::Make(X_SIZE, Y_SIZE,
|
||||
kAlpha_8_SkColorType,
|
||||
kPremul_SkAlphaType);
|
||||
const GrImageInfo dstInfo(GrColorType::kAlpha_8,
|
||||
kPremul_SkAlphaType,
|
||||
nullptr,
|
||||
{X_SIZE, Y_SIZE});
|
||||
|
||||
// Attempt to read back just alpha from a RGBA/BGRA texture. Once with a texture-only src and
|
||||
// once with a render target.
|
||||
@ -186,15 +186,18 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
|
||||
|
||||
auto origin = GrRenderable::kYes == renderable ? kBottomLeft_GrSurfaceOrigin
|
||||
: kTopLeft_GrSurfaceOrigin;
|
||||
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
|
||||
dContext, renderable, origin,
|
||||
{info.fColorType, info.fAlphaType, nullptr, X_SIZE, Y_SIZE}, rgbaData, 0);
|
||||
GrImageInfo ii = dstInfo.makeColorType(info.fColorType).makeAlphaType(info.fAlphaType);
|
||||
auto view = sk_gpu_test::MakeTextureProxyViewFromData(dContext,
|
||||
renderable,
|
||||
origin,
|
||||
ii,
|
||||
rgbaData,
|
||||
/*row bytes*/ 0);
|
||||
if (!view) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), info.fColorType,
|
||||
kPremul_SkAlphaType, nullptr);
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), ii.colorInfo());
|
||||
|
||||
for (auto rowBytes : kRowBytes) {
|
||||
size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE;
|
||||
|
@ -134,10 +134,10 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
|
||||
|
||||
auto format = GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_RECTANGLE);
|
||||
GrBackendTexture rectangleTex = dContext->createBackendTexture(kWidth,
|
||||
kHeight,
|
||||
format,
|
||||
GrMipmapped::kNo,
|
||||
GrRenderable::kYes);
|
||||
kHeight,
|
||||
format,
|
||||
GrMipmapped::kNo,
|
||||
GrRenderable::kYes);
|
||||
if (!rectangleTex.isValid()) {
|
||||
continue;
|
||||
}
|
||||
@ -169,20 +169,19 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
|
||||
SkASSERT(rectProxy->hasRestrictedSampling());
|
||||
SkASSERT(rectProxy->peekTexture()->hasRestrictedSampling());
|
||||
|
||||
GrImageInfo grII = ii;
|
||||
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(rectangleTex.getBackendFormat(),
|
||||
GrColorType::kRGBA_8888);
|
||||
grII.colorType());
|
||||
GrSurfaceProxyView view(rectProxy, origin, swizzle);
|
||||
|
||||
test_basic_draw_as_src(reporter, dContext, view, GrColorType::kRGBA_8888,
|
||||
kPremul_SkAlphaType, refPixels);
|
||||
test_basic_draw_as_src(reporter, dContext, view, grII.colorType(), kPremul_SkAlphaType,
|
||||
refPixels);
|
||||
|
||||
// Test copy to both a texture and RT
|
||||
TestCopyFromSurface(reporter, dContext, rectProxy.get(), origin, GrColorType::kRGBA_8888,
|
||||
TestCopyFromSurface(reporter, dContext, rectProxy.get(), origin, grII.colorType(),
|
||||
refPixels, "RectangleTexture-copy-from");
|
||||
|
||||
auto rectContext = GrSurfaceContext::Make(dContext, std::move(view),
|
||||
GrColorType::kRGBA_8888, kPremul_SkAlphaType,
|
||||
nullptr);
|
||||
auto rectContext = GrSurfaceContext::Make(dContext, std::move(view), grII.colorInfo());
|
||||
SkASSERT(rectContext);
|
||||
|
||||
TestReadPixels(reporter, dContext, rectContext.get(), refPixels, "RectangleTexture-read");
|
||||
|
@ -756,9 +756,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
|
||||
auto makeImageSurfaceContext = [dContext](SkSurface* surface) {
|
||||
sk_sp<SkImage> i(surface->makeImageSnapshot());
|
||||
SkImage_Gpu* gpuImage = (SkImage_Gpu*)as_IB(i);
|
||||
return GrSurfaceContext::Make(dContext, *gpuImage->view(dContext),
|
||||
SkColorTypeToGrColorType(i->colorType()), kPremul_SkAlphaType,
|
||||
gpuImage->refColorSpace());
|
||||
return GrSurfaceContext::Make(dContext,
|
||||
*gpuImage->view(dContext),
|
||||
i->imageInfo().colorInfo());
|
||||
};
|
||||
|
||||
// Test that non-wrapped RTs are created clear.
|
||||
|
@ -89,8 +89,9 @@ void TestCopyFromSurface(skiatest::Reporter* reporter,
|
||||
SkASSERT(copy && copy->asTextureProxy());
|
||||
auto swizzle = dContext->priv().caps()->getReadSwizzle(copy->backendFormat(), colorType);
|
||||
GrSurfaceProxyView view(std::move(copy), origin, swizzle);
|
||||
auto dstContext = GrSurfaceContext::Make(dContext, std::move(view), colorType,
|
||||
kPremul_SkAlphaType, nullptr);
|
||||
auto dstContext = GrSurfaceContext::Make(dContext,
|
||||
std::move(view),
|
||||
{colorType, kPremul_SkAlphaType, nullptr});
|
||||
SkASSERT(dstContext);
|
||||
|
||||
TestReadPixels(reporter, dContext, dstContext.get(), expectedPixelValues, testName);
|
||||
|
@ -48,8 +48,7 @@ GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
|
||||
return {};
|
||||
}
|
||||
GrSurfaceProxyView view(proxy, origin, swizzle);
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), imageInfo.colorType(),
|
||||
imageInfo.alphaType(), imageInfo.refColorSpace());
|
||||
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), imageInfo.colorInfo());
|
||||
if (!sContext) {
|
||||
return {};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user