2016-01-14 17:24:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Test.h"
|
2017-01-27 15:11:42 +00:00
|
|
|
#include "TestUtils.h"
|
|
|
|
|
2016-01-14 17:24:09 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2017-03-09 14:03:58 +00:00
|
|
|
#include "GrClip.h"
|
2016-01-14 17:24:09 +00:00
|
|
|
#include "GrContext.h"
|
2016-08-03 21:26:53 +00:00
|
|
|
#include "GrContextPriv.h"
|
2016-10-27 18:47:55 +00:00
|
|
|
#include "GrRenderTargetContext.h"
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
#include "GrTest.h"
|
2017-03-09 14:03:58 +00:00
|
|
|
#include "gl/GLTestContext.h"
|
2016-01-14 17:24:09 +00:00
|
|
|
#include "gl/GrGLGpu.h"
|
|
|
|
#include "gl/GrGLUtil.h"
|
|
|
|
|
2016-11-07 14:53:44 +00:00
|
|
|
// skbug.com/5932
|
2017-01-25 17:10:37 +00:00
|
|
|
static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* context,
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
sk_sp<GrTextureProxy> rectProxy, uint32_t expectedPixelValues[]) {
|
2016-11-07 14:53:44 +00:00
|
|
|
sk_sp<GrRenderTargetContext> rtContext(
|
2017-04-24 14:57:28 +00:00
|
|
|
context->makeDeferredRenderTargetContext(SkBackingFit::kExact, rectProxy->width(),
|
|
|
|
rectProxy->height(), rectProxy->config(),
|
|
|
|
nullptr));
|
2017-09-07 16:36:34 +00:00
|
|
|
for (auto filter : {GrSamplerState::Filter::kNearest,
|
|
|
|
GrSamplerState::Filter::kBilerp,
|
|
|
|
GrSamplerState::Filter::kMipMap}) {
|
2016-11-07 14:53:44 +00:00
|
|
|
rtContext->clear(nullptr, 0xDDCCBBAA, true);
|
2017-10-18 17:15:13 +00:00
|
|
|
auto fp = GrSimpleTextureEffect::Make(rectProxy, SkMatrix::I(), filter);
|
2016-11-07 14:53:44 +00:00
|
|
|
GrPaint paint;
|
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
|
|
|
paint.addColorFragmentProcessor(std::move(fp));
|
2017-01-11 18:42:54 +00:00
|
|
|
rtContext->drawPaint(GrNoClip(), std::move(paint), SkMatrix::I());
|
2017-03-14 18:39:29 +00:00
|
|
|
test_read_pixels(reporter, rtContext.get(), expectedPixelValues,
|
2017-01-27 15:11:42 +00:00
|
|
|
"RectangleTexture-basic-draw");
|
2016-11-07 14:53:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
static void test_clear(skiatest::Reporter* reporter, GrSurfaceContext* rectContext) {
|
2017-01-25 17:10:37 +00:00
|
|
|
if (GrRenderTargetContext* rtc = rectContext->asRenderTargetContext()) {
|
2016-01-14 17:24:09 +00:00
|
|
|
// Clear the whole thing.
|
|
|
|
GrColor color0 = GrColorPackRGBA(0xA, 0xB, 0xC, 0xD);
|
2016-10-27 18:47:55 +00:00
|
|
|
rtc->clear(nullptr, color0, false);
|
2016-01-14 17:24:09 +00:00
|
|
|
|
2017-01-25 17:10:37 +00:00
|
|
|
int w = rtc->width();
|
|
|
|
int h = rtc->height();
|
2016-01-14 17:24:09 +00:00
|
|
|
int pixelCnt = w * h;
|
|
|
|
SkAutoTMalloc<uint32_t> expectedPixels(pixelCnt);
|
|
|
|
|
|
|
|
// The clear color is a GrColor, our readback is to kRGBA_8888, which may be different.
|
2016-01-15 14:21:18 +00:00
|
|
|
uint32_t expectedColor0 = 0;
|
2016-01-14 17:24:09 +00:00
|
|
|
uint8_t* expectedBytes0 = SkTCast<uint8_t*>(&expectedColor0);
|
|
|
|
expectedBytes0[0] = GrColorUnpackR(color0);
|
|
|
|
expectedBytes0[1] = GrColorUnpackG(color0);
|
|
|
|
expectedBytes0[2] = GrColorUnpackB(color0);
|
|
|
|
expectedBytes0[3] = GrColorUnpackA(color0);
|
2017-01-25 17:10:37 +00:00
|
|
|
for (int i = 0; i < rtc->width() * rtc->height(); ++i) {
|
2016-01-14 17:24:09 +00:00
|
|
|
expectedPixels.get()[i] = expectedColor0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the the top to a different color.
|
|
|
|
GrColor color1 = GrColorPackRGBA(0x1, 0x2, 0x3, 0x4);
|
|
|
|
SkIRect rect = SkIRect::MakeWH(w, h/2);
|
2016-10-27 18:47:55 +00:00
|
|
|
rtc->clear(&rect, color1, false);
|
2016-01-14 17:24:09 +00:00
|
|
|
|
2016-01-15 14:21:18 +00:00
|
|
|
uint32_t expectedColor1 = 0;
|
2016-01-14 17:24:09 +00:00
|
|
|
uint8_t* expectedBytes1 = SkTCast<uint8_t*>(&expectedColor1);
|
|
|
|
expectedBytes1[0] = GrColorUnpackR(color1);
|
|
|
|
expectedBytes1[1] = GrColorUnpackG(color1);
|
|
|
|
expectedBytes1[2] = GrColorUnpackB(color1);
|
|
|
|
expectedBytes1[3] = GrColorUnpackA(color1);
|
|
|
|
|
|
|
|
for (int y = 0; y < h/2; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
|
|
|
expectedPixels.get()[y * h + x] = expectedColor1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_read_pixels(reporter, rtc, expectedPixels.get(), "RectangleTexture-clear");
|
2016-01-14 17:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 21:02:39 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
sk_gpu_test::GLTestContext* glContext = ctxInfo.glContext();
|
2016-01-14 17:24:09 +00:00
|
|
|
static const int kWidth = 13;
|
|
|
|
static const int kHeight = 13;
|
|
|
|
|
|
|
|
GrColor pixels[kWidth * kHeight];
|
|
|
|
for (int y = 0; y < kHeight; ++y) {
|
|
|
|
for (int x = 0; x < kWidth; ++x) {
|
|
|
|
pixels[y * kWidth + x] = y * kWidth + x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
|
|
|
|
bool useBLOrigin = kBottomLeft_GrSurfaceOrigin == origin;
|
|
|
|
|
2016-01-14 17:24:09 +00:00
|
|
|
GrGLuint rectTexID = glContext->createTextureRectangle(kWidth, kHeight, GR_GL_RGBA,
|
|
|
|
GR_GL_RGBA, GR_GL_UNSIGNED_BYTE,
|
|
|
|
pixels);
|
|
|
|
|
|
|
|
if (!rectTexID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let GrContext know that we messed with the GL context directly.
|
|
|
|
context->resetContext();
|
|
|
|
|
|
|
|
// Wrap the rectangle texture ID in a GrTexture
|
|
|
|
GrGLTextureInfo rectangleInfo;
|
|
|
|
rectangleInfo.fID = rectTexID;
|
|
|
|
rectangleInfo.fTarget = GR_GL_TEXTURE_RECTANGLE;
|
|
|
|
|
2017-04-26 17:29:21 +00:00
|
|
|
GrBackendTexture rectangleTex(kWidth, kHeight, kRGBA_8888_GrPixelConfig, rectangleInfo);
|
2016-01-14 17:24:09 +00:00
|
|
|
|
|
|
|
GrColor refPixels[kWidth * kHeight];
|
|
|
|
for (int y = 0; y < kHeight; ++y) {
|
|
|
|
for (int x = 0; x < kWidth; ++x) {
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
int y0 = useBLOrigin ? kHeight - y - 1 : y;
|
2016-01-14 17:24:09 +00:00
|
|
|
refPixels[y * kWidth + x] = pixels[y0 * kWidth + x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
sk_sp<GrTextureProxy> rectProxy = GrSurfaceProxy::MakeWrappedBackend(context,
|
|
|
|
rectangleTex,
|
|
|
|
origin);
|
2017-01-27 15:58:31 +00:00
|
|
|
if (!rectProxy) {
|
|
|
|
ERRORF(reporter, "Error creating proxy for rectangle texture.");
|
|
|
|
GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID));
|
|
|
|
continue;
|
2016-01-14 17:24:09 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 17:10:37 +00:00
|
|
|
test_basic_draw_as_src(reporter, context, rectProxy, refPixels);
|
|
|
|
|
2017-01-27 15:11:42 +00:00
|
|
|
// Test copy to both a texture and RT
|
|
|
|
test_copy_from_surface(reporter, context, rectProxy.get(), refPixels,
|
|
|
|
false, "RectangleTexture-copy-from");
|
2016-01-14 17:24:09 +00:00
|
|
|
|
2017-01-25 17:10:37 +00:00
|
|
|
sk_sp<GrSurfaceContext> rectContext = context->contextPriv().makeWrappedSurfaceContext(
|
|
|
|
std::move(rectProxy), nullptr);
|
|
|
|
SkASSERT(rectContext);
|
2016-11-07 14:53:44 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_read_pixels(reporter, rectContext.get(), refPixels, "RectangleTexture-read");
|
2016-01-14 17:24:09 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_copy_to_surface(reporter, context->resourceProvider(),
|
|
|
|
rectContext.get(), "RectangleTexture-copy-to");
|
2016-01-14 17:24:09 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_write_pixels(reporter, rectContext.get(), true, "RectangleTexture-write");
|
2016-01-14 17:24:09 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_clear(reporter, rectContext.get());
|
2016-01-14 17:24:09 +00:00
|
|
|
|
|
|
|
GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|