skia2/tests/RectangleTextureTest.cpp
Greg Daniel 09c9400695 Reland "Reland "Require mips to be allocated at texture creation time and disable late allocations.""
This reverts commit 01422bc8ef.

Reason for revert: follow on change may be ready

Original change's description:
> Revert "Reland "Require mips to be allocated at texture creation time and disable late allocations.""
> 
> This reverts commit 9eb36b9eb8.
> 
> Reason for revert: Alpha8 isn't renderable on es2 so we end up dropping draws on certain A8 mip requests
> 
> Original change's description:
> > Reland "Require mips to be allocated at texture creation time and disable late allocations."
> > 
> > This reverts commit 0c78238e29.
> > 
> > Reason for revert: <INSERT REASONING HERE>
> > 
> > Original change's description:
> > > Revert "Require mips to be allocated at texture creation time and disable late allocations."
> > > 
> > > This reverts commit cd2c3f9055.
> > > 
> > > Reason for revert: Looks to be causing angle failures on initial clear test
> > > 
> > > Original change's description:
> > > > Require mips to be allocated at texture creation time and disable late allocations.
> > > > 
> > > > If we get a non-mipped texture for a draw that wants to be use mip map filter, we
> > > > will copy the texture into a new mipped texture.
> > > > 
> > > > Clean up of unused code in the GPU backends for reallocating for mips will be done
> > > > in a follow up CL.
> > > > 
> > > > Bug: skia:
> > > > Change-Id: Idab588c1abf4bbbf7eeceb3727d500e5df274188
> > > > Reviewed-on: https://skia-review.googlesource.com/132830
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > > 
> > >
> > > 
> > > Change-Id: I49f0ace52f2586d61b451630b2e6aae84b420b81
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/133041
> > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > 
> > Bug: skia:
> > Change-Id: I004447a5f1ec72c3be2318ddea803f57efb12ea4
> > Reviewed-on: https://skia-review.googlesource.com/133340
> > 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: I9e9718d380c4d9927ec39e46008750ab7396391f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/133680
> 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: Ic3df69f65a89962b21cdb50ee436a29fd121ab1f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/133740
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-06-08 23:01:44 +00:00

170 lines
6.9 KiB
C++

/*
* 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"
#include "TestUtils.h"
#include "GrClip.h"
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrProxyProvider.h"
#include "GrRenderTargetContext.h"
#include "GrSurfacePriv.h"
#include "GrTest.h"
#include "GrTexturePriv.h"
#include "GrTextureProxyPriv.h"
#include "gl/GLTestContext.h"
#include "gl/GrGLGpu.h"
#include "gl/GrGLUtil.h"
// skbug.com/5932
static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* context,
sk_sp<GrTextureProxy> rectProxy, uint32_t expectedPixelValues[]) {
sk_sp<GrRenderTargetContext> rtContext(context->contextPriv().makeDeferredRenderTargetContext(
SkBackingFit::kExact, rectProxy->width(),
rectProxy->height(), rectProxy->config(),
nullptr));
for (auto filter : {GrSamplerState::Filter::kNearest,
GrSamplerState::Filter::kBilerp,
GrSamplerState::Filter::kMipMap}) {
rtContext->clear(nullptr, 0xDDCCBBAA, GrRenderTargetContext::CanClearFullscreen::kYes);
auto fp = GrSimpleTextureEffect::Make(rectProxy, SkMatrix::I(), filter);
GrPaint paint;
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
paint.addColorFragmentProcessor(std::move(fp));
rtContext->drawPaint(GrNoClip(), std::move(paint), SkMatrix::I());
test_read_pixels(reporter, rtContext.get(), expectedPixelValues,
"RectangleTexture-basic-draw");
}
}
static void test_clear(skiatest::Reporter* reporter, GrSurfaceContext* rectContext) {
if (GrRenderTargetContext* rtc = rectContext->asRenderTargetContext()) {
// Clear the whole thing.
GrColor color0 = GrColorPackRGBA(0xA, 0xB, 0xC, 0xD);
rtc->clear(nullptr, color0, GrRenderTargetContext::CanClearFullscreen::kNo);
int w = rtc->width();
int h = rtc->height();
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.
uint32_t expectedColor0 = 0;
uint8_t* expectedBytes0 = SkTCast<uint8_t*>(&expectedColor0);
expectedBytes0[0] = GrColorUnpackR(color0);
expectedBytes0[1] = GrColorUnpackG(color0);
expectedBytes0[2] = GrColorUnpackB(color0);
expectedBytes0[3] = GrColorUnpackA(color0);
for (int i = 0; i < rtc->width() * rtc->height(); ++i) {
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);
rtc->clear(&rect, color1, GrRenderTargetContext::CanClearFullscreen::kNo);
uint32_t expectedColor1 = 0;
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;
}
}
test_read_pixels(reporter, rtc, expectedPixels.get(), "RectangleTexture-clear");
}
}
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
sk_gpu_test::GLTestContext* glContext = ctxInfo.glContext();
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;
}
}
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
bool useBLOrigin = kBottomLeft_GrSurfaceOrigin == origin;
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;
GrBackendTexture rectangleTex(kWidth, kHeight, kRGBA_8888_GrPixelConfig, rectangleInfo);
GrColor refPixels[kWidth * kHeight];
for (int y = 0; y < kHeight; ++y) {
for (int x = 0; x < kWidth; ++x) {
int y0 = useBLOrigin ? kHeight - y - 1 : y;
refPixels[y * kWidth + x] = pixels[y0 * kWidth + x];
}
}
sk_sp<GrTextureProxy> rectProxy = proxyProvider->wrapBackendTexture(rectangleTex, origin);
if (!rectProxy) {
ERRORF(reporter, "Error creating proxy for rectangle texture.");
GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID));
continue;
}
SkASSERT(rectProxy->mipMapped() == GrMipMapped::kNo);
SkASSERT(rectProxy->priv().peekTexture()->texturePriv().mipMapped() == GrMipMapped::kNo);
SkASSERT(rectProxy->texPriv().isGLTextureRectangleOrExternal());
SkASSERT(rectProxy->priv().peekTexture()->surfacePriv().isGLTextureRectangleOrExternal());
SkASSERT(rectProxy->texPriv().isClampOnly());
SkASSERT(rectProxy->priv().peekTexture()->surfacePriv().isClampOnly());
test_basic_draw_as_src(reporter, context, rectProxy, refPixels);
// Test copy to both a texture and RT
test_copy_from_surface(reporter, context, rectProxy.get(), refPixels,
false, "RectangleTexture-copy-from");
sk_sp<GrSurfaceContext> rectContext = context->contextPriv().makeWrappedSurfaceContext(
std::move(rectProxy));
SkASSERT(rectContext);
test_read_pixels(reporter, rectContext.get(), refPixels, "RectangleTexture-read");
test_copy_to_surface(reporter, context->contextPriv().proxyProvider(),
rectContext.get(), "RectangleTexture-copy-to");
test_write_pixels(reporter, rectContext.get(), true, "RectangleTexture-write");
test_clear(reporter, rectContext.get());
GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID));
}
}