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 | 14 |
15 #include <float.h> | 15 #include <float.h> |
16 #include "Test.h" | 16 #include "Test.h" |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
18 #include "GrContext.h" | 18 #include "GrContext.h" |
19 #include "GrTexture.h" | 19 #include "GrTexture.h" |
20 #include "GrContextFactory.h" | 20 #include "GrContextFactory.h" |
21 | 21 |
22 #include "SkGpuDevice.h" | 22 #include "SkGpuDevice.h" |
23 #include "SkHalf.h" | 23 #include "SkHalf.h" |
24 | 24 |
25 static const int DEV_W = 100, DEV_H = 100; | 25 static const int DEV_W = 100, DEV_H = 100; |
26 static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4/*RGBA*/; | |
27 static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^
24 | |
28 | |
29 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); | 26 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); |
30 | 27 |
31 DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) { | 28 template <typename T> |
32 SkTDArray<float> controlPixelData, readBuffer; | 29 void runFPTest(skiatest::Reporter* reporter, GrContextFactory* factory, |
33 controlPixelData.setCount(FP_CONTROL_ARRAY_SIZE); | 30 T min, T max, T epsilon, T maxInt, int arraySize, GrPixelConfig c
onfig) { |
34 readBuffer.setCount(FP_CONTROL_ARRAY_SIZE); | 31 SkTDArray<T> controlPixelData, readBuffer; |
| 32 controlPixelData.setCount(arraySize); |
| 33 readBuffer.setCount(arraySize); |
35 | 34 |
36 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) { | 35 for (int i = 0; i < arraySize; i += 4) { |
37 controlPixelData[i + 0] = FLT_MIN; | 36 controlPixelData[i + 0] = min; |
38 controlPixelData[i + 1] = FLT_MAX; | 37 controlPixelData[i + 1] = max; |
39 controlPixelData[i + 2] = FLT_EPSILON; | 38 controlPixelData[i + 2] = epsilon; |
40 controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint; | 39 controlPixelData[i + 3] = maxInt; |
41 } | 40 } |
42 | 41 |
43 for (int origin = 0; origin < 2; ++origin) { | 42 for (int origin = 0; origin < 2; ++origin) { |
44 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt;
++glCtxType) { | 43 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt;
++glCtxType) { |
45 GrSurfaceDesc desc; | 44 GrSurfaceDesc desc; |
46 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 45 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
47 desc.fWidth = DEV_W; | 46 desc.fWidth = DEV_W; |
48 desc.fHeight = DEV_H; | 47 desc.fHeight = DEV_H; |
49 desc.fConfig = kRGBA_float_GrPixelConfig; | 48 desc.fConfig = config; |
50 desc.fOrigin = 0 == origin ? | 49 desc.fOrigin = 0 == origin ? |
51 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; | 50 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; |
52 | 51 |
53 GrContextFactory::GLContextType type = | 52 GrContextFactory::GLContextType type = |
54 static_cast<GrContextFactory::GLContextType>(glCtxType); | 53 static_cast<GrContextFactory::GLContextType>(glCtxType); |
55 if (!GrContextFactory::IsRenderingGLContext(type)) { | 54 if (!GrContextFactory::IsRenderingGLContext(type)) { |
56 continue; | 55 continue; |
57 } | 56 } |
58 GrContext* context = factory->get(type); | 57 GrContext* context = factory->get(type); |
59 if (NULL == context){ | 58 if (NULL == context) { |
60 continue; | 59 continue; |
61 } | 60 } |
62 | 61 |
63 SkAutoTUnref<GrTexture> fpTexture(context->textureProvider()->create
Texture( | 62 SkAutoTUnref<GrTexture> fpTexture(context->textureProvider()->create
Texture( |
64 desc, false, controlPixelData.begin(), 0)); | 63 desc, false, controlPixelData.begin(), 0)); |
65 // Floating point textures are NOT supported everywhere | 64 // Floating point textures are NOT supported everywhere |
66 if (NULL == fpTexture) { | 65 if (NULL == fpTexture) { |
67 continue; | 66 continue; |
68 } | 67 } |
69 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); |
70 REPORTER_ASSERT(reporter, | 69 REPORTER_ASSERT(reporter, |
71 0 == memcmp(readBuffer.begin(), controlPixelData.begin(), re
adBuffer.bytes())); | 70 0 == memcmp(readBuffer.begin(), controlPixelData.begin(), readBu
ffer.bytes())); |
72 } | 71 } |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 static const int HALF_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 1 /*alpha-only*/; | 75 static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4/*RGBA*/; |
| 76 static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^
24 |
77 | 77 |
78 DEF_GPUTEST(HalfFloatTextureTest, reporter, factory) { | 78 DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) { |
79 SkTDArray<SkHalf> controlPixelData, readBuffer; | 79 runFPTest<float>(reporter, factory, FLT_MIN, FLT_MAX, FLT_EPSILON, |
80 controlPixelData.setCount(HALF_CONTROL_ARRAY_SIZE); | 80 kMaxIntegerRepresentableInSPFloatingPoint, |
81 readBuffer.setCount(HALF_CONTROL_ARRAY_SIZE); | 81 FP_CONTROL_ARRAY_SIZE, kRGBA_float_GrPixelConfig); |
| 82 } |
82 | 83 |
83 for (int i = 0; i < HALF_CONTROL_ARRAY_SIZE; i += 4) { | 84 static const int HALF_ALPHA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 1 /*alpha-only*
/; |
84 controlPixelData[i + 0] = SK_HalfMin; | 85 static const SkHalf kMaxIntegerRepresentableInHalfFloatingPoint = 0x6800; // 2
^ 11 |
85 controlPixelData[i + 1] = SK_HalfMax; | |
86 controlPixelData[i + 2] = SK_HalfEpsilon; | |
87 controlPixelData[i + 3] = 0x6800; // 2^11 | |
88 } | |
89 | 86 |
90 for (int origin = 0; origin < 2; ++origin) { | 87 DEF_GPUTEST(HalfFloatAlphaTextureTest, reporter, factory) { |
91 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt;
++glCtxType) { | 88 runFPTest<SkHalf>(reporter, factory, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon, |
92 GrSurfaceDesc desc; | 89 kMaxIntegerRepresentableInHalfFloatingPoint, |
93 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 90 HALF_ALPHA_CONTROL_ARRAY_SIZE, kAlpha_half_GrPixelConfig); |
94 desc.fWidth = DEV_W; | 91 } |
95 desc.fHeight = DEV_H; | |
96 desc.fConfig = kAlpha_half_GrPixelConfig; | |
97 desc.fOrigin = 0 == origin ? | |
98 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; | |
99 | 92 |
100 GrContextFactory::GLContextType type = | 93 static const int HALF_RGBA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4 /*RGBA*/; |
101 static_cast<GrContextFactory::GLContextType>(glCtxType); | |
102 if (!GrContextFactory::IsRenderingGLContext(type)) { | |
103 continue; | |
104 } | |
105 GrContext* context = factory->get(type); | |
106 if (NULL == context){ | |
107 continue; | |
108 } | |
109 | 94 |
110 SkAutoTUnref<GrTexture> fpTexture(context->textureProvider()->create
Texture( | 95 DEF_GPUTEST(HalfFloatRGBATextureTest, reporter, factory) { |
111 desc, false, controlPixelData.begin(), 0)); | 96 runFPTest<SkHalf>(reporter, factory, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon, |
112 // 16-bit floating point textures are NOT supported everywhere | 97 kMaxIntegerRepresentableInHalfFloatingPoint, |
113 if (NULL == fpTexture) { | 98 HALF_RGBA_CONTROL_ARRAY_SIZE, kRGBA_half_GrPixelConfig); |
114 continue; | |
115 } | |
116 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.b
egin(), 0); | |
117 REPORTER_ASSERT(reporter, | |
118 0 == memcmp(readBuffer.begin(), controlPixelData.begin(), re
adBuffer.bytes())); | |
119 } | |
120 } | |
121 } | 99 } |
122 | 100 |
123 #endif | 101 #endif |
OLD | NEW |