| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 /* | 8 /* |
| 9 * This is a straightforward test of floating point textures, which are | 9 * This is a straightforward test of floating point textures, which are |
| 10 * supported on some platforms. As of right now, this test only supports | 10 * supported on some platforms. As of right now, this test only supports |
| 11 * 32 bit floating point textures, and indeed floating point test values | 11 * 32 bit floating point textures, and indeed floating point test values |
| 12 * have been selected to require 32 bits of precision and full IEEE conformance | 12 * have been selected to require 32 bits of precision and full IEEE conformance |
| 13 */ | 13 */ |
| 14 #if SK_SUPPORT_GPU | 14 #if SK_SUPPORT_GPU |
| 15 #include <float.h> | 15 #include <float.h> |
| 16 #include "Test.h" | 16 #include "Test.h" |
| 17 #include "GrContext.h" | 17 #include "GrContext.h" |
| 18 #include "GrTexture.h" | 18 #include "GrTexture.h" |
| 19 #include "GrContextFactory.h" | 19 #include "GrContextFactory.h" |
| 20 | 20 |
| 21 #include "SkGpuDevice.h" | 21 #include "SkGpuDevice.h" |
| 22 #include "SkHalf.h" | 22 #include "SkHalf.h" |
| 23 | 23 |
| 24 static const int DEV_W = 100, DEV_H = 100; | 24 static const int DEV_W = 100, DEV_H = 100; |
| 25 static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4; | 25 static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4/*RGBA*/; |
| 26 static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^
24 | 26 static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^
24 |
| 27 | 27 |
| 28 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); | 28 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); |
| 29 | 29 |
| 30 DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) { | 30 DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) { |
| 31 SkTDArray<float> controlPixelData, readBuffer; | 31 SkTDArray<float> controlPixelData, readBuffer; |
| 32 controlPixelData.setCount(FP_CONTROL_ARRAY_SIZE); | 32 controlPixelData.setCount(FP_CONTROL_ARRAY_SIZE); |
| 33 readBuffer.setCount(FP_CONTROL_ARRAY_SIZE); | 33 readBuffer.setCount(FP_CONTROL_ARRAY_SIZE); |
| 34 | 34 |
| 35 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) { | 35 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) { |
| 36 controlPixelData[i] = FLT_MIN; | 36 controlPixelData[i + 0] = FLT_MIN; |
| 37 controlPixelData[i + 1] = FLT_MAX; | 37 controlPixelData[i + 1] = FLT_MAX; |
| 38 controlPixelData[i + 2] = FLT_EPSILON; | 38 controlPixelData[i + 2] = FLT_EPSILON; |
| 39 controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint; | 39 controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint; |
| 40 } | 40 } |
| 41 | 41 |
| 42 for (int origin = 0; origin < 2; ++origin) { | 42 for (int origin = 0; origin < 2; ++origin) { |
| 43 int glCtxTypeCnt = 1; | 43 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt;
++glCtxType) { |
| 44 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; | |
| 45 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { | |
| 46 GrSurfaceDesc desc; | 44 GrSurfaceDesc desc; |
| 47 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 45 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 48 desc.fWidth = DEV_W; | 46 desc.fWidth = DEV_W; |
| 49 desc.fHeight = DEV_H; | 47 desc.fHeight = DEV_H; |
| 50 desc.fConfig = kRGBA_float_GrPixelConfig; | 48 desc.fConfig = kRGBA_float_GrPixelConfig; |
| 51 desc.fOrigin = 0 == origin ? | 49 desc.fOrigin = 0 == origin ? |
| 52 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; | 50 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; |
| 53 | 51 |
| 54 GrContext* context = NULL; | |
| 55 GrContextFactory::GLContextType type = | 52 GrContextFactory::GLContextType type = |
| 56 static_cast<GrContextFactory::GLContextType>(glCtxType); | 53 static_cast<GrContextFactory::GLContextType>(glCtxType); |
| 57 if (!GrContextFactory::IsRenderingGLContext(type)) { | 54 if (!GrContextFactory::IsRenderingGLContext(type)) { |
| 58 continue; | 55 continue; |
| 59 } | 56 } |
| 60 context = factory->get(type); | 57 GrContext* context = factory->get(type); |
| 61 if (NULL == context){ | 58 if (NULL == context){ |
| 62 continue; | 59 continue; |
| 63 } | 60 } |
| 64 | 61 |
| 65 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(des
c, | 62 SkAutoTUnref<GrTexture> fpTexture( |
| 66 NUL
L, | 63 context->createUncachedTexture(desc, controlPixelData.begin(
), 0)); |
| 67 0))
; | |
| 68 | |
| 69 // Floating point textures are NOT supported everywhere | 64 // Floating point textures are NOT supported everywhere |
| 70 if (NULL == fpTexture) { | 65 if (NULL == fpTexture) { |
| 71 continue; | 66 continue; |
| 72 } | 67 } |
| 73 | |
| 74 // write square | |
| 75 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe
lData.begin(), 0); | |
| 76 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.b
egin(), 0); | 68 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.b
egin(), 0); |
| 77 for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) { | 69 REPORTER_ASSERT(reporter, |
| 78 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]); | 70 0 == memcmp(readBuffer.begin(), controlPixelData.begin(), re
adBuffer.bytes())); |
| 79 } | |
| 80 } | 71 } |
| 81 } | 72 } |
| 82 } | 73 } |
| 83 | 74 |
| 84 static const int HALF_CONTROL_ARRAY_SIZE = DEV_W * DEV_H; | 75 static const int HALF_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 1 /*alpha-only*/; |
| 85 | 76 |
| 86 DEF_GPUTEST(HalfFloatTextureTest, reporter, factory) { | 77 DEF_GPUTEST(HalfFloatTextureTest, reporter, factory) { |
| 87 SkTDArray<SkHalf> controlPixelData, readBuffer; | 78 SkTDArray<SkHalf> controlPixelData, readBuffer; |
| 88 controlPixelData.setCount(HALF_CONTROL_ARRAY_SIZE); | 79 controlPixelData.setCount(HALF_CONTROL_ARRAY_SIZE); |
| 89 readBuffer.setCount(HALF_CONTROL_ARRAY_SIZE); | 80 readBuffer.setCount(HALF_CONTROL_ARRAY_SIZE); |
| 90 | 81 |
| 91 for (int i = 0; i < HALF_CONTROL_ARRAY_SIZE; i += 4) { | 82 for (int i = 0; i < HALF_CONTROL_ARRAY_SIZE; i += 4) { |
| 92 controlPixelData[i] = SK_HalfMin; | 83 controlPixelData[i + 0] = SK_HalfMin; |
| 93 controlPixelData[i + 1] = SK_HalfMax; | 84 controlPixelData[i + 1] = SK_HalfMax; |
| 94 controlPixelData[i + 2] = SK_HalfEpsilon; | 85 controlPixelData[i + 2] = SK_HalfEpsilon; |
| 95 controlPixelData[i + 3] = 0x6800; // 2^11 | 86 controlPixelData[i + 3] = 0x6800; // 2^11 |
| 96 } | 87 } |
| 97 | 88 |
| 98 for (int origin = 0; origin < 2; ++origin) { | 89 for (int origin = 0; origin < 2; ++origin) { |
| 99 int glCtxTypeCnt = 1; | 90 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt;
++glCtxType) { |
| 100 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; | |
| 101 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { | |
| 102 GrSurfaceDesc desc; | 91 GrSurfaceDesc desc; |
| 103 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 92 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 104 desc.fWidth = DEV_W; | 93 desc.fWidth = DEV_W; |
| 105 desc.fHeight = DEV_H; | 94 desc.fHeight = DEV_H; |
| 106 desc.fConfig = kAlpha_half_GrPixelConfig; | 95 desc.fConfig = kAlpha_half_GrPixelConfig; |
| 107 desc.fOrigin = 0 == origin ? | 96 desc.fOrigin = 0 == origin ? |
| 108 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; | 97 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; |
| 109 | 98 |
| 110 GrContext* context = NULL; | |
| 111 GrContextFactory::GLContextType type = | 99 GrContextFactory::GLContextType type = |
| 112 static_cast<GrContextFactory::GLContextType>(glCtxType); | 100 static_cast<GrContextFactory::GLContextType>(glCtxType); |
| 113 if (!GrContextFactory::IsRenderingGLContext(type)) { | 101 if (!GrContextFactory::IsRenderingGLContext(type)) { |
| 114 continue; | 102 continue; |
| 115 } | 103 } |
| 116 context = factory->get(type); | 104 GrContext* context = factory->get(type); |
| 117 if (NULL == context){ | 105 if (NULL == context){ |
| 118 continue; | 106 continue; |
| 119 } | 107 } |
| 120 | 108 |
| 121 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(des
c, | 109 SkAutoTUnref<GrTexture> fpTexture( |
| 122 NUL
L, | 110 context->createUncachedTexture(desc, controlPixelData.begin(
), 0)); |
| 123 0))
; | |
| 124 | |
| 125 // 16-bit floating point textures are NOT supported everywhere | 111 // 16-bit floating point textures are NOT supported everywhere |
| 126 if (NULL == fpTexture) { | 112 if (NULL == fpTexture) { |
| 127 continue; | 113 continue; |
| 128 } | 114 } |
| 129 | |
| 130 // write square | |
| 131 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe
lData.begin(), 0); | |
| 132 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.b
egin(), 0); | 115 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.b
egin(), 0); |
| 133 for (int j = 0; j < HALF_CONTROL_ARRAY_SIZE; ++j) { | 116 REPORTER_ASSERT(reporter, |
| 134 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]); | 117 0 == memcmp(readBuffer.begin(), controlPixelData.begin(), re
adBuffer.bytes())); |
| 135 } | |
| 136 } | 118 } |
| 137 } | 119 } |
| 138 } | 120 } |
| 139 | 121 |
| 140 #endif | 122 #endif |
| OLD | NEW |