Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 /* | |
| 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 | |
| 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 | |
| 13 */ | |
| 14 #if SK_SUPPORT_GPU | |
| 15 #include <float.h> | |
| 16 #include "Test.h" | |
| 17 #include "GrContext.h" | |
| 18 #include "GrTexture.h" | |
| 19 #include "GrContextFactory.h" | |
| 20 #include "SkGpuDevice.h" | |
| 21 | |
| 22 static const int DEV_W = 100, DEV_H = 100; | |
| 23 static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * sizeof(float); | |
| 24 static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^ 24 | |
| 25 | |
| 26 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); | |
| 27 | |
| 28 enum DevType { | |
| 29 kGpu_BottomLeft_DevType, | |
| 30 kGpu_TopLeft_DevType, | |
| 31 }; | |
| 32 | |
| 33 struct CanvasConfig { | |
| 34 DevType fDevType; | |
| 35 bool fTightRowBytes; | |
| 36 }; | |
| 37 | |
| 38 static const CanvasConfig gCanvasConfigs[] = { | |
| 39 {kGpu_BottomLeft_DevType, true}, // row bytes has no meaning on gpu devices | |
| 40 {kGpu_TopLeft_DevType, true}, // row bytes has no meaning on gpu devices | |
| 41 }; | |
| 42 | |
| 43 DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) { | |
| 44 float controlPixelData[FP_CONTROL_ARRAY_SIZE]; | |
| 45 float readBuffer[FP_CONTROL_ARRAY_SIZE]; | |
| 46 for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) { | |
| 47 controlPixelData[i] = FLT_MIN; | |
| 48 controlPixelData[i + 1] = FLT_MAX; | |
| 49 controlPixelData[i + 2] = FLT_EPSILON; | |
| 50 controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint; | |
| 51 } | |
| 52 | |
| 53 for (size_t i = 0; i < SK_ARRAY_COUNT(gCanvasConfigs); ++i) { | |
| 54 int glCtxTypeCnt = 1; | |
| 55 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; | |
| 56 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { | |
| 57 GrTextureDesc desc; | |
| 58 desc.fFlags = kRenderTarget_GrTextureFlagBit; | |
| 59 desc.fWidth = DEV_W; | |
| 60 desc.fHeight = DEV_H; | |
| 61 desc.fConfig = kRGBA_float_GrPixelConfig; | |
| 62 desc.fOrigin = kGpu_TopLeft_DevType == gCanvasConfigs[i].fDevType ? | |
|
bsalomon
2014/07/09 14:06:42
I think this is the only place where gCanvasConfig
| |
| 63 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; | |
| 64 | |
| 65 GrContext* context = NULL; | |
| 66 GrContextFactory::GLContextType type = | |
| 67 static_cast<GrContextFactory::GLContextType>(glCtxType); | |
| 68 if (!GrContextFactory::IsRenderingGLContext(type)) { | |
| 69 continue; | |
| 70 } | |
| 71 context = factory->get(type); | |
| 72 if (NULL == context){ | |
| 73 continue; | |
| 74 } | |
| 75 | |
| 76 SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(des c, | |
| 77 NUL L, | |
| 78 0)) ; | |
| 79 | |
| 80 // Floating point textures are NOT supported everywhere | |
| 81 if (NULL == fpTexture) { | |
| 82 continue; | |
| 83 } | |
| 84 | |
| 85 // write square | |
| 86 context->writeTexturePixels(fpTexture, 0, 0, DEV_W, DEV_H, desc.fCon fig, | |
| 87 controlPixelData, 0); | |
| 88 context->readTexturePixels(fpTexture, 0, 0, DEV_W, DEV_H, desc.fConf ig, readBuffer, 0); | |
| 89 for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) { | |
| 90 REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]); | |
| 91 } | |
| 92 } | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 #endif | |
| OLD | NEW |