Revert "Add integer texture support."

This reverts commit 434c534bd0.

Reason for revert: Undefined behavior. From

https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Ubuntu-Clang-Golo-GPU-GT610-x86_64-Debug-ASAN/builds/1272/steps/test_skia%20on%20Ubuntu/logs/stdio

../../../tests/IntTextureTest.cpp:51:44: runtime error: left shift of negative value -1
    #0 0x2257480 in test_IntTexture(skiatest::Reporter*, sk_gpu_test::ContextInfo const&) (/b/swarm_slave/w/ir0aO1sa/out/Debug/dm+0x2257480)
    #1 0x1ca1066 in skiatest::RunWithGPUTestContexts(void (*)(skiatest::Reporter*, sk_gpu_test::ContextInfo const&), bool (*)(sk_gpu_test::GrContextFactory::ContextType), skiatest::Reporter*, sk_gpu_test::GrContextFactory*) (/b/swarm_slave/w/ir0aO1sa/out/Debug/dm+0x1ca1066)
    #2 0x1ca080d in run_test(skiatest::Test) (/b/swarm_slave/w/ir0aO1sa/out/Debug/dm+0x1ca080d)
    #3 0x1c9e5e9 in dm_main() (/b/swarm_slave/w/ir0aO1sa/out/Debug/dm+0x1c9e5e9)
    #4 0x7f2d2ba8df44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
    #5 0x1bb3028 in _start (/b/swarm_slave/w/ir0aO1sa/out/Debug/dm+0x1bb3028)

SUMMARY: AddressSanitizer: undefined-behavior ../../../tests/IntTextureTest.cpp:51:44 in 
step returned non-zero exit code: 1


Original change's description:
> Add integer texture support.
> 
> This allows us to create integer textures and sample them from a GrProcessor's code.
> 
> Filtering is limited to NEAREST.
> 
> Adds tests for reading/writing pixels, copying, and drawing. These operations are not allowed to convert to fixed/float configs.
> 
> Vulkan support is TBD.
> 
> 
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4348
> 
> Change-Id: If38d89a03285d4bd98d1f14f9638b0320977e43d
> Reviewed-on: https://skia-review.googlesource.com/4348
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Chris Dalton <csmartdalton@google.com>
> 

TBR=bsalomon@google.com,csmartdalton@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: I39f1a0a0dd3e6cde1143c8cc1217d2e3d5977b21
Reviewed-on: https://skia-review.googlesource.com/4663
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
This commit is contained in:
Leon Scroggins 2016-11-10 18:31:58 +00:00 committed by Skia Commit-Bot
parent 805eb6c777
commit 9c7edb8311
25 changed files with 233 additions and 680 deletions

View File

