Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: tests/FloatingPointTextureTest.cpp

Issue 762923003: Add support for half float alpha textures. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix config setup Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "SkGpuDevice.h" 21 #include "SkGpuDevice.h"
22 #include "SkHalf.h"
21 23
22 static const int DEV_W = 100, DEV_H = 100; 24 static const int DEV_W = 100, DEV_H = 100;
23 static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * sizeof(float); 25 static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4;
24 static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^ 24 26 static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^ 24
25 27
26 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); 28 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
27 29
28 DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) { 30 DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) {
29 float controlPixelData[FP_CONTROL_ARRAY_SIZE]; 31 float controlPixelData[FP_CONTROL_ARRAY_SIZE];
30 float readBuffer[FP_CONTROL_ARRAY_SIZE]; 32 float readBuffer[FP_CONTROL_ARRAY_SIZE];
31 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) { 33 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) {
32 controlPixelData[i] = FLT_MIN; 34 controlPixelData[i] = FLT_MIN;
33 controlPixelData[i + 1] = FLT_MAX; 35 controlPixelData[i + 1] = FLT_MAX;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // write square 72 // write square
71 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe lData, 0); 73 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe lData, 0);
72 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer, 0); 74 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer, 0);
73 for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) { 75 for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) {
74 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]); 76 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]);
75 } 77 }
76 } 78 }
77 } 79 }
78 } 80 }
79 81
82 static const int HALF_CONTROL_ARRAY_SIZE = DEV_W * DEV_H;
83
84 DEF_GPUTEST(HalfFloatTextureTest, reporter, factory) {
85 SkHalf controlPixelData[HALF_CONTROL_ARRAY_SIZE];
86 SkHalf readBuffer[HALF_CONTROL_ARRAY_SIZE];
87 for (int i = 0; i < HALF_CONTROL_ARRAY_SIZE; i += 4) {
88 controlPixelData[i] = SK_HalfMin;
89 controlPixelData[i + 1] = SK_HalfMax;
90 controlPixelData[i + 2] = SK_HalfEpsilon;
91 controlPixelData[i + 3] = 0x6800; // 2^11
92 }
93
94 for (int origin = 0; origin < 2; ++origin) {
95 int glCtxTypeCnt = 1;
96 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
97 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
98 GrSurfaceDesc desc;
99 desc.fFlags = kRenderTarget_GrSurfaceFlag;
100 desc.fWidth = DEV_W;
101 desc.fHeight = DEV_H;
102 desc.fConfig = kAlpha_half_GrPixelConfig;
103 desc.fOrigin = 0 == origin ?
104 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
105
106 GrContext* context = NULL;
107 GrContextFactory::GLContextType type =
108 static_cast<GrContextFactory::GLContextType>(glCtxType);
109 if (!GrContextFactory::IsRenderingGLContext(type)) {
110 continue;
111 }
112 context = factory->get(type);
113 if (NULL == context){
114 continue;
115 }
116
117 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(des c,
118 NUL L,
119 0)) ;
120
121 // 16-bit floating point textures are NOT supported everywhere
122 if (NULL == fpTexture) {
123 continue;
124 }
125
126 // write square
127 fpTexture->writePixels(0, 0, DEV_W, DEV_H, desc.fConfig, controlPixe lData, 0);
128 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer, 0);
129 for (int j = 0; j < HALF_CONTROL_ARRAY_SIZE; ++j) {
130 SkASSERT(readBuffer[j] == controlPixelData[j]);
131 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]);
132 }
133 }
134 }
135 }
136
80 #endif 137 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698