IntTextureTest.cpp revision 67c18d6b5188a0497f6912a73d964c763d2f8f84
1bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon/* 2bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon * Copyright 2016 Google Inc. 3bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon * 4bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon * Use of this source code is governed by a BSD-style license that can be 5bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon * found in the LICENSE file. 6bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon */ 7bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 8bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon#include "Test.h" 9bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 10bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon#if SK_SUPPORT_GPU 11bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon#include "GrContext.h" 12bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon#include "GrRenderTargetContext.h" 13bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon#include "GrTexture.h" 14bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon#include "effects/GrSimpleTextureEffect.h" 15bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 16bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomontemplate <typename I> 17bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomonstatic SK_WHEN(std::is_integral<I>::value && 4 == sizeof(I), void) 1807792b218e1cf31c42611276d597fcc99677d391Brian Osmancheck_pixels(skiatest::Reporter* reporter, int w, int h, const I exepctedData[], 1907792b218e1cf31c42611276d597fcc99677d391Brian Osman const I actualData[], const char* testName) { 20bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon for (int j = 0; j < h; ++j) { 21bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon for (int i = 0; i < w; ++i) { 22bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon I expected = exepctedData[j * w + i]; 23bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon I actual = actualData[j * w + i]; 24bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon if (expected != actual) { 2507792b218e1cf31c42611276d597fcc99677d391Brian Osman ERRORF(reporter, "[%s] Expected 0x08%x, got 0x%08x at %d, %d.", testName, expected, 2607792b218e1cf31c42611276d597fcc99677d391Brian Osman actual, i, j); 27bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon return; 28bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 29bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 30bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 31bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon} 32bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 33bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian SalomonDEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) { 34bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon GrContext* context = ctxInfo.grContext(); 35bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon if (!context->caps()->isConfigTexturable(kRGBA_8888_sint_GrPixelConfig)) { 36bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon return; 37bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 38bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon static const int kS = UINT8_MAX + 1; 39bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon GrSurfaceDesc desc; 40bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon desc.fConfig = kRGBA_8888_sint_GrPixelConfig; 41bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon desc.fWidth = kS; 42bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon desc.fHeight = kS; 43bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon sk_sp<GrTexture> texture; 44bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 45bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon std::unique_ptr<int32_t[]> testData(new int32_t[kS * kS]); 46bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon for (int j = 0; j < kS; ++j) { 47bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon for (int i = 0; i < kS; ++i) { 48bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon uint32_t r = i - INT8_MIN; 49bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon uint32_t g = j - INT8_MIN; 50bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon uint32_t b = INT8_MAX - r; 51bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon uint32_t a = INT8_MAX - g; 52bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon testData.get()[j * kS + i] = (a << 24) | (b << 16) | (g << 8) | r; 53bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 54bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 55bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 56bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // Test that attempting to create a integer texture with multiple MIP level fails. 57bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon GrMipLevel levels[2]; 58bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon levels[0].fPixels = testData.get(); 59bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon levels[0].fRowBytes = kS * sizeof(int32_t); 60bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon levels[1].fPixels = testData.get(); 61bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon levels[1].fRowBytes = (kS / 2) * sizeof(int32_t); 62bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon texture.reset(context->textureProvider()->createMipMappedTexture(desc, SkBudgeted::kYes, levels, 63bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 2)); 64bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, !texture); 65bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 66bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // Test that we can create a integer texture. 67bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon texture.reset(context->textureProvider()->createTexture(desc, SkBudgeted::kYes, 68bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon levels[0].fPixels, 69bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon levels[0].fRowBytes)); 70bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, texture); 71bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon if (!texture) { 72bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon return; 73bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 74bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 75bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // Test that reading to a non-integer config fails. 76bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon std::unique_ptr<int32_t[]> readData(new int32_t[kS * kS]); 77bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon bool success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_GrPixelConfig, readData.get()); 78bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, !success); 79bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon std::unique_ptr<uint16_t[]> halfData(new uint16_t[4 * kS * kS]); 80bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon success = texture->readPixels(0, 0, kS, kS, kRGBA_half_GrPixelConfig, halfData.get()); 81bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, !success); 82bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 83bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // Can read back as ints. (ES only requires being able to read back into 32bit ints which 84bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // we don't support. Right now this test is counting on GR_RGBA_INTEGER/GL_BYTE being the 85bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // implementation-dependent second format). 86bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon sk_bzero(readData.get(), sizeof(int32_t) * kS * kS); 87bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get()); 88bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, success); 89bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon if (success) { 9007792b218e1cf31c42611276d597fcc99677d391Brian Osman check_pixels(reporter, kS, kS, testData.get(), readData.get(), "readPixels"); 91bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 92bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 93bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // readPixels should fail if we attempt to use the unpremul flag with an integer texture. 94bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get(), 0, 95bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon GrContext::kUnpremul_PixelOpsFlag); 96bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, !success); 97bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 98bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // Test that copying from one integer texture to another succeeds. 99e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips { 100e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, desc, 101e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips texture.get(), SkBudgeted::kYes)); 102e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips REPORTER_ASSERT(reporter, copy); 103e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips if (!copy) { 104e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips return; 105e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips } 106e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips 107e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips GrSurface* copySurface = copy->instantiate(context->textureProvider()); 108e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips REPORTER_ASSERT(reporter, copySurface); 109e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips if (!copySurface) { 110e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips return; 111e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips } 112e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips 113e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips sk_bzero(readData.get(), sizeof(int32_t) * kS * kS); 114e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips success = copySurface->readPixels(0, 0, kS, kS, 115e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips kRGBA_8888_sint_GrPixelConfig, readData.get()); 116e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips REPORTER_ASSERT(reporter, success); 117e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips if (success) { 11807792b218e1cf31c42611276d597fcc99677d391Brian Osman check_pixels(reporter, kS, kS, testData.get(), readData.get(), "copyIntegerToInteger"); 119e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips } 120293d696fcfb9f1c83019c4b15c4864cd6649ed78Robert Phillips } 121398487a850431cf495330d4023607df5305a311fRobert Phillips 122e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips 123e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips // Test that copying to a non-integer (8888) texture fails. 124e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips { 125e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips GrSurfaceDesc nonIntDesc = desc; 126e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips nonIntDesc.fConfig = kRGBA_8888_GrPixelConfig; 127e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips 128e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, nonIntDesc, 129e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips texture.get(), SkBudgeted::kYes)); 130e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips REPORTER_ASSERT(reporter, !copy); 131d316e77c1e1967b439a9a6c11146c54e367bff71Robert Phillips } 132e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips 133e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips // Test that copying to a non-integer (RGBA_half) texture fails. 134e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips if (context->caps()->isConfigTexturable(kRGBA_half_GrPixelConfig)) { 135e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips GrSurfaceDesc nonIntDesc = desc; 136e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips nonIntDesc.fConfig = kRGBA_half_GrPixelConfig; 137e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips 138e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips sk_sp<GrSurfaceProxy> copy(GrSurfaceProxy::TestCopy(context, nonIntDesc, 139e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips texture.get(), SkBudgeted::kYes)); 140e2f7d1899d890c2f08571e1bd6c7fa2c5ea1be0bRobert Phillips REPORTER_ASSERT(reporter, !copy); 141bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 142bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 143bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // We overwrite the top left quarter of the texture with the bottom right quarter of the 144bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // original data. 145bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon const void* bottomRightQuarter = testData.get() + kS / 2 * kS + kS / 2; 146bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon size_t rowBytes = kS * sizeof(int32_t); 147bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 148bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // Can't write pixels from a non-int config. 149bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_GrPixelConfig, bottomRightQuarter, 150bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon rowBytes); 151bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, !success); 152bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 153bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // Can't use unpremul flag. 154bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_sint_GrPixelConfig, 155bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon bottomRightQuarter, rowBytes, 156bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon GrContext::kUnpremul_PixelOpsFlag); 157bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, !success); 158bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 159bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_sint_GrPixelConfig, 160bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon bottomRightQuarter, rowBytes); 161bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, success); 162bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon if (!success) { 163bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon return; 164bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 165bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon sk_bzero(readData.get(), sizeof(int32_t) * kS * kS); 166bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get()); 167bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, success); 168bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon if (!success) { 169bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon return; 170bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 171bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon std::unique_ptr<int32_t[]> overwrittenTestData(new int32_t[kS * kS]); 172bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon memcpy(overwrittenTestData.get(), testData.get(), sizeof(int32_t) * kS * kS); 173bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon char* dst = (char*)overwrittenTestData.get(); 174bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon char* src = (char*)(testData.get() + kS/2 * kS + kS/2); 175bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon for (int i = 0; i < kS/2; ++i) { 176bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon memcpy(dst, src, sizeof(int32_t) * kS/2); 177bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon dst += rowBytes; 178bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon src += rowBytes; 179bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 18007792b218e1cf31c42611276d597fcc99677d391Brian Osman check_pixels(reporter, kS, kS, overwrittenTestData.get(), readData.get(), "overwrite"); 181bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 182bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // Test drawing from the integer texture to a fixed point texture. To avoid any premul issues 183bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // we init the int texture with 0s and 1s and make alpha always be 1. We expect that 1s turn 184bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // into 0xffs and zeros stay zero. 185bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon std::unique_ptr<uint32_t[]> expectedData(new uint32_t[kS * kS]); 186bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon std::unique_ptr<uint32_t[]> actualData(new uint32_t[kS * kS]); 187bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon for (int i = 0; i < kS*kS; ++i) { 188bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon int32_t a = 0x1; 189bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon int32_t b = ((i & 0x1) ? 1 : 0); 190bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon int32_t g = ((i & 0x1) ? 0 : 1); 191bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon int32_t r = ((i & 0x2) ? 1 : 0); 192bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon testData.get()[i] = (a << 24) | (b << 16) | (g << 8) | r; 193bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon expectedData.get()[i] = ((0xFF * a) << 24) | ((0xFF * b) << 16) | 194bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon ((0xFF * g) << 8) | (0xFF * r); 195bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 196bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon texture->writePixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, testData.get()); 197bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon sk_sp<GrRenderTargetContext> rtContext = context->makeRenderTargetContext( 198bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon SkBackingFit::kExact, kS, kS, kRGBA_8888_GrPixelConfig, nullptr); 199bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 20007792b218e1cf31c42611276d597fcc99677d391Brian Osman struct { 20107792b218e1cf31c42611276d597fcc99677d391Brian Osman GrSamplerParams::FilterMode fMode; 20207792b218e1cf31c42611276d597fcc99677d391Brian Osman const char* fName; 20307792b218e1cf31c42611276d597fcc99677d391Brian Osman } kNamedFilters[] ={ 20407792b218e1cf31c42611276d597fcc99677d391Brian Osman { GrSamplerParams::kNone_FilterMode, "filter-none" }, 20507792b218e1cf31c42611276d597fcc99677d391Brian Osman { GrSamplerParams::kBilerp_FilterMode, "filter-bilerp" }, 20607792b218e1cf31c42611276d597fcc99677d391Brian Osman { GrSamplerParams::kMipMap_FilterMode, "filter-mipmap" } 20707792b218e1cf31c42611276d597fcc99677d391Brian Osman }; 20807792b218e1cf31c42611276d597fcc99677d391Brian Osman 20907792b218e1cf31c42611276d597fcc99677d391Brian Osman for (auto filter : kNamedFilters) { 21067c18d6b5188a0497f6912a73d964c763d2f8f84Robert Phillips sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), nullptr, 21167c18d6b5188a0497f6912a73d964c763d2f8f84Robert Phillips SkMatrix::I(), 21207792b218e1cf31c42611276d597fcc99677d391Brian Osman filter.fMode)); 213bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, fp); 214bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon if (!fp) { 215bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon return; 216bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 217bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon rtContext->clear(nullptr, 0xDDAABBCC, true); 218bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon GrPaint paint; 219bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon paint.setPorterDuffXPFactory(SkBlendMode::kSrc); 220bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon paint.addColorFragmentProcessor(fp); 22182f44319159bb98dcacdbbec7ea643dde5ed024bBrian Salomon rtContext->drawPaint(GrNoClip(), std::move(paint), SkMatrix::I()); 222bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon SkImageInfo readInfo = SkImageInfo::Make(kS, kS, kRGBA_8888_SkColorType, 223bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon kPremul_SkAlphaType); 224bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon rtContext->readPixels(readInfo, actualData.get(), 0, 0, 0); 22507792b218e1cf31c42611276d597fcc99677d391Brian Osman check_pixels(reporter, kS, kS, expectedData.get(), actualData.get(), filter.fName); 226bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon } 227bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 228bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon // No rendering to integer textures. 229bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon GrSurfaceDesc intRTDesc = desc; 230bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon intRTDesc.fFlags = kRenderTarget_GrSurfaceFlag; 231bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon texture.reset(context->textureProvider()->createTexture(intRTDesc, SkBudgeted::kYes)); 232bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon REPORTER_ASSERT(reporter, !texture); 233bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon} 234bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon 235bf7b620b1e44985b164a8bd68031a7613fe0bb9bBrian Salomon#endif 236