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