@ -109,7 +109,6 @@ tests_sources = [
"$_tests/IndexedPngOverflowTest.cpp",
"$_tests/InfRectTest.cpp",
"$_tests/InterpolatorTest.cpp",
"$_tests/IntTextureTest.cpp",
"$_tests/InvalidIndexedPngTest.cpp",
"$_tests/IsClosedSingleContourTest.cpp",
"$_tests/LayerDrawLooperTest.cpp",

View File

@ -295,7 +295,6 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) {
kRGBA_GrColorComponentFlags, // kBGRA_8888_GrPixelConfig
kRGBA_GrColorComponentFlags, // kSRGBA_8888_GrPixelConfig
kRGBA_GrColorComponentFlags, // kSBGRA_8888_GrPixelConfig
kRGBA_GrColorComponentFlags, // kRGBA_8888_sint_GrPixelConfig
kRGB_GrColorComponentFlags, // kETC1_GrPixelConfig
kA_GrColorComponentFlag, // kLATC_GrPixelConfig
kA_GrColorComponentFlag, // kR11_EAC_GrPixelConfig
@ -315,14 +314,13 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) {
GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(9 == kRGBA_8888_sint_GrPixelConfig);
GR_STATIC_ASSERT(10 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(11 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(12 == kR11_EAC_GrPixelConfig);
GR_STATIC_ASSERT(13 == kASTC_12x12_GrPixelConfig);
GR_STATIC_ASSERT(14 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(15 == kAlpha_half_GrPixelConfig);
GR_STATIC_ASSERT(16 == kRGBA_half_GrPixelConfig);
GR_STATIC_ASSERT(9 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(10 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(11 == kR11_EAC_GrPixelConfig);
GR_STATIC_ASSERT(12 == kASTC_12x12_GrPixelConfig);
GR_STATIC_ASSERT(13 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(14 == kAlpha_half_GrPixelConfig);
GR_STATIC_ASSERT(15 == kRGBA_half_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt);
}

View File

@ -229,10 +229,6 @@ enum GrPixelConfig {
* Premultiplied and sRGB. Byte order is b,g,r,a.
*/
kSBGRA_8888_GrPixelConfig,
/**
* 8 bit signed integers per-channel. Byte order is b,g,r,a.
*/
kRGBA_8888_sint_GrPixelConfig,
/**
* ETC1 Compressed Data
*/
@ -322,7 +318,7 @@ static inline GrPixelConfig GrMakePixelConfigUncompressed(GrPixelConfig config)
}
// Returns true if the pixel config is 32 bits per pixel
static inline bool GrPixelConfigIs8888Unorm(GrPixelConfig config) {
static inline bool GrPixelConfigIs8888(GrPixelConfig config) {
switch (config) {
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
@ -376,7 +372,6 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
case kSBGRA_8888_GrPixelConfig:
case kRGBA_8888_sint_GrPixelConfig:
return 4;
case kRGBA_half_GrPixelConfig:
return 8;
@ -421,10 +416,6 @@ static inline bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) {
}
}
static inline bool GrPixelConfigIsSint(GrPixelConfig config) {
return config == kRGBA_8888_sint_GrPixelConfig;
}
/**
* Optional bitfield flags that can be set on GrSurfaceDesc (below).
*/

View File

@ -25,7 +25,6 @@ enum GrSLType {
kMat33f_GrSLType,
kMat44f_GrSLType,
kTexture2DSampler_GrSLType,
kTexture2DISampler_GrSLType,
kTextureExternalSampler_GrSLType,
kTexture2DRectSampler_GrSLType,
kTextureBufferSampler_GrSLType,
@ -88,7 +87,7 @@ static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
*/
static inline int GrSLTypeVectorCount(GrSLType type) {
SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, -1 };
static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1 };
return kCounts[type];
GR_STATIC_ASSERT(0 == kVoid_GrSLType);
@ -100,15 +99,14 @@ static inline int GrSLTypeVectorCount(GrSLType type) {
GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(13 == kBool_GrSLType);
GR_STATIC_ASSERT(14 == kInt_GrSLType);
GR_STATIC_ASSERT(15 == kUint_GrSLType);
GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(17 == kSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(12 == kBool_GrSLType);
GR_STATIC_ASSERT(13 == kInt_GrSLType);
GR_STATIC_ASSERT(14 == kUint_GrSLType);
GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(16 == kSampler_GrSLType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
}
@ -138,16 +136,15 @@ static inline bool GrSLTypeIsFloatType(GrSLType type) {
GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(13 == kBool_GrSLType);
GR_STATIC_ASSERT(14 == kInt_GrSLType);
GR_STATIC_ASSERT(15 == kUint_GrSLType);
GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(17 == kSampler_GrSLType);
GR_STATIC_ASSERT(18 == kGrSLTypeCount);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(12 == kBool_GrSLType);
GR_STATIC_ASSERT(13 == kInt_GrSLType);
GR_STATIC_ASSERT(14 == kUint_GrSLType);
GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(16 == kSampler_GrSLType);
GR_STATIC_ASSERT(17 == kGrSLTypeCount);
}
/** Is the shading language type integral (including vectors/matrices)? */
@ -164,16 +161,15 @@ static inline bool GrSLTypeIsIntType(GrSLType type) {
GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(13 == kBool_GrSLType);
GR_STATIC_ASSERT(14 == kInt_GrSLType);
GR_STATIC_ASSERT(15 == kUint_GrSLType);
GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(17 == kSampler_GrSLType);
GR_STATIC_ASSERT(18 == kGrSLTypeCount);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(12 == kBool_GrSLType);
GR_STATIC_ASSERT(13 == kInt_GrSLType);
GR_STATIC_ASSERT(14 == kUint_GrSLType);
GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(16 == kSampler_GrSLType);
GR_STATIC_ASSERT(17 == kGrSLTypeCount);
}
/** Is the shading language type numeric (including vectors/matrices)? */
@ -194,7 +190,6 @@ static inline size_t GrSLTypeSize(GrSLType type) {
3 * 3 * sizeof(float), // kMat33f_GrSLType
4 * 4 * sizeof(float), // kMat44f_GrSLType
0, // kTexture2DSampler_GrSLType
0, // kTexture2DISampler_GrSLType
0, // kTextureExternalSampler_GrSLType
0, // kTexture2DRectSampler_GrSLType
0, // kTextureBufferSampler_GrSLType
@ -215,16 +210,15 @@ static inline size_t GrSLTypeSize(GrSLType type) {
GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(13 == kBool_GrSLType);
GR_STATIC_ASSERT(14 == kInt_GrSLType);
GR_STATIC_ASSERT(15 == kUint_GrSLType);
GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(17 == kSampler_GrSLType);
GR_STATIC_ASSERT(18 == kGrSLTypeCount);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(12 == kBool_GrSLType);
GR_STATIC_ASSERT(13 == kInt_GrSLType);
GR_STATIC_ASSERT(14 == kUint_GrSLType);
GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(16 == kSampler_GrSLType);
GR_STATIC_ASSERT(17 == kGrSLTypeCount);
}
static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
@ -232,9 +226,8 @@ static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
return type >= kTexture2DSampler_GrSLType && type <= kTexture2DRectSampler_GrSLType;
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
}
static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
@ -242,10 +235,9 @@ static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
return type >= kTexture2DSampler_GrSLType && type <= kTextureBufferSampler_GrSLType;
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
}
static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {

View File

@ -241,23 +241,22 @@ SkString GrCaps::dump() const {
map_flags_to_string(fMapBufferFlags).c_str());
static const char* kConfigNames[] = {
"Unknown", // kUnknown_GrPixelConfig
"Alpha8", // kAlpha_8_GrPixelConfig,
"Index8", // kIndex_8_GrPixelConfig,
"RGB565", // kRGB_565_GrPixelConfig,
"RGBA444", // kRGBA_4444_GrPixelConfig,
"RGBA8888", // kRGBA_8888_GrPixelConfig,
"BGRA8888", // kBGRA_8888_GrPixelConfig,
"SRGBA8888", // kSRGBA_8888_GrPixelConfig,
"SBGRA8888", // kSBGRA_8888_GrPixelConfig,
"RGBA8888_sint", // kRGBA_8888_sint_GrPixelConfig,
"ETC1", // kETC1_GrPixelConfig,
"LATC", // kLATC_GrPixelConfig,
"R11EAC", // kR11_EAC_GrPixelConfig,
"ASTC12x12", // kASTC_12x12_GrPixelConfig,
"RGBAFloat", // kRGBA_float_GrPixelConfig
"AlphaHalf", // kAlpha_half_GrPixelConfig
"RGBAHalf", // kRGBA_half_GrPixelConfig
"Unknown", // kUnknown_GrPixelConfig
"Alpha8", // kAlpha_8_GrPixelConfig,
"Index8", // kIndex_8_GrPixelConfig,
"RGB565", // kRGB_565_GrPixelConfig,
"RGBA444", // kRGBA_4444_GrPixelConfig,
"RGBA8888", // kRGBA_8888_GrPixelConfig,
"BGRA8888", // kBGRA_8888_GrPixelConfig,
"SRGBA8888",// kSRGBA_8888_GrPixelConfig,
"SBGRA8888",// kSBGRA_8888_GrPixelConfig,
"ETC1", // kETC1_GrPixelConfig,
"LATC", // kLATC_GrPixelConfig,
"R11EAC", // kR11_EAC_GrPixelConfig,
"ASTC12x12",// kASTC_12x12_GrPixelConfig,
"RGBAFloat",// kRGBA_float_GrPixelConfig
"AlphaHalf",// kAlpha_half_GrPixelConfig
"RGBAHalf", // kRGBA_half_GrPixelConfig
};
GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
@ -268,14 +267,13 @@ SkString GrCaps::dump() const {
GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(9 == kRGBA_8888_sint_GrPixelConfig);
GR_STATIC_ASSERT(10 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(11 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(12 == kR11_EAC_GrPixelConfig);
GR_STATIC_ASSERT(13 == kASTC_12x12_GrPixelConfig);
GR_STATIC_ASSERT(14 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(15 == kAlpha_half_GrPixelConfig);
GR_STATIC_ASSERT(16 == kRGBA_half_GrPixelConfig);
GR_STATIC_ASSERT(9 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(10 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(11 == kR11_EAC_GrPixelConfig);
GR_STATIC_ASSERT(12 == kASTC_12x12_GrPixelConfig);
GR_STATIC_ASSERT(13 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(14 == kAlpha_half_GrPixelConfig);
GR_STATIC_ASSERT(15 == kRGBA_half_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false));

View File

@ -266,15 +266,11 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
bool applyPremulToSrc = false;
if (kUnpremul_PixelOpsFlag & pixelOpsFlags) {
if (!GrPixelConfigIs8888Unorm(srcConfig)) {
if (!GrPixelConfigIs8888(srcConfig)) {
return false;
}
applyPremulToSrc = true;
}
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(surface->config()) != GrPixelConfigIsSint(srcConfig)) {
return false;
}
GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference;
// Don't prefer to draw for the conversion (and thereby access a texture from the cache) when
@ -415,14 +411,10 @@ bool GrContext::readSurfacePixels(GrSurface* src,
}
bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags);
if (unpremul && !GrPixelConfigIs8888Unorm(dstConfig)) {
if (unpremul && !GrPixelConfigIs8888(dstConfig)) {
// The unpremul flag is only allowed for 8888 configs.
return false;
}
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(src->config()) != GrPixelConfigIsSint(dstConfig)) {
return false;
}
GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference;
// Don't prefer to draw for the conversion (and thereby access a texture from the cache) when
@ -548,11 +540,6 @@ bool GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
ASSERT_OWNED_RESOURCE(src);
ASSERT_OWNED_RESOURCE(dst);
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(dst->config()) != GrPixelConfigIsSint(src->config())) {
return false;
}
if (!dst->asRenderTarget()) {
SkIRect clippedSrcRect;
SkIPoint clippedDstPoint;
@ -696,7 +683,6 @@ static inline GrPixelConfig GrPixelConfigFallback(GrPixelConfig config) {
kRGBA_8888_GrPixelConfig, // kBGRA_8888_GrPixelConfig
kUnknown_GrPixelConfig, // kSRGBA_8888_GrPixelConfig
kSRGBA_8888_GrPixelConfig, // kSBGRA_8888_GrPixelConfig
kUnknown_GrPixelConfig, // kRGBA_8888_sint_GrPixelConfig
kUnknown_GrPixelConfig, // kETC1_GrPixelConfig
kUnknown_GrPixelConfig, // kLATC_GrPixelConfig
kUnknown_GrPixelConfig, // kR11_EAC_GrPixelConfig
@ -716,14 +702,13 @@ static inline GrPixelConfig GrPixelConfigFallback(GrPixelConfig config) {
GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig);
GR_STATIC_ASSERT(9 == kRGBA_8888_sint_GrPixelConfig);
GR_STATIC_ASSERT(10 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(11 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(12 == kR11_EAC_GrPixelConfig);
GR_STATIC_ASSERT(13 == kASTC_12x12_GrPixelConfig);
GR_STATIC_ASSERT(14 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(15 == kAlpha_half_GrPixelConfig);
GR_STATIC_ASSERT(16 == kRGBA_half_GrPixelConfig);
GR_STATIC_ASSERT(9 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(10 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(11 == kR11_EAC_GrPixelConfig);
GR_STATIC_ASSERT(12 == kASTC_12x12_GrPixelConfig);
GR_STATIC_ASSERT(13 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(14 == kAlpha_half_GrPixelConfig);
GR_STATIC_ASSERT(15 == kRGBA_half_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFallback) == kGrPixelConfigCnt);
}

View File

@ -104,10 +104,6 @@ static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDes
return false;
}
if (GrPixelConfigIsSint(desc.fConfig) && texels.count() > 1) {
return false;
}
*isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
return false;
@ -266,13 +262,6 @@ bool GrGpu::copySurface(GrSurface* dst,
const SkIPoint& dstPoint) {
SkASSERT(dst && src);
this->handleDirtyContext();
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(dst->config()) != GrPixelConfigIsSint(src->config())) {
return false;
}
if (GrPixelConfigIsCompressed(dst->config())) {
return false;
}
return this->onCopySurface(dst, src, srcRect, dstPoint);
}
@ -281,14 +270,8 @@ bool GrGpu::getReadPixelsInfo(GrSurface* srcSurface, int width, int height, size
ReadPixelTempDrawInfo* tempDrawInfo) {
SkASSERT(drawPreference);
SkASSERT(tempDrawInfo);
SkASSERT(srcSurface);
SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference);
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(srcSurface->config()) != GrPixelConfigIsSint(readConfig)) {
return false;
}
// We currently do not support reading into a compressed buffer
if (GrPixelConfigIsCompressed(readConfig)) {
return false;
@ -322,7 +305,6 @@ bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height,
WritePixelTempDrawInfo* tempDrawInfo) {
SkASSERT(drawPreference);
SkASSERT(tempDrawInfo);
SkASSERT(dstSurface);
SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference);
if (GrPixelConfigIsCompressed(dstSurface->desc().fConfig) &&
@ -330,11 +312,6 @@ bool GrGpu::getWritePixelsInfo(GrSurface* dstSurface, int width, int height,
return false;
}
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(dstSurface->config()) != GrPixelConfigIsSint(srcConfig)) {
return false;
}
if (SkToBool(dstSurface->asRenderTarget())) {
if (this->caps()->useDrawInsteadOfAllRenderTargetWrites()) {
ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
@ -366,12 +343,7 @@ bool GrGpu::readPixels(GrSurface* surface,
int left, int top, int width, int height,
GrPixelConfig config, void* buffer,
size_t rowBytes) {
SkASSERT(surface);
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(surface->config()) != GrPixelConfigIsSint(config)) {
return false;
}
this->handleDirtyContext();
// We cannot read pixels into a compressed buffer
if (GrPixelConfigIsCompressed(config)) {
@ -386,8 +358,6 @@ bool GrGpu::readPixels(GrSurface* surface,
return false;
}
this->handleDirtyContext();
return this->onReadPixels(surface,
left, top, width, height,
config, buffer,
@ -397,18 +367,15 @@ bool GrGpu::readPixels(GrSurface* surface,
bool GrGpu::writePixels(GrSurface* surface,
int left, int top, int width, int height,
GrPixelConfig config, const SkTArray<GrMipLevel>& texels) {
SkASSERT(surface);
if (!surface) {
return false;
}
for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) {
if (!texels[currentMipLevel].fPixels ) {
return false;
}
}
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(surface->config()) != GrPixelConfigIsSint(config)) {
return false;
}
this->handleDirtyContext();
if (this->onWritePixels(surface, left, top, width, height, config, texels)) {
SkIRect rect = SkIRect::MakeXYWH(left, top, width, height);
@ -439,11 +406,6 @@ bool GrGpu::transferPixels(GrSurface* surface,
SkASSERT(transferBuffer);
SkASSERT(fence);
// We don't allow conversion between integer configs and float/fixed configs.
if (GrPixelConfigIsSint(surface->config()) != GrPixelConfigIsSint(config)) {
return false;
}
this->handleDirtyContext();
if (this->onTransferPixels(surface, left, top, width, height, config,
transferBuffer, offset, rowBytes)) {

View File

@ -48,9 +48,7 @@ GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
return nullptr;
}
}
if (mipLevelCount > 1 && GrPixelConfigIsSint(desc.fConfig)) {
return nullptr;
}
if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
!fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
return nullptr;
@ -86,10 +84,10 @@ GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete
GrMipLevel* texels = nullptr;
int levelCount = 0;
if (srcData) {
tempTexels.fPixels = srcData;
tempTexels.fRowBytes = rowBytes;
texels = &tempTexels;
levelCount = 1;
tempTexels.fPixels = srcData;
tempTexels.fRowBytes = rowBytes;
texels = &tempTexels;
levelCount = 1;
}
return this->createMipMappedTexture(desc, budgeted, texels, levelCount);
}

View File

@ -63,12 +63,7 @@ GrBatch* GrCopySurfaceBatch::Create(GrSurface* dst, GrSurface* src, const SkIRec
const SkIPoint& dstPoint) {
SkASSERT(dst);
SkASSERT(src);
if (GrPixelConfigIsSint(dst->config()) != GrPixelConfigIsSint(src->config())) {
return nullptr;
}
if (GrPixelConfigIsCompressed(dst->config())) {
return nullptr;
}
SkIRect clippedSrcRect;
SkIPoint clippedDstPoint;
// If the rect is outside the src or dst then we've already succeeded.

View File

@ -863,10 +863,6 @@ bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
return false;
}
if (GrPixelConfigIsSint(surfaceConfig) != GrPixelConfigIsSint(readConfig)) {
return false;
}
GrGLenum readFormat;
GrGLenum readType;
if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
@ -878,11 +874,8 @@ bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
// the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
// GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
// GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
// The manual does not seem to fully match the spec as the spec allows integer formats
// when the bound color buffer is an integer buffer. It doesn't specify which integer
// formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
readFormat != GR_GL_BGRA && readFormat != GR_GL_RGBA_INTEGER) {
readFormat != GR_GL_BGRA) {
return false;
}
// There is also a set of allowed types, but all the types we use are in the set:
@ -897,22 +890,16 @@ bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
}
// See Section 16.1.2 in the ES 3.2 specification.
switch (fConfigTable[surfaceConfig].fFormatType) {
case kNormalizedFixedPoint_FormatType:
if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
return true;
}
break;
case kInteger_FormatType:
if (GR_GL_RGBA_INTEGER == readFormat && GR_GL_INT == readType) {
return true;
}
break;
case kFloat_FormatType:
if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
return true;
}
break;
if (kNormalizedFixedPoint_FormatType == fConfigTable[surfaceConfig].fFormatType) {
if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
return true;
}
} else {
SkASSERT(kFloat_FormatType == fConfigTable[surfaceConfig].fFormatType);
if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
return true;
}
}
if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
@ -1582,33 +1569,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
}
fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bool hasIntegerTextures;
if (standard == kGL_GrGLStandard) {
hasIntegerTextures = version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_EXT_texture_integer");
} else {
hasIntegerTextures = (version >= GR_GL_VER(3, 0));
}
// We may have limited GLSL to an earlier version that doesn't have integer sampler types.
if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
hasIntegerTextures = false;
}
fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA_INTEGER;
fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8I;
fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RGBA_INTEGER;
fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fExternalType = GR_GL_BYTE;
fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormatType = kInteger_FormatType;
// We currently only support using integer textures as srcs, not for rendering (even though GL
// allows it).
if (hasIntegerTextures) {
fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
ConfigInfo::kFBOColorAttachment_Flag;
if (texStorageSupported) {
fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags |=
ConfigInfo::kCanUseTexStorage_Flag;
}
}
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
if (this->ES2CompatibilitySupport()) {
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;

View File

@ -425,7 +425,6 @@ private:
enum FormatType {
kNormalizedFixedPoint_FormatType,
kFloat_FormatType,
kInteger_FormatType,
};
struct ReadPixelsFormat {

View File

@ -408,112 +408,24 @@
#define GR_GL_LINE_WIDTH_GRANULARITY 0x0B23
#define GR_GL_LINE_WIDTH_RANGE 0x0B22
/* Unsized formats */
#define GR_GL_STENCIL_INDEX 0x1901
/* PixelFormat */
#define GR_GL_DEPTH_COMPONENT 0x1902
#define GR_GL_DEPTH_STENCIL 0x84F9
#define GR_GL_RED 0x1903
#define GR_GL_RED_INTEGER 0x8D94
#define GR_GL_GREEN 0x1904
#define GR_GL_BLUE 0x1905
#define GR_GL_ALPHA 0x1906
#define GR_GL_RGB 0x1907
#define GR_GL_RGBA 0x1908
#define GR_GL_BGRA 0x80E1
#define GR_GL_LUMINANCE 0x1909
#define GR_GL_LUMINANCE_ALPHA 0x190A
#define GR_GL_RG_INTEGER 0x8228
#define GR_GL_RGB 0x1907
#define GR_GL_RGB_INTEGER 0x8D98
#define GR_GL_SRGB 0x8C40
#define GR_GL_RGBA 0x1908
#define GR_GL_SRGB_ALPHA 0x8C42
#define GR_GL_RGBA_INTEGER 0x8D99
#define GR_GL_BGRA 0x80E1
/* Stencil index sized formats */
#define GR_GL_STENCIL_INDEX4 0x8D47
#define GR_GL_STENCIL_INDEX8 0x8D48
#define GR_GL_STENCIL_INDEX16 0x8D49
/* Depth component sized formats */
#define GR_GL_DEPTH_COMPONENT16 0x81A5
/* Depth stencil sized formats */
#define GR_GL_DEPTH24_STENCIL8 0x88F0
/* Red sized formats */
#define GR_GL_R8 0x8229
#define GR_GL_R16 0x822A
#define GR_GL_R16F 0x822D
#define GR_GL_R32F 0x822E
/* Red integer sized formats */
#define GR_GL_R8I 0x8231
#define GR_GL_R8UI 0x8232
#define GR_GL_R16I 0x8233
#define GR_GL_R16UI 0x8234
#define GR_GL_R32I 0x8235
#define GR_GL_R32UI 0x8236
/* Alpha sized formats */
#define GR_GL_ALPHA8 0x803C
#define GR_GL_ALPHA16 0x803E
#define GR_GL_ALPHA16F 0x881C
#define GR_GL_ALPHA32F 0x8816
/* Alpha integer sized formats */
#define GR_GL_ALPHA8I 0x8D90
#define GR_GL_ALPHA8UI 0x8D7E
#define GR_GL_ALPHA16I 0x8D8A
#define GR_GL_ALPHA16UI 0x8D78
#define GR_GL_ALPHA32I 0x8D84
#define GR_GL_ALPHA32UI 0x8D72
/* RG sized formats */
#define GR_GL_RG8 0x822B
#define GR_GL_RG16 0x822C
#define GR_GL_R16F 0x822D
#define GR_GL_R32F 0x822E
/* RG sized integer formats */
#define GR_GL_RG8I 0x8237
#define GR_GL_RG8UI 0x8238
#define GR_GL_RG16I 0x8239
#define GR_GL_RG16UI 0x823A
#define GR_GL_RG32I 0x823B
#define GR_GL_RG32UI 0x823C
/* RGB sized formats */
#define GR_GL_RGB5 0x8050
#define GR_GL_RGB565 0x8D62
#define GR_GL_RGB8 0x8051
#define GR_GL_SRGB8 0x8C41
/* RGB integer sized formats */
#define GR_GL_RGB8I 0x8D8F
#define GR_GL_RGB8UI 0x8D7D
#define GR_GL_RGB16I 0x8D89
#define GR_GL_RGB16UI 0x8D77
#define GR_GL_RGB32I 0x8D83
#define GR_GL_RGB32UI 0x8D71
/* RGBA sized formats */
#define GR_GL_RGBA4 0x8056
#define GR_GL_RGB5_A1 0x8057
#define GR_GL_PALETTE8_RGBA8 0x8B96
#define GR_GL_RGBA8 0x8058
#define GR_GL_SRGB8_ALPHA8 0x8C43
#define GR_GL_ALPHA8 0x803C
#define GR_GL_R8 0x8229
#define GR_GL_R16F 0x822D
#define GR_GL_RGBA16F 0x881A
#define GR_GL_RGBA32F 0x8814
/* RGBA integer sized formats */
#define GR_GL_RGBA8I 0x8D8E
#define GR_GL_RGBA8UI 0x8D7C
#define GR_GL_RGBA16I 0x8D88
#define GR_GL_RGBA16UI 0x8D76
#define GR_GL_RGBA32I 0x8D82
#define GR_GL_RGBA32UI 0x8D70
/* BGRA sized formats */
#define GR_GL_BGRA8 0x93A1
#define GR_GL_ALPHA16F 0x881C
/* PixelType */
/* GL_UNSIGNED_BYTE */
@ -870,6 +782,26 @@
#define GR_GL_RENDERBUFFER 0x8D41
#define GR_GL_RGBA4 0x8056
#define GR_GL_RGB5_A1 0x8057
#define GR_GL_RGB565 0x8D62
#define GR_GL_RGBA8 0x8058
#define GR_GL_RGBA32F 0x8814
#define GR_GL_RGB5 0x8050
#define GR_GL_RGB8 0x8051
#define GR_GL_BGRA8 0x93A1
#define GR_GL_SRGB 0x8C40
#define GR_GL_SRGB8 0x8C41
#define GR_GL_SRGB_ALPHA 0x8C42
#define GR_GL_SRGB8_ALPHA8 0x8C43
#define GR_GL_DEPTH_COMPONENT16 0x81A5
#define GR_GL_STENCIL_INDEX 0x1901
#define GR_GL_STENCIL_INDEX4 0x8D47
#define GR_GL_STENCIL_INDEX8 0x8D48
#define GR_GL_STENCIL_INDEX16 0x8D49
#define GR_GL_DEPTH_STENCIL 0x84F9
#define GR_GL_DEPTH24_STENCIL8 0x88F0
#define GR_GL_MAX_SAMPLES 0x8D57
// GL_IMG_multisampled_render_to_texture uses a different value for GL_MAX_SAMPLES
#define GR_GL_MAX_SAMPLES_IMG 0x9135

View File

@ -922,7 +922,6 @@ static inline GrGLint config_alignment(GrPixelConfig config) {
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
case kSBGRA_8888_GrPixelConfig:
case kRGBA_8888_sint_GrPixelConfig:
case kRGBA_float_GrPixelConfig:
return 4;
default:
@ -972,14 +971,14 @@ static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc
// This means if we may later want to add mipmaps, we cannot use TexStorage.
// Right now, we cannot know if we will later add mipmaps or not.
// The only time we can use TexStorage is when we already have the
// mipmaps or are using a format incompatible with MIP maps.
useTexStorage &= texels.count() > 1 || GrPixelConfigIsSint(desc.fConfig);
// mipmaps.
useTexStorage &= texels.count() > 1;
if (useTexStorage) {
// We never resize or change formats of textures.
GL_ALLOC_CALL(&interface,
TexStorage2D(target,
SkTMax(texels.count(), 1),
texels.count(),
internalFormatForTexStorage,
desc.fWidth, desc.fHeight));
GrGLenum error = check_alloc_error(desc, &interface);
@ -3489,9 +3488,6 @@ static inline bool can_blit_framebuffer_for_copy_surface(const GrSurface* dst,
!gpu->glCaps().canConfigBeFBOColorAttachment(src->config())) {
return false;
}
// Blits are not allowed between int color buffers and float/fixed color buffers. GrGpu should
// have filtered such cases out.
SkASSERT(GrPixelConfigIsSint(dst->config()) == GrPixelConfigIsSint(src->config()));
const GrGLTexture* dstTex = static_cast<const GrGLTexture*>(dst->asTexture());
const GrGLTexture* srcTex = static_cast<const GrGLTexture*>(dst->asTexture());
const GrRenderTarget* dstRT = dst->asRenderTarget();
@ -3727,10 +3723,19 @@ bool GrGLGpu::onCopySurface(GrSurface* dst,
return false;
}
bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
int progIdx = TextureToCopyProgramIdx(srcTex);
bool GrGLGpu::createCopyProgram(int progIdx) {
const GrGLSLCaps* glslCaps = this->glCaps().glslCaps();
GrSLType samplerType = srcTex->texturePriv().samplerType();
static const GrSLType kSamplerTypes[3] = { kTexture2DSampler_GrSLType,
kTextureExternalSampler_GrSLType,
kTexture2DRectSampler_GrSLType };
if (kTextureExternalSampler_GrSLType == kSamplerTypes[progIdx] &&
!this->glCaps().glslCaps()->externalTextureSupport()) {
return false;
}
if (kTexture2DRectSampler_GrSLType == kSamplerTypes[progIdx] &&
!this->glCaps().rectangleTextureSupport()) {
return false;
}
if (!fCopyProgramArrayBuffer) {
static const GrGLfloat vdata[] = {
@ -3758,7 +3763,7 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
GrShaderVar::kUniform_TypeModifier);
GrGLSLShaderVar uPosXform("u_posXform", kVec4f_GrSLType,
GrShaderVar::kUniform_TypeModifier);
GrGLSLShaderVar uTexture("u_texture", samplerType,
GrGLSLShaderVar uTexture("u_texture", kSamplerTypes[progIdx],
GrShaderVar::kUniform_TypeModifier);
GrGLSLShaderVar vTexCoord("v_texCoord", kVec2f_GrSLType,
GrShaderVar::kVaryingOut_TypeModifier);
@ -3797,7 +3802,7 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
fshaderTxt.appendf("#extension %s : require\n", extension);
}
}
if (samplerType == kTextureExternalSampler_GrSLType) {
if (kSamplerTypes[progIdx] == kTextureExternalSampler_GrSLType) {
fshaderTxt.appendf("#extension %s : require\n",
glslCaps->externalTextureExtensionString());
}
@ -3813,7 +3818,7 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
"void main() {"
" sk_FragColor = %s(u_texture, v_texCoord);"
"}",
GrGLSLTexture2DFunctionName(kVec2f_GrSLType, samplerType, this->glslGeneration())
GrGLSLTexture2DFunctionName(kVec2f_GrSLType, kSamplerTypes[progIdx], this->glslGeneration())
);
const char* str;
@ -4165,10 +4170,10 @@ bool GrGLGpu::copySurfaceAsDraw(GrSurface* dst,
const SkIRect& srcRect,
const SkIPoint& dstPoint) {
GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture());
int progIdx = TextureToCopyProgramIdx(srcTex);
int progIdx = TextureTargetToCopyProgramIdx(srcTex->target());
if (!fCopyPrograms[progIdx].fProgram) {
if (!this->createCopyProgram(srcTex)) {
if (!this->createCopyProgram(progIdx)) {
SkDebugf("Failed to create copy program.\n");
return false;
}
@ -4354,7 +4359,6 @@ bool GrGLGpu::copySurfaceAsBlitFramebuffer(GrSurface* dst,
// Uses draw calls to do a series of downsample operations to successive mips.
// If this returns false, then the calling code falls back to using glGenerateMipmap.
bool GrGLGpu::generateMipmap(GrGLTexture* texture, bool gammaCorrect) {
SkASSERT(!GrPixelConfigIsSint(texture->config()));
// Our iterative downsample requires the ability to limit which level we're sampling:
if (!this->glCaps().doManualMipmapping()) {
return false;

View File

@ -17,7 +17,7 @@
#include "GrGLTexture.h"
#include "GrGLVertexArray.h"
#include "GrGpu.h"
#include "GrTexturePriv.h"
#include "GrTypes.h"
#include "GrWindowRectsState.h"
#include "GrXferProcessor.h"
#include "SkTArray.h"
@ -395,7 +395,7 @@ private:
sk_sp<GrGLContext> fGLContext;
bool createCopyProgram(GrTexture* srcTexture);
bool createCopyProgram(int progIdx);
bool createMipmapProgram(int progIdx);
bool createWireRectProgram();
bool createPLSSetupProgram();
@ -589,13 +589,13 @@ private:
int fHWNumRasterSamples;
///@}
/** IDs for copy surface program. (4 sampler types) */
/** IDs for copy surface program. */
struct {
GrGLuint fProgram;
GrGLint fTextureUniform;
GrGLint fTexCoordXformUniform;
GrGLint fPosXformUniform;
} fCopyPrograms[4];
} fCopyPrograms[3];
sk_sp<GrGLBuffer> fCopyProgramArrayBuffer;
/** IDs for texture mipmap program. (4 filter configurations) */
@ -613,18 +613,16 @@ private:
} fWireRectProgram;
sk_sp<GrGLBuffer> fWireRectArrayBuffer;
static int TextureToCopyProgramIdx(GrTexture* texture) {
switch (texture->texturePriv().samplerType()) {
case kTexture2DSampler_GrSLType:
static int TextureTargetToCopyProgramIdx(GrGLenum target) {
switch (target) {
case GR_GL_TEXTURE_2D:
return 0;
case kTexture2DISampler_GrSLType:
case GR_GL_TEXTURE_EXTERNAL:
return 1;
case kTexture2DRectSampler_GrSLType:
case GR_GL_TEXTURE_RECTANGLE:
return 2;
case kTextureExternalSampler_GrSLType:
return 3;
default:
SkFAIL("Unexpected samper type");
SkFAIL("Unexpected texture target type.");
return 0;
}
}

View File

@ -12,31 +12,20 @@
#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
static inline GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, GrPixelConfig config,
const GrGLGpu* gpu) {
static inline GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, const GrGLGpu* gpu) {
if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) {
SkASSERT(gpu->glCaps().glslCaps()->externalTextureSupport());
SkASSERT(!GrPixelConfigIsSint(config));
return kTextureExternalSampler_GrSLType;
} else if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE) {
SkASSERT(gpu->glCaps().rectangleTextureSupport());
SkASSERT(!GrPixelConfigIsSint(config));
return kTexture2DRectSampler_GrSLType;
} else if (GrPixelConfigIsSint(config)) {
return kTexture2DISampler_GrSLType;
} else {
SkASSERT(idDesc.fInfo.fTarget == GR_GL_TEXTURE_2D);
return kTexture2DSampler_GrSLType;
}
}
static inline GrTextureParams::FilterMode highest_filter_mode(const GrGLTexture::IDDesc& idDesc,
GrPixelConfig config) {
if (GrPixelConfigIsSint(config)) {
// Integer textures in GL can use GL_NEAREST_MIPMAP_NEAREST. This is a mode we don't support
// and don't currently have a use for.
return GrTextureParams::kNone_FilterMode;
}
static inline GrTextureParams::FilterMode highest_filter_mode(const GrGLTexture::IDDesc& idDesc) {
if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE ||
idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) {
return GrTextureParams::kBilerp_FilterMode;
@ -48,8 +37,7 @@ static inline GrTextureParams::FilterMode highest_filter_mode(const GrGLTexture:
GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
const IDDesc& idDesc)
: GrSurface(gpu, desc)
, INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu),
highest_filter_mode(idDesc, desc.fConfig), false) {
, INHERITED(gpu, desc, sampler_type(idDesc, gpu), highest_filter_mode(idDesc), false) {
this->init(desc, idDesc);
this->registerWithCache(budgeted);
}
@ -58,8 +46,7 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc&
const IDDesc& idDesc,
bool wasMipMapDataProvided)
: GrSurface(gpu, desc)
, INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu),
highest_filter_mode(idDesc, desc.fConfig),
, INHERITED(gpu, desc, sampler_type(idDesc, gpu), highest_filter_mode(idDesc),
wasMipMapDataProvided) {
this->init(desc, idDesc);
this->registerWithCache(budgeted);
@ -67,8 +54,7 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc&
GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const IDDesc& idDesc)
: GrSurface(gpu, desc)
, INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu),
highest_filter_mode(idDesc, desc.fConfig), false) {
, INHERITED(gpu, desc, sampler_type(idDesc, gpu), highest_filter_mode(idDesc), false) {
this->init(desc, idDesc);
this->registerWithCacheWrapped();
}
@ -76,8 +62,7 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
bool wasMipMapDataProvided)
: GrSurface(gpu, desc)
, INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu),
highest_filter_mode(idDesc, desc.fConfig),
, INHERITED(gpu, desc, sampler_type(idDesc, gpu), highest_filter_mode(idDesc),
wasMipMapDataProvided) {
this->init(desc, idDesc);
}

View File

@ -124,8 +124,6 @@ static inline const char* GrGLSLTypeString(GrSLType t) {
return "mat4";
case kTexture2DSampler_GrSLType:
return "sampler2D";
case kTexture2DISampler_GrSLType:
return "isampler2D";
case kTextureExternalSampler_GrSLType:
return "samplerExternalOES";
case kTexture2DRectSampler_GrSLType:
@ -142,9 +140,10 @@ static inline const char* GrGLSLTypeString(GrSLType t) {
return "texture2D";
case kSampler_GrSLType:
return "sampler";
default:
SkFAIL("Unknown shader var type.");
return ""; // suppress warning
}
SkFAIL("Unknown shader var type.");
return ""; // suppress warning
}
/** A generic base-class representing a GLSL expression.

View File

@ -129,25 +129,24 @@ void GrGLSLCaps::initSamplerPrecisionTable() {
}
uint8_t* table = fSamplerPrecisions[visibility];
table[kUnknown_GrPixelConfig] = kDefault_GrSLPrecision;
table[kAlpha_8_GrPixelConfig] = lowp;
table[kIndex_8_GrPixelConfig] = lowp;
table[kRGB_565_GrPixelConfig] = lowp;
table[kRGBA_4444_GrPixelConfig] = lowp;
table[kRGBA_8888_GrPixelConfig] = lowp;
table[kBGRA_8888_GrPixelConfig] = lowp;
table[kSRGBA_8888_GrPixelConfig] = lowp;
table[kSBGRA_8888_GrPixelConfig] = lowp;
table[kRGBA_8888_sint_GrPixelConfig] = lowp;
table[kETC1_GrPixelConfig] = lowp;
table[kLATC_GrPixelConfig] = lowp;
table[kR11_EAC_GrPixelConfig] = lowp;
table[kASTC_12x12_GrPixelConfig] = lowp;
table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision;
table[kAlpha_half_GrPixelConfig] = mediump;
table[kRGBA_half_GrPixelConfig] = mediump;
table[kUnknown_GrPixelConfig] = kDefault_GrSLPrecision;
table[kAlpha_8_GrPixelConfig] = lowp;
table[kIndex_8_GrPixelConfig] = lowp;
table[kRGB_565_GrPixelConfig] = lowp;
table[kRGBA_4444_GrPixelConfig] = lowp;
table[kRGBA_8888_GrPixelConfig] = lowp;
table[kBGRA_8888_GrPixelConfig] = lowp;
table[kSRGBA_8888_GrPixelConfig] = lowp;
table[kSBGRA_8888_GrPixelConfig] = lowp;
table[kETC1_GrPixelConfig] = lowp;
table[kLATC_GrPixelConfig] = lowp;
table[kR11_EAC_GrPixelConfig] = lowp;
table[kASTC_12x12_GrPixelConfig] = lowp;
table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision;
table[kAlpha_half_GrPixelConfig] = mediump;
table[kRGBA_half_GrPixelConfig] = mediump;
GR_STATIC_ASSERT(17 == kGrPixelConfigCnt);
GR_STATIC_ASSERT(16 == kGrPixelConfigCnt);
}
}

View File

@ -15,6 +15,8 @@
class GrGLSLCaps : public GrShaderCaps {
public:
/**
* Indicates how GLSL must interact with advanced blend equations. The KHR extension requires
* special layout qualifiers in the fragment shader.

View File

@ -25,11 +25,10 @@ uint32_t grsltype_to_alignment_mask(GrSLType type) {
0x7, // kMat22f_GrSLType
0xF, // kMat33f_GrSLType
0xF, // kMat44f_GrSLType
0x0, // kTexture2DSampler_GrSLType, should never return this
0x0, // kTexture2DISampler_GrSLType, should never return this
0x0, // kTextureExternalSampler_GrSLType, should never return this
0x0, // kTexture2DSamplerRect_GrSLType, should never return this
0x0, // ktextureBufferSampler_GrSLType, should never return this
0x0, // Sampler2D_GrSLType, should never return this
0x0, // SamplerExternal_GrSLType, should never return this
0x0, // Sampler2DRect_GrSLType, should never return this
0x0, // SamplerBuffer_GrSLType, should never return this
0x0, // kBool_GrSLType
0x7, // kInt_GrSLType
0x7, // kUint_GrSLType
@ -45,15 +44,14 @@ uint32_t grsltype_to_alignment_mask(GrSLType type) {
GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(13 == kBool_GrSLType);
GR_STATIC_ASSERT(14 == kInt_GrSLType);
GR_STATIC_ASSERT(15 == kUint_GrSLType);
GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(17 == kSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(12 == kBool_GrSLType);
GR_STATIC_ASSERT(13 == kInt_GrSLType);
GR_STATIC_ASSERT(14 == kUint_GrSLType);
GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(16 == kSampler_GrSLType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAlignmentMask) == kGrSLTypeCount);
return kAlignmentMask[type];
}
@ -73,7 +71,6 @@ static inline uint32_t grsltype_to_vk_size(GrSLType type) {
12 * sizeof(float), // kMat33f_GrSLType
16 * sizeof(float), // kMat44f_GrSLType
0, // kTexture2DSampler_GrSLType
0, // kTexture2DISampler_GrSLType
0, // kTextureExternalSampler_GrSLType
0, // kTexture2DRectSampler_GrSLType
0, // kTextureBufferSampler_GrSLType
@ -94,15 +91,14 @@ static inline uint32_t grsltype_to_vk_size(GrSLType type) {
GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(13 == kBool_GrSLType);
GR_STATIC_ASSERT(14 == kInt_GrSLType);
GR_STATIC_ASSERT(15 == kUint_GrSLType);
GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(17 == kSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(12 == kBool_GrSLType);
GR_STATIC_ASSERT(13 == kInt_GrSLType);
GR_STATIC_ASSERT(14 == kUint_GrSLType);
GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(16 == kSampler_GrSLType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrSLTypeCount);
}

View File

@ -19,62 +19,58 @@ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) {
}
switch (config) {
case kUnknown_GrPixelConfig:
return false;
case kRGBA_8888_GrPixelConfig:
*format = VK_FORMAT_R8G8B8A8_UNORM;
return true;
break;
case kBGRA_8888_GrPixelConfig:
*format = VK_FORMAT_B8G8R8A8_UNORM;
return true;
break;
case kSRGBA_8888_GrPixelConfig:
*format = VK_FORMAT_R8G8B8A8_SRGB;
return true;
break;
case kSBGRA_8888_GrPixelConfig:
*format = VK_FORMAT_B8G8R8A8_SRGB;
return true;
case kRGBA_8888_sint_GrPixelConfig:
*format = VK_FORMAT_R8G8B8A8_SINT;
return true;
break;
case kRGB_565_GrPixelConfig:
*format = VK_FORMAT_R5G6B5_UNORM_PACK16;
return true;
break;
case kRGBA_4444_GrPixelConfig:
// R4G4B4A4 is not required to be supported so we actually
// store the data is if it was B4G4R4A4 and swizzle in shaders
*format = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
return true;
break;
case kIndex_8_GrPixelConfig:
// No current vulkan support for this config
return false;
case kAlpha_8_GrPixelConfig:
*format = VK_FORMAT_R8_UNORM;
return true;
break;
case kETC1_GrPixelConfig:
// converting to ETC2 which is a superset of ETC1
*format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
return true;
break;
case kLATC_GrPixelConfig:
// No current vulkan support for this config
return false;
case kR11_EAC_GrPixelConfig:
*format = VK_FORMAT_EAC_R11_UNORM_BLOCK;
return true;
break;
case kASTC_12x12_GrPixelConfig:
*format = VK_FORMAT_ASTC_12x12_UNORM_BLOCK;
return true;
break;
case kRGBA_float_GrPixelConfig:
*format = VK_FORMAT_R32G32B32A32_SFLOAT;
return true;
break;
case kRGBA_half_GrPixelConfig:
*format = VK_FORMAT_R16G16B16A16_SFLOAT;
return true;
break;
case kAlpha_half_GrPixelConfig:
*format = VK_FORMAT_R16_SFLOAT;
return true;
break;
default:
return false;
}
SkFAIL("Unexpected config");
return false;
return true;
}
bool GrVkFormatToPixelConfig(VkFormat format, GrPixelConfig* config) {
@ -96,9 +92,6 @@ bool GrVkFormatToPixelConfig(VkFormat format, GrPixelConfig* config) {
case VK_FORMAT_B8G8R8A8_SRGB:
*config = kSBGRA_8888_GrPixelConfig;
break;
case VK_FORMAT_R8G8B8A8_SINT:
*config = kRGBA_8888_sint_GrPixelConfig;
break;
case VK_FORMAT_R5G6B5_UNORM_PACK16:
*config = kRGB_565_GrPixelConfig;
break;

View File

@ -20,7 +20,6 @@ static inline int grsltype_to_location_size(GrSLType type) {
3, // kMat33f_GrSLType
4, // kMat44f_GrSLType
0, // kTexture2DSampler_GrSLType
0, // kTexture2DISampler_GrSLType
0, // kTextureExternalSampler_GrSLType
0, // kTexture2DRectSampler_GrSLType
0, // kTextureBufferSampler_GrSLType
@ -41,15 +40,14 @@ static inline int grsltype_to_location_size(GrSLType type) {
GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTexture2DISampler_GrSLType);
GR_STATIC_ASSERT(10 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(12 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(13 == kBool_GrSLType);
GR_STATIC_ASSERT(14 == kInt_GrSLType);
GR_STATIC_ASSERT(15 == kUint_GrSLType);
GR_STATIC_ASSERT(16 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(17 == kSampler_GrSLType);
GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
GR_STATIC_ASSERT(12 == kBool_GrSLType);
GR_STATIC_ASSERT(13 == kInt_GrSLType);
GR_STATIC_ASSERT(14 == kUint_GrSLType);
GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
GR_STATIC_ASSERT(16 == kSampler_GrSLType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrSLTypeCount);
}

View File

@ -111,8 +111,6 @@ Compiler::Compiler()
ADD_TYPE(Sampler2DMS);
ADD_TYPE(Sampler2DMSArray);
ADD_TYPE(ISampler2D);
ADD_TYPE(GSampler1D);
ADD_TYPE(GSampler2D);
ADD_TYPE(GSampler3D);

View File

@ -78,8 +78,6 @@ public:
, fSampler1DArrayShadow_Type(new Type("sampler1DArrayShadow"))
, fSampler2DArrayShadow_Type(new Type("sampler2DArrayShadow"))
, fSamplerCubeArrayShadow_Type(new Type("samplerCubeArrayShadow"))
// Related to below FIXME, gsampler*s don't currently expand to cover integer case.
, fISampler2D_Type(new Type("isampler2D", SpvDim2D, false, false, false, true))
// FIXME figure out what we're supposed to do with the gsampler et al. types)
, fGSampler1D_Type(new Type("$gsampler1D", static_type(*fSampler1D_Type)))
, fGSampler2D_Type(new Type("$gsampler2D", static_type(*fSampler2D_Type)))
@ -195,8 +193,6 @@ public:
const std::unique_ptr<Type> fSampler2DArrayShadow_Type;
const std::unique_ptr<Type> fSamplerCubeArrayShadow_Type;
const std::unique_ptr<Type> fISampler2D_Type;
const std::unique_ptr<Type> fGSampler1D_Type;
const std::unique_ptr<Type> fGSampler2D_Type;
const std::unique_ptr<Type> fGSampler3D_Type;

View File

@ -251,9 +251,6 @@ int textureQueryLevels(samplerCubeArrayShadow sampler);
$gvec4 texture($gsampler1D sampler, float P);
$gvec4 texture($gsampler1D sampler, float P, float bias);
$gvec4 texture($gsampler2D sampler, vec2 P);
// The above currently only expand to handle the float/fixed case. So we also declare this integer
// version of texture().
ivec4 texture(isampler2D sampler, vec2 P);
vec4 texture(samplerExternalOES sampler, vec2 P, float bias);
vec4 texture(samplerExternalOES sampler, vec2 P);
@ -486,7 +483,6 @@ vec4 texture1DProjLod(sampler1D sampler, vec2 coord, float lod);
vec4 texture1DProjLod(sampler1D sampler, vec4 coord, float lod);
*/
vec4 texture2D(sampler2D sampler, vec2 coord);
ivec4 texture2D(isampler2D sampler, vec2 coord);
vec4 texture2D(samplerExternalOES sampler, vec2 coord);
vec4 texture2D(sampler2D sampler, vec2 coord, float bias);
vec4 texture2DProj(sampler2D sampler, vec3 coord);

View File

@ -1,220 +0,0 @@
/*
* 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 "Test.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrRenderTargetContext.h"
#include "GrTexture.h"
#include "effects/GrSimpleTextureEffect.h"
template <typename I>
static SK_WHEN(std::is_integral<I>::value && 4 == sizeof(I), void)
check_pixels(skiatest::Reporter* reporter, int w, int h,
const I exepctedData[], const I actualData[]) {
for (int j = 0; j < h; ++j) {
for (int i = 0; i < w; ++i) {
I expected = exepctedData[j * w + i];
I actual = actualData[j * w + i];
if (expected != actual) {
ERRORF(reporter, "Expected 0x08%x, got 0x%08x at %d, %d.", expected, actual, i, j);
return;
}
}
}
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
if (!context->caps()->isConfigTexturable(kRGBA_8888_sint_GrPixelConfig)) {
return;
}
static const int kS = UINT8_MAX + 1;
GrSurfaceDesc desc;
desc.fConfig = kRGBA_8888_sint_GrPixelConfig;
desc.fWidth = kS;
desc.fHeight = kS;
sk_sp<GrTexture> texture;
std::unique_ptr<int32_t> testData(new int32_t[kS * kS]);
for (int j = 0; j < kS; ++j) {
for (int i = 0; i < kS; ++i) {
int32_t r = i - INT8_MIN;
int32_t g = j - INT8_MIN;
int32_t b = INT8_MAX - r;
int32_t a = INT8_MAX - g;
testData.get()[j * kS + i] = a << 24 | b << 16 | g << 8 | r;
}
}
// Test that attempting to create a integer texture with multiple MIP level fails.
GrMipLevel levels[2];
levels[0].fPixels = testData.get();
levels[0].fRowBytes = kS * sizeof(int32_t);
levels[1].fPixels = testData.get();
levels[1].fRowBytes = (kS / 2) * sizeof(int32_t);
texture.reset(context->textureProvider()->createMipMappedTexture(desc, SkBudgeted::kYes, levels,
2));
REPORTER_ASSERT(reporter, !texture);
// Test that we can create a integer texture.
texture.reset(context->textureProvider()->createTexture(desc, SkBudgeted::kYes,
levels[0].fPixels,
levels[0].fRowBytes));
REPORTER_ASSERT(reporter, texture);
if (!texture) {
return;
}
// Test that reading to a non-integer config fails.
std::unique_ptr<int32_t> readData(new int32_t[kS * kS]);
bool success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_GrPixelConfig, readData.get());
REPORTER_ASSERT(reporter, !success);
std::unique_ptr<uint16_t> halfData(new uint16_t[4 * kS * kS]);
success = texture->readPixels(0, 0, kS, kS, kRGBA_half_GrPixelConfig, halfData.get());
REPORTER_ASSERT(reporter, !success);
// Can read back as ints. (ES only requires being able to read back into 32bit ints which
// we don't support. Right now this test is counting on GR_RGBA_INTEGER/GL_BYTE being the
// implementation-dependent second format).
sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get());
REPORTER_ASSERT(reporter, success);
if (success) {
check_pixels(reporter, kS, kS, testData.get(), readData.get());
}
// readPixels should fail if we attempt to use the unpremul flag with an integer texture.
success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get(), 0,
GrContext::kUnpremul_PixelOpsFlag);
REPORTER_ASSERT(reporter, !success);
// Test that copying from one integer texture to another succeeds.
sk_sp<GrTexture> copy(context->textureProvider()->createTexture(desc, SkBudgeted::kYes));
REPORTER_ASSERT(reporter, copy);
if (!copy) {
return;
}
success = context->copySurface(copy.get(), texture.get());
REPORTER_ASSERT(reporter, success);
if (!success) {
return;
}
sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get());
REPORTER_ASSERT(reporter, success);
if (success) {
check_pixels(reporter, kS, kS, testData.get(), readData.get());
}
// Test that copying to a non-integer texture fails.
GrSurfaceDesc nonIntDesc = desc;
nonIntDesc.fConfig = kRGBA_8888_GrPixelConfig;
copy.reset(context->textureProvider()->createTexture(nonIntDesc, SkBudgeted::kYes));
REPORTER_ASSERT(reporter, copy);
if (!copy) {
return;
}
success = context->copySurface(copy.get(), texture.get());
REPORTER_ASSERT(reporter, !success);
nonIntDesc.fConfig = kRGBA_half_GrPixelConfig;
copy.reset(context->textureProvider()->createTexture(nonIntDesc, SkBudgeted::kYes));
REPORTER_ASSERT(reporter, copy ||
!context->caps()->isConfigTexturable(kRGBA_half_GrPixelConfig));
if (copy) {
success = context->copySurface(copy.get(), texture.get());
REPORTER_ASSERT(reporter, !success);
}
// We overwrite the top left quarter of the texture with the bottom right quarter of the
// original data.
const void* bottomRightQuarter = testData.get() + kS / 2 * kS + kS / 2;
size_t rowBytes = kS * sizeof(int32_t);
// Can't write pixels from a non-int config.
success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_GrPixelConfig, bottomRightQuarter,
rowBytes);
REPORTER_ASSERT(reporter, !success);
// Can't use unpremul flag.
success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_sint_GrPixelConfig,
bottomRightQuarter, rowBytes,
GrContext::kUnpremul_PixelOpsFlag);
REPORTER_ASSERT(reporter, !success);
success = texture->writePixels(0, 0, kS/2, kS/2, kRGBA_8888_sint_GrPixelConfig,
bottomRightQuarter, rowBytes);
REPORTER_ASSERT(reporter, success);
if (!success) {
return;
}
sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
success = texture->readPixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, readData.get());
REPORTER_ASSERT(reporter, success);
if (!success) {
return;
}
std::unique_ptr<int32_t> overwrittenTestData(new int32_t[kS * kS]);
memcpy(overwrittenTestData.get(), testData.get(), sizeof(int32_t) * kS * kS);
char* dst = (char*)overwrittenTestData.get();
char* src = (char*)(testData.get() + kS/2 * kS + kS/2);
for (int i = 0; i < kS/2; ++i) {
memcpy(dst, src, sizeof(int32_t) * kS/2);
dst += rowBytes;
src += rowBytes;
}
check_pixels(reporter, kS, kS, overwrittenTestData.get(), readData.get());
// Test drawing from the integer texture to a fixed point texture. To avoid any premul issues
// we init the int texture with 0s and 1s and make alpha always be 1. We expect that 1s turn
// into 0xffs and zeros stay zero.
std::unique_ptr<uint32_t> expectedData(new uint32_t[kS * kS]);
std::unique_ptr<uint32_t> actualData(new uint32_t[kS * kS]);
for (int i = 0; i < kS*kS; ++i) {
int32_t a = 0x1;
int32_t b = ((i & 0x1) ? 1 : 0);
int32_t g = ((i & 0x1) ? 0 : 1);
int32_t r = ((i & 0x2) ? 1 : 0);
testData.get()[i] = (a << 24) | (b << 16) | (g << 8) | r;
expectedData.get()[i] = ((0xFF * a) << 24) | ((0xFF * b) << 16) |
((0xFF * g) << 8) | (0xFF * r);
}
texture->writePixels(0, 0, kS, kS, kRGBA_8888_sint_GrPixelConfig, testData.get());
sk_sp<GrRenderTargetContext> rtContext = context->makeRenderTargetContext(
SkBackingFit::kExact, kS, kS, kRGBA_8888_GrPixelConfig, nullptr);
for (auto filter : {GrTextureParams::kNone_FilterMode,
GrTextureParams::kBilerp_FilterMode,
GrTextureParams::kMipMap_FilterMode}) {
SkMatrix m;
m.setIDiv(kS, kS);
sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), nullptr, m,
filter));
REPORTER_ASSERT(reporter, fp);
if (!fp) {
return;
}
rtContext->clear(nullptr, 0xDDAABBCC, true);
GrPaint paint;
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
paint.addColorFragmentProcessor(fp);
rtContext->drawPaint(GrNoClip(), paint, SkMatrix::I());
SkImageInfo readInfo = SkImageInfo::Make(kS, kS, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
rtContext->readPixels(readInfo, actualData.get(), 0, 0, 0);
check_pixels(reporter, kS, kS, expectedData.get(), actualData.get());
}
// No rendering to integer textures.
GrSurfaceDesc intRTDesc = desc;
intRTDesc.fFlags = kRenderTarget_GrSurfaceFlag;
texture.reset(context->textureProvider()->createTexture(intRTDesc, SkBudgeted::kYes));
REPORTER_ASSERT(reporter, !texture);
}
#endif