46cfbc67f6
This reverts commit4c6f9b7670
. Reason for revert: Landing with neuxs 7 and androind one fixes Original change's description: > Revert "Reland "Remove support for copyAsDraw in gpu copySurface."" > > This reverts commit84ea04949c
. > > Reason for revert: nexus 7 and android one broken > > Original change's description: > > Reland "Remove support for copyAsDraw in gpu copySurface." > > > > This reverts commitc5167c053b
. > > > > Reason for revert: fixed > > > > Original change's description: > > > Revert "Remove support for copyAsDraw in gpu copySurface." > > > > > > This reverts commit6565506463
. > > > > > > Reason for revert: seems to break things? > > > > > > Original change's description: > > > > Remove support for copyAsDraw in gpu copySurface. > > > > > > > > The major changes on a higher lever are: > > > > 1) The majority of all copies now go through GrSurfaceProxy::Copy which > > > > takes in a proxy and returns a new one with the data copied to it. This > > > > is the most common use case within Ganesh. > > > > > > > > 2) The backend copy calls no longer do draws, require origins to be the > > > > same, and won't do any swizzling or adjustment of subrects. They are > > > > all implemented to be dumb copy this data to this other spot. > > > > > > > > 3) The GrSurfaceContext copy call has now been moved to priv and renamed > > > > copyNoDraw, and a new priv copyAsDraw was added to GrRenderTargetContext. > > > > > > > > 4) WritePixels and ReplaceRenderTarget both need to specifiy the destination > > > > of copies. They are the only users (besides the GrSurfaceProxy::Copy) which > > > > call the priv methods on GrSurfaceContext. > > > > > > > > Change-Id: Iaf1eb3a73ccaf39a75af77e281dae594f809186f > > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/217459 > > > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com > > > > > > Change-Id: Id43aa8aa1451e794342e930441d9975b90e6b59f > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218549 > > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com > > > > Change-Id: I1a96f85ae2ff7622a6b57406755d478e7fbcf56e > > No-Presubmit: true > > No-Tree-Checks: true > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218797 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com > > Change-Id: I310930a9df30535f45a065263a40239141e15562 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219384 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com Change-Id: I88df4f19aa26ed77b5af4e25d138387cbabd1934 No-Presubmit: true No-Tree-Checks: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219386 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
203 lines
9.9 KiB
C++
203 lines
9.9 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 "include/core/SkImageInfo.h"
|
|
#include "include/core/SkPoint.h"
|
|
#include "include/core/SkRect.h"
|
|
#include "include/core/SkRefCnt.h"
|
|
#include "include/core/SkTypes.h"
|
|
#include "include/gpu/GrContext.h"
|
|
#include "include/gpu/GrTypes.h"
|
|
#include "include/private/GrSurfaceProxy.h"
|
|
#include "include/private/GrTextureProxy.h"
|
|
#include "include/private/GrTypesPriv.h"
|
|
#include "include/private/SkTemplates.h"
|
|
#include "src/core/SkUtils.h"
|
|
#include "src/gpu/GrCaps.h"
|
|
#include "src/gpu/GrContextPriv.h"
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
|
#include "src/gpu/GrSurfaceContext.h"
|
|
#include "src/gpu/SkGr.h"
|
|
#include "tests/Test.h"
|
|
#include "tools/gpu/GrContextFactory.h"
|
|
#include "tools/gpu/ProxyUtils.h"
|
|
|
|
#include <initializer_list>
|
|
#include <utility>
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
|
|
GrContext* context = ctxInfo.grContext();
|
|
static const int kW = 10;
|
|
static const int kH = 10;
|
|
static const size_t kRowBytes = sizeof(uint32_t) * kW;
|
|
|
|
SkAutoTMalloc<uint32_t> srcPixels(kW * kH);
|
|
for (int i = 0; i < kW * kH; ++i) {
|
|
srcPixels.get()[i] = i;
|
|
}
|
|
|
|
SkAutoTMalloc<uint32_t> dstPixels(kW * kH);
|
|
for (int i = 0; i < kW * kH; ++i) {
|
|
dstPixels.get()[i] = ~i;
|
|
}
|
|
|
|
static const SkIRect kSrcRects[] {
|
|
{ 0, 0, kW , kH },
|
|
{-1, -1, kW+1, kH+1},
|
|
{ 1, 1, kW-1, kH-1},
|
|
{ 5, 5, 6 , 6 },
|
|
};
|
|
|
|
static const SkIPoint kDstPoints[] {
|
|
{ 0 , 0 },
|
|
{ 1 , 1 },
|
|
{ kW/2, kH/4},
|
|
{ kW-1, kH-1},
|
|
{ kW , kH },
|
|
{ kW+1, kH+2},
|
|
{-1 , -1 },
|
|
};
|
|
|
|
static const SkImageInfo kImageInfos[] {
|
|
SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
|
|
SkImageInfo::Make(kW, kH, kBGRA_8888_SkColorType, kPremul_SkAlphaType)
|
|
};
|
|
|
|
SkAutoTMalloc<uint32_t> read(kW * kH);
|
|
|
|
for (auto sOrigin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
|
|
for (auto dOrigin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
|
|
for (auto sRenderable : {GrRenderable::kYes, GrRenderable::kNo}) {
|
|
for (auto dRenderable : {GrRenderable::kYes, GrRenderable::kNo}) {
|
|
for (auto srcRect : kSrcRects) {
|
|
for (auto dstPoint : kDstPoints) {
|
|
for (auto ii: kImageInfos) {
|
|
auto src = sk_gpu_test::MakeTextureProxyFromData(
|
|
context, sRenderable, kW, kH, ii.colorType(), sOrigin,
|
|
srcPixels.get(), kRowBytes);
|
|
auto dst = sk_gpu_test::MakeTextureProxyFromData(
|
|
context, dRenderable, kW, kH, ii.colorType(), dOrigin,
|
|
dstPixels.get(), kRowBytes);
|
|
|
|
// Should always work if the color type is RGBA, but may not work
|
|
// for BGRA
|
|
if (ii.colorType() == kRGBA_8888_SkColorType) {
|
|
if (!src || !dst) {
|
|
ERRORF(reporter,
|
|
"Could not create surfaces for copy surface test.");
|
|
continue;
|
|
}
|
|
} else {
|
|
GrPixelConfig config =
|
|
SkColorType2GrPixelConfig(kBGRA_8888_SkColorType);
|
|
if (!context->priv().caps()->isConfigTexturable(config)) {
|
|
continue;
|
|
}
|
|
if (!src || !dst) {
|
|
ERRORF(reporter,
|
|
"Could not create surfaces for copy surface test.");
|
|
continue;
|
|
}
|
|
}
|
|
|
|
sk_sp<GrSurfaceContext> dstContext =
|
|
context->priv().makeWrappedSurfaceContext(std::move(dst));
|
|
|
|
bool result = false;
|
|
if (sOrigin == dOrigin) {
|
|
result = dstContext->testCopy(src.get(), srcRect, dstPoint);
|
|
} else if (dRenderable == GrRenderable::kYes) {
|
|
SkASSERT(dstContext->asRenderTargetContext());
|
|
result = dstContext->asRenderTargetContext()->blitTexture(
|
|
src.get(), srcRect, dstPoint);
|
|
}
|
|
|
|
bool expectedResult = true;
|
|
SkIPoint dstOffset = { dstPoint.fX - srcRect.fLeft,
|
|
dstPoint.fY - srcRect.fTop };
|
|
SkIRect copiedDstRect = SkIRect::MakeXYWH(dstPoint.fX,
|
|
dstPoint.fY,
|
|
srcRect.width(),
|
|
srcRect.height());
|
|
|
|
SkIRect copiedSrcRect;
|
|
if (!copiedSrcRect.intersect(srcRect, SkIRect::MakeWH(kW, kH))) {
|
|
expectedResult = false;
|
|
} else {
|
|
// If the src rect was clipped, apply same clipping to each side
|
|
// of copied dst rect.
|
|
copiedDstRect.fLeft += copiedSrcRect.fLeft - srcRect.fLeft;
|
|
copiedDstRect.fTop += copiedSrcRect.fTop - srcRect.fTop;
|
|
copiedDstRect.fRight -= copiedSrcRect.fRight - srcRect.fRight;
|
|
copiedDstRect.fBottom -= copiedSrcRect.fBottom -
|
|
srcRect.fBottom;
|
|
}
|
|
if (copiedDstRect.isEmpty() ||
|
|
!copiedDstRect.intersect(SkIRect::MakeWH(kW, kH))) {
|
|
expectedResult = false;
|
|
}
|
|
if (sOrigin != dOrigin && dRenderable == GrRenderable::kNo) {
|
|
expectedResult = false;
|
|
}
|
|
|
|
// To make the copied src rect correct we would apply any dst
|
|
// clipping back to the src rect, but we don't use it again so
|
|
// don't bother.
|
|
if (expectedResult != result) {
|
|
ERRORF(reporter, "Expected return value %d from copySurface, "
|
|
"got %d.", expectedResult, result);
|
|
continue;
|
|
}
|
|
|
|
if (!expectedResult || !result) {
|
|
continue;
|
|
}
|
|
|
|
sk_memset32(read.get(), 0, kW * kH);
|
|
if (!dstContext->readPixels(ii, read.get(), kRowBytes, 0, 0)) {
|
|
ERRORF(reporter, "Error calling readPixels");
|
|
continue;
|
|
}
|
|
|
|
bool abort = false;
|
|
// Validate that pixels inside copiedDstRect received the correct
|
|
// value from src and that those outside were not modified.
|
|
for (int y = 0; y < kH && !abort; ++y) {
|
|
for (int x = 0; x < kW; ++x) {
|
|
uint32_t r = read.get()[y * kW + x];
|
|
if (copiedDstRect.contains(x, y)) {
|
|
int sx = x - dstOffset.fX;
|
|
int sy = y - dstOffset.fY;
|
|
uint32_t s = srcPixels.get()[sy * kW + sx];
|
|
if (s != r) {
|
|
ERRORF(reporter, "Expected dst %d,%d to contain "
|
|
"0x%08x copied from src location %d,%d. Got "
|
|
"0x%08x", x, y, s, sx, sy, r);
|
|
abort = true;
|
|
break;
|
|
}
|
|
} else {
|
|
uint32_t d = dstPixels.get()[y * kW + x];
|
|
if (d != r) {
|
|
ERRORF(reporter, "Expected dst %d,%d to be "
|
|
"unmodified (0x%08x). Got 0x%08x",
|
|
x, y, d, r);
|
|
abort = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|