2017-01-27 15:11:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/TestUtils.h"
|
|
|
|
|
|
|
|
#include "include/encode/SkPngEncoder.h"
|
|
|
|
#include "include/utils/SkBase64.h"
|
2019-05-07 17:29:22 +00:00
|
|
|
#include "src/core/SkUtils.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrContextPriv.h"
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
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 commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > 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>
2019-06-07 15:43:30 +00:00
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
2019-05-07 17:29:22 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrSurfaceContext.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrSurfaceProxy.h"
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
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 commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > 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>
2019-06-07 15:43:30 +00:00
|
|
|
#include "src/gpu/GrTextureContext.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
void test_read_pixels(skiatest::Reporter* reporter,
|
2017-01-27 15:11:42 +00:00
|
|
|
GrSurfaceContext* srcContext, uint32_t expectedPixelValues[],
|
|
|
|
const char* testName) {
|
|
|
|
int pixelCnt = srcContext->width() * srcContext->height();
|
|
|
|
SkAutoTMalloc<uint32_t> pixels(pixelCnt);
|
|
|
|
memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt);
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(srcContext->width(), srcContext->height(),
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2019-07-01 17:05:28 +00:00
|
|
|
bool read = srcContext->readPixels(ii, pixels.get(), 0, {0, 0});
|
2017-01-27 15:11:42 +00:00
|
|
|
if (!read) {
|
|
|
|
ERRORF(reporter, "%s: Error reading from texture.", testName);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < pixelCnt; ++i) {
|
|
|
|
if (pixels.get()[i] != expectedPixelValues[i]) {
|
|
|
|
ERRORF(reporter, "%s: Error, pixel value %d should be 0x%08x, got 0x%08x.",
|
|
|
|
testName, i, expectedPixelValues[i], pixels.get()[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
void test_write_pixels(skiatest::Reporter* reporter,
|
2017-01-27 15:11:42 +00:00
|
|
|
GrSurfaceContext* dstContext, bool expectedToWork,
|
|
|
|
const char* testName) {
|
|
|
|
int pixelCnt = dstContext->width() * dstContext->height();
|
|
|
|
SkAutoTMalloc<uint32_t> pixels(pixelCnt);
|
|
|
|
for (int y = 0; y < dstContext->width(); ++y) {
|
|
|
|
for (int x = 0; x < dstContext->height(); ++x) {
|
|
|
|
pixels.get()[y * dstContext->width() + x] =
|
2018-10-29 18:11:04 +00:00
|
|
|
SkColorToPremulGrColor(SkColorSetARGB(2*y, x, y, x + y));
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(dstContext->width(), dstContext->height(),
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2019-07-01 17:05:28 +00:00
|
|
|
bool write = dstContext->writePixels(ii, pixels.get(), 0, {0, 0});
|
2017-01-27 15:11:42 +00:00
|
|
|
if (!write) {
|
|
|
|
if (expectedToWork) {
|
|
|
|
ERRORF(reporter, "%s: Error writing to texture.", testName);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write && !expectedToWork) {
|
|
|
|
ERRORF(reporter, "%s: writePixels succeeded when it wasn't supposed to.", testName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_read_pixels(reporter, dstContext, pixels.get(), testName);
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:50:07 +00:00
|
|
|
void test_copy_from_surface(skiatest::Reporter* reporter, GrContext* context, GrSurfaceProxy* proxy,
|
|
|
|
GrColorType colorType, uint32_t expectedPixelValues[],
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
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 commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > 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>
2019-06-07 15:43:30 +00:00
|
|
|
const char* testName) {
|
2019-06-24 19:50:07 +00:00
|
|
|
sk_sp<GrTextureProxy> dstProxy = GrSurfaceProxy::Copy(context, proxy, GrMipMapped::kNo,
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
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 commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > 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>
2019-06-07 15:43:30 +00:00
|
|
|
SkBackingFit::kExact, SkBudgeted::kYes);
|
|
|
|
SkASSERT(dstProxy);
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2019-06-24 19:50:07 +00:00
|
|
|
sk_sp<GrSurfaceContext> dstContext = context->priv().makeWrappedSurfaceContext(
|
|
|
|
std::move(dstProxy), colorType, kPremul_SkAlphaType);
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
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 commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > 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>
2019-06-07 15:43:30 +00:00
|
|
|
SkASSERT(dstContext.get());
|
2017-01-27 15:11:42 +00:00
|
|
|
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
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 commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > 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>
2019-06-07 15:43:30 +00:00
|
|
|
test_read_pixels(reporter, dstContext.get(), expectedPixelValues, testName);
|
2017-01-27 15:11:42 +00:00
|
|
|
}
|
2018-07-17 17:28:20 +00:00
|
|
|
|
|
|
|
void fill_pixel_data(int width, int height, GrColor* data) {
|
|
|
|
for (int j = 0; j < height; ++j) {
|
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
unsigned int red = (unsigned int)(256.f * (i / (float)width));
|
|
|
|
unsigned int green = (unsigned int)(256.f * (j / (float)height));
|
|
|
|
data[i + j * width] = GrColorPackRGBA(red - (red >> 8), green - (green >> 8),
|
|
|
|
0xff, 0xff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 17:29:22 +00:00
|
|
|
bool create_backend_texture(GrContext* context, GrBackendTexture* backendTex,
|
2019-07-23 17:44:16 +00:00
|
|
|
const SkImageInfo& ii, const SkColor4f& color,
|
|
|
|
GrMipMapped mipMapped, GrRenderable renderable) {
|
|
|
|
// TODO: use the color-init version of createBackendTexture once Metal supports it.
|
|
|
|
#if 0
|
|
|
|
*backendTex = context->createBackendTexture(ii.width(), ii.height(), ii.colorType(),
|
|
|
|
color, mipMapped, renderable);
|
|
|
|
#else
|
2019-05-07 17:29:22 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(ii);
|
2019-07-23 17:44:16 +00:00
|
|
|
sk_memset32(bm.getAddr32(0, 0), color.toSkColor(), ii.width() * ii.height());
|
2019-05-07 17:29:22 +00:00
|
|
|
|
2019-06-10 19:09:34 +00:00
|
|
|
SkASSERT(GrMipMapped::kNo == mipMapped);
|
2019-07-01 19:04:06 +00:00
|
|
|
*backendTex = context->priv().createBackendTexture(&bm.pixmap(), 1, renderable,
|
|
|
|
GrProtected::kNo);
|
2019-07-23 17:44:16 +00:00
|
|
|
#endif
|
2019-05-07 17:29:22 +00:00
|
|
|
|
2019-06-10 19:09:34 +00:00
|
|
|
return backendTex->isValid();
|
2019-05-07 17:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void delete_backend_texture(GrContext* context, const GrBackendTexture& backendTex) {
|
2019-05-29 18:24:32 +00:00
|
|
|
GrFlushInfo flushInfo;
|
|
|
|
flushInfo.fFlags = kSyncCpu_GrFlushFlag;
|
|
|
|
context->flush(flushInfo);
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2019-05-07 17:29:22 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 19:09:34 +00:00
|
|
|
bool does_full_buffer_contain_correct_color(const GrColor* srcBuffer,
|
|
|
|
const GrColor* dstBuffer,
|
2018-07-17 17:28:20 +00:00
|
|
|
int width,
|
|
|
|
int height) {
|
2019-06-10 19:09:34 +00:00
|
|
|
const GrColor* srcPtr = srcBuffer;
|
|
|
|
const GrColor* dstPtr = dstBuffer;
|
2018-07-17 17:28:20 +00:00
|
|
|
for (int j = 0; j < height; ++j) {
|
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
if (srcPtr[i] != dstPtr[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srcPtr += width;
|
|
|
|
dstPtr += width;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-01 16:42:53 +00:00
|
|
|
|
|
|
|
bool bitmap_to_base64_data_uri(const SkBitmap& bitmap, SkString* dst) {
|
|
|
|
SkPixmap pm;
|
|
|
|
if (!bitmap.peekPixels(&pm)) {
|
|
|
|
dst->set("peekPixels failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're going to embed this PNG in a data URI, so make it as small as possible
|
|
|
|
SkPngEncoder::Options options;
|
|
|
|
options.fFilterFlags = SkPngEncoder::FilterFlag::kAll;
|
|
|
|
options.fZLibLevel = 9;
|
|
|
|
|
|
|
|
SkDynamicMemoryWStream wStream;
|
|
|
|
if (!SkPngEncoder::Encode(&wStream, pm, options)) {
|
|
|
|
dst->set("SkPngEncoder::Encode failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<SkData> pngData = wStream.detachAsData();
|
|
|
|
size_t len = SkBase64::Encode(pngData->data(), pngData->size(), nullptr);
|
|
|
|
|
|
|
|
// The PNG can be almost arbitrarily large. We don't want to fill our logs with enormous URLs.
|
|
|
|
// Infra says these can be pretty big, as long as we're only outputting them on failure.
|
|
|
|
static const size_t kMaxBase64Length = 1024 * 1024;
|
|
|
|
if (len > kMaxBase64Length) {
|
|
|
|
dst->printf("Encoded image too large (%u bytes)", static_cast<uint32_t>(len));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst->resize(len);
|
|
|
|
SkBase64::Encode(pngData->data(), pngData->size(), dst->writable_str());
|
|
|
|
dst->prepend("data:image/png;base64,");
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-11 21:10:17 +00:00
|
|
|
|
2019-07-15 16:30:44 +00:00
|
|
|
bool compare_pixels(const GrPixelInfo& infoA, const char* a, size_t rowBytesA,
|
|
|
|
const GrPixelInfo& infoB, const char* b, size_t rowBytesB,
|
|
|
|
const float tolRGBA[4], std::function<ComparePixmapsErrorReporter>& error) {
|
|
|
|
if (infoA.width() != infoB.width() || infoA.height() != infoB.height()) {
|
|
|
|
static constexpr float kDummyDiffs[4] = {};
|
|
|
|
error(-1, -1, kDummyDiffs);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAlphaType floatAlphaType = infoA.alphaType();
|
|
|
|
// If one is premul and the other is unpremul we do the comparison in premul space.
|
|
|
|
if ((infoA.alphaType() == kPremul_SkAlphaType ||
|
|
|
|
infoB.alphaType() == kPremul_SkAlphaType) &&
|
|
|
|
(infoA.alphaType() == kUnpremul_SkAlphaType ||
|
|
|
|
infoB.alphaType() == kUnpremul_SkAlphaType)) {
|
|
|
|
floatAlphaType = kPremul_SkAlphaType;
|
|
|
|
}
|
|
|
|
sk_sp<SkColorSpace> floatCS;
|
|
|
|
if (SkColorSpace::Equals(infoA.colorSpace(), infoB.colorSpace())) {
|
|
|
|
floatCS = infoA.refColorSpace();
|
|
|
|
} else {
|
|
|
|
floatCS = SkColorSpace::MakeSRGBLinear();
|
|
|
|
}
|
|
|
|
GrPixelInfo floatInfo(GrColorType::kRGBA_F32, floatAlphaType, std::move(floatCS),
|
|
|
|
infoA.width(), infoA.height());
|
|
|
|
|
|
|
|
size_t floatBpp = GrColorTypeBytesPerPixel(GrColorType::kRGBA_F32);
|
|
|
|
size_t floatRowBytes = floatBpp * infoA.width();
|
|
|
|
std::unique_ptr<char[]> floatA(new char[floatRowBytes * infoA.height()]);
|
|
|
|
std::unique_ptr<char[]> floatB(new char[floatRowBytes * infoA.height()]);
|
|
|
|
SkAssertResult(GrConvertPixels(floatInfo, floatA.get(), floatRowBytes, infoA, a, rowBytesA));
|
|
|
|
SkAssertResult(GrConvertPixels(floatInfo, floatB.get(), floatRowBytes, infoB, b, rowBytesB));
|
|
|
|
|
|
|
|
auto at = [floatBpp, floatRowBytes](const char* floatBuffer, int x, int y) {
|
|
|
|
return reinterpret_cast<const float*>(floatBuffer + y * floatRowBytes + x * floatBpp);
|
|
|
|
};
|
|
|
|
for (int y = 0; y < infoA.height(); ++y) {
|
|
|
|
for (int x = 0; x < infoA.width(); ++x) {
|
|
|
|
const float* rgbaA = at(floatA.get(), x, y);
|
|
|
|
const float* rgbaB = at(floatB.get(), x, y);
|
|
|
|
float diffs[4];
|
|
|
|
bool bad = false;
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
diffs[i] = rgbaB[i] - rgbaA[i];
|
|
|
|
if (std::abs(diffs[i]) > std::abs(tolRGBA[i])) {
|
|
|
|
bad = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bad) {
|
|
|
|
error(x, y, diffs);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compare_pixels(const SkPixmap& a, const SkPixmap& b, const float tolRGBA[4],
|
|
|
|
std::function<ComparePixmapsErrorReporter>& error) {
|
|
|
|
return compare_pixels(a.info(), static_cast<const char*>(a.addr()), a.rowBytes(),
|
|
|
|
b.info(), static_cast<const char*>(b.addr()), b.rowBytes(),
|
|
|
|
tolRGBA, error);
|
|
|
|
}
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/utils/SkCharToGlyphCache.h"
|
2019-04-11 21:10:17 +00:00
|
|
|
|
|
|
|
static SkGlyphID hash_to_glyph(uint32_t value) {
|
|
|
|
return SkToU16(((value >> 16) ^ value) & 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class UnicharGen {
|
|
|
|
SkUnichar fU;
|
|
|
|
const int fStep;
|
|
|
|
public:
|
|
|
|
UnicharGen(int step) : fU(0), fStep(step) {}
|
|
|
|
|
|
|
|
SkUnichar next() {
|
|
|
|
fU += fStep;
|
|
|
|
return fU;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(chartoglyph_cache, reporter) {
|
|
|
|
SkCharToGlyphCache cache;
|
|
|
|
const int step = 3;
|
|
|
|
|
|
|
|
UnicharGen gen(step);
|
|
|
|
for (int i = 0; i < 500; ++i) {
|
|
|
|
SkUnichar c = gen.next();
|
|
|
|
SkGlyphID glyph = hash_to_glyph(c);
|
|
|
|
|
|
|
|
int index = cache.findGlyphIndex(c);
|
2019-04-15 16:07:19 +00:00
|
|
|
if (index >= 0) {
|
|
|
|
index = cache.findGlyphIndex(c);
|
|
|
|
}
|
2019-04-11 21:10:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, index < 0);
|
|
|
|
cache.insertCharAndGlyph(~index, c, glyph);
|
|
|
|
|
|
|
|
UnicharGen gen2(step);
|
|
|
|
for (int j = 0; j <= i; ++j) {
|
|
|
|
c = gen2.next();
|
|
|
|
glyph = hash_to_glyph(c);
|
|
|
|
index = cache.findGlyphIndex(c);
|
2019-04-15 16:07:19 +00:00
|
|
|
if ((unsigned)index != glyph) {
|
|
|
|
index = cache.findGlyphIndex(c);
|
|
|
|
}
|
2019-04-11 21:10:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, (unsigned)index == glyph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|