| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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; |
| 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 float controlPixelData[FP_CONTROL_ARRAY_SIZE]; | 31 SkTDArray<float> controlPixelData, readBuffer; |
| 32 float readBuffer[FP_CONTROL_ARRAY_SIZE]; | 32 controlPixelData.setCount(FP_CONTROL_ARRAY_SIZE); |
| 33 readBuffer.setCount(FP_CONTROL_ARRAY_SIZE); |
| 34 |
| 33 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) { | 35 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) { |
| 34 controlPixelData[i] = FLT_MIN; | 36 controlPixelData[i] = FLT_MIN; |
| 35 controlPixelData[i + 1] = FLT_MAX; | 37 controlPixelData[i + 1] = FLT_MAX; |
| 36 controlPixelData[i + 2] = FLT_EPSILON; | 38 controlPixelData[i + 2] = FLT_EPSILON; |
| 37 controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint; | 39 controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint; |
| 38 } | 40 } |
| 39 | 41 |
| 40 for (int origin = 0; origin < 2; ++origin) { | 42 for (int origin = 0; origin < 2; ++origin) { |
| 41 int glCtxTypeCnt = 1; | 43 int glCtxTypeCnt = 1; |
| 42 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; | 44 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 63 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(des
c, | 65 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(des
c, |
| 64 NUL
L, | 66 NUL
L, |
| 65 0))
; | 67 0))
; |
| 66 | 68 |
| 67 // Floating point textures are NOT supported everywhere | 69 // Floating point textures are NOT supported everywhere |
| 68 if (NULL == fpTexture) { | 70 if (NULL == fpTexture) { |
| 69 continue; | 71 continue; |
| 70 } | 72 } |
| 71 | 73 |
| 72 // write square | 74 // write square |
| 73 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe
lData, 0); | 75 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe
lData.begin(), 0); |
| 74 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer,
0); | 76 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.b
egin(), 0); |
| 75 for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) { | 77 for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) { |
| 76 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]); | 78 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]); |
| 77 } | 79 } |
| 78 } | 80 } |
| 79 } | 81 } |
| 80 } | 82 } |
| 81 | 83 |
| 82 static const int HALF_CONTROL_ARRAY_SIZE = DEV_W * DEV_H; | 84 static const int HALF_CONTROL_ARRAY_SIZE = DEV_W * DEV_H; |
| 83 | 85 |
| 84 DEF_GPUTEST(HalfFloatTextureTest, reporter, factory) { | 86 DEF_GPUTEST(HalfFloatTextureTest, reporter, factory) { |
| 85 SkHalf controlPixelData[HALF_CONTROL_ARRAY_SIZE]; | 87 SkTDArray<SkHalf> controlPixelData, readBuffer; |
| 86 SkHalf readBuffer[HALF_CONTROL_ARRAY_SIZE]; | 88 controlPixelData.setCount(HALF_CONTROL_ARRAY_SIZE); |
| 89 readBuffer.setCount(HALF_CONTROL_ARRAY_SIZE); |
| 90 |
| 87 for (int i = 0; i < HALF_CONTROL_ARRAY_SIZE; i += 4) { | 91 for (int i = 0; i < HALF_CONTROL_ARRAY_SIZE; i += 4) { |
| 88 controlPixelData[i] = SK_HalfMin; | 92 controlPixelData[i] = SK_HalfMin; |
| 89 controlPixelData[i + 1] = SK_HalfMax; | 93 controlPixelData[i + 1] = SK_HalfMax; |
| 90 controlPixelData[i + 2] = SK_HalfEpsilon; | 94 controlPixelData[i + 2] = SK_HalfEpsilon; |
| 91 controlPixelData[i + 3] = 0x6800; // 2^11 | 95 controlPixelData[i + 3] = 0x6800; // 2^11 |
| 92 } | 96 } |
| 93 | 97 |
| 94 for (int origin = 0; origin < 2; ++origin) { | 98 for (int origin = 0; origin < 2; ++origin) { |
| 95 int glCtxTypeCnt = 1; | 99 int glCtxTypeCnt = 1; |
| 96 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; | 100 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 117 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(des
c, | 121 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(des
c, |
| 118 NUL
L, | 122 NUL
L, |
| 119 0))
; | 123 0))
; |
| 120 | 124 |
| 121 // 16-bit floating point textures are NOT supported everywhere | 125 // 16-bit floating point textures are NOT supported everywhere |
| 122 if (NULL == fpTexture) { | 126 if (NULL == fpTexture) { |
| 123 continue; | 127 continue; |
| 124 } | 128 } |
| 125 | 129 |
| 126 // write square | 130 // write square |
| 127 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe
lData, 0); | 131 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe
lData.begin(), 0); |
| 128 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer,
0); | 132 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.b
egin(), 0); |
| 129 for (int j = 0; j < HALF_CONTROL_ARRAY_SIZE; ++j) { | 133 for (int j = 0; j < HALF_CONTROL_ARRAY_SIZE; ++j) { |
| 130 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]); | 134 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]); |
| 131 } | 135 } |
| 132 } | 136 } |
| 133 } | 137 } |
| 134 } | 138 } |
| 135 | 139 |
| 136 #endif | 140 #endif |
| OLD | NEW |