c95b589112
This reverts commitcf0d08e149
. Reason for revert: fix codegen Original change's description: > Revert "Migrate GrSurfaceContext readPixels to take direct context" > > This reverts commitd169e1915c
. > > Reason for revert: broke chrome via code generator > > Original change's description: > > Migrate GrSurfaceContext readPixels to take direct context > > > > After this lands we'll proceed up the stack and add the direct > > context requirement to the public API and SkImage. > > > > Bug: skia:104662 > > Change-Id: I4b2d779a7fcd65eec68e631757821ac8e136ddba > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309044 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I6126f2dca4bc902c903512ac486e22841cc472e5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309281 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=robertphillips@google.com,adlai@google.com Bug: skia:104662 Change-Id: If899edab54d031a3619a4bbab90d13738679c037 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309319 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Adlai Holler <adlai@google.com>
110 lines
4.4 KiB
C++
110 lines
4.4 KiB
C++
/*
|
|
* Copyright 2018 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "include/gpu/GrDirectContext.h"
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
|
#include "src/gpu/GrContextPriv.h"
|
|
#include "src/gpu/GrImageInfo.h"
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
#include "src/gpu/GrSurfaceContext.h"
|
|
#include "tests/Test.h"
|
|
#include "tests/TestUtils.h"
|
|
|
|
static void testing_only_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
|
SkColorType ct, GrRenderable renderable, bool doDataUpload,
|
|
GrMipmapped mipMapped) {
|
|
const int kWidth = 16;
|
|
const int kHeight = 16;
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);
|
|
|
|
SkAutoPixmapStorage expectedPixels, actualPixels;
|
|
expectedPixels.alloc(ii);
|
|
actualPixels.alloc(ii);
|
|
|
|
const GrCaps* caps = dContext->priv().caps();
|
|
|
|
GrColorType grCT = SkColorTypeToGrColorType(ct);
|
|
|
|
GrBackendFormat backendFormat = dContext->defaultBackendFormat(ct, renderable);
|
|
if (!backendFormat.isValid()) {
|
|
return;
|
|
}
|
|
|
|
GrBackendTexture backendTex;
|
|
|
|
if (doDataUpload) {
|
|
SkASSERT(GrMipmapped::kNo == mipMapped);
|
|
|
|
FillPixelData(kWidth, kHeight, expectedPixels.writable_addr32(0, 0));
|
|
|
|
backendTex = dContext->createBackendTexture(&expectedPixels, 1,
|
|
renderable, GrProtected::kNo);
|
|
} else {
|
|
backendTex = dContext->createBackendTexture(kWidth, kHeight, ct, SkColors::kTransparent,
|
|
mipMapped, renderable, GrProtected::kNo);
|
|
|
|
size_t allocSize = SkAutoPixmapStorage::AllocSize(ii, nullptr);
|
|
// createBackendTexture will fill the texture with 0's if no data is provided, so
|
|
// we set the expected result likewise.
|
|
memset(expectedPixels.writable_addr32(0, 0), 0, allocSize);
|
|
}
|
|
if (!backendTex.isValid()) {
|
|
return;
|
|
}
|
|
// skbug.com/9165
|
|
auto supportedRead =
|
|
caps->supportedReadPixelsColorType(grCT, backendTex.getBackendFormat(), grCT);
|
|
if (supportedRead.fColorType != grCT) {
|
|
return;
|
|
}
|
|
|
|
sk_sp<GrTextureProxy> wrappedProxy;
|
|
if (GrRenderable::kYes == renderable) {
|
|
wrappedProxy = dContext->priv().proxyProvider()->wrapRenderableBackendTexture(
|
|
backendTex, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, nullptr);
|
|
} else {
|
|
wrappedProxy = dContext->priv().proxyProvider()->wrapBackendTexture(
|
|
backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, GrIOType::kRW_GrIOType);
|
|
}
|
|
REPORTER_ASSERT(reporter, wrappedProxy);
|
|
|
|
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(wrappedProxy->backendFormat(),
|
|
grCT);
|
|
GrSurfaceProxyView view(std::move(wrappedProxy), kTopLeft_GrSurfaceOrigin, swizzle);
|
|
auto surfaceContext = GrSurfaceContext::Make(dContext, std::move(view), grCT,
|
|
kPremul_SkAlphaType, nullptr);
|
|
REPORTER_ASSERT(reporter, surfaceContext);
|
|
|
|
bool result = surfaceContext->readPixels(dContext,
|
|
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight},
|
|
actualPixels.writable_addr(), actualPixels.rowBytes(),
|
|
{0, 0});
|
|
|
|
REPORTER_ASSERT(reporter, result);
|
|
REPORTER_ASSERT(reporter,
|
|
DoesFullBufferContainCorrectColor(expectedPixels.addr32(),
|
|
actualPixels.addr32(), kWidth, kHeight));
|
|
}
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTestingBackendTextureUploadTest, reporter, ctxInfo) {
|
|
for (auto colorType: { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType }) {
|
|
for (auto renderable: { GrRenderable::kYes, GrRenderable::kNo }) {
|
|
for (bool doDataUpload: {true, false}) {
|
|
testing_only_texture_test(reporter, ctxInfo.directContext(), colorType,
|
|
renderable, doDataUpload, GrMipmapped::kNo);
|
|
|
|
if (!doDataUpload) {
|
|
testing_only_texture_test(reporter, ctxInfo.directContext(), colorType,
|
|
renderable, doDataUpload, GrMipmapped::kYes);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|