OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 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 using packed pixel configs (4444, 565). |
| 10 * This test will make sure that these RGBA_4444 and RGB_565 are always supporte
d |
| 11 * as valid texturing configs. |
| 12 */ |
| 13 |
| 14 #include "Test.h" |
| 15 |
| 16 #if SK_SUPPORT_GPU |
| 17 #include "GrContext.h" |
| 18 #include "GrTexture.h" |
| 19 |
| 20 static const int DEV_W = 100, DEV_H = 100; |
| 21 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); |
| 22 |
| 23 template <typename T> |
| 24 void runTest(skiatest::Reporter* reporter, GrContext* context, |
| 25 T val1, T val2, int arraySize, GrPixelConfig config) { |
| 26 SkTDArray<T> controlPixelData, readBuffer; |
| 27 controlPixelData.setCount(arraySize); |
| 28 readBuffer.setCount(arraySize); |
| 29 |
| 30 for (int i = 0; i < arraySize; i += 2) { |
| 31 controlPixelData[i] = val1; |
| 32 controlPixelData[i + 1] = val2; |
| 33 } |
| 34 |
| 35 for (int origin = 0; origin < 2; ++origin) { |
| 36 GrSurfaceDesc desc; |
| 37 desc.fFlags = kNone_GrSurfaceFlags; |
| 38 desc.fWidth = DEV_W; |
| 39 desc.fHeight = DEV_H; |
| 40 desc.fConfig = config; |
| 41 desc.fOrigin = 0 == origin ? |
| 42 kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; |
| 43 SkAutoTUnref<GrTexture> fpTexture(context->textureProvider()->createText
ure( |
| 44 desc, SkBudgeted::kNo, controlPixelData.begin(), 0)); |
| 45 SkASSERT(fpTexture); |
| 46 fpTexture->readPixels(0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer.begin
(), 0); |
| 47 REPORTER_ASSERT(reporter, |
| 48 0 == memcmp(readBuffer.begin(), controlPixelData.begin()
, |
| 49 readBuffer.bytes())); |
| 50 } |
| 51 } |
| 52 |
| 53 static const int CONTROL_ARRAY_SIZE = DEV_W * DEV_H; |
| 54 |
| 55 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RGBA4444TextureTest, reporter, ctxInfo) { |
| 56 runTest<uint16_t>(reporter, ctxInfo.grContext(), 0xFF00, 0xFA62, |
| 57 CONTROL_ARRAY_SIZE, kRGBA_4444_GrPixelConfig); |
| 58 } |
| 59 |
| 60 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RGB565TextureTest, reporter, ctxInfo) { |
| 61 runTest<uint16_t>(reporter, ctxInfo.grContext(), 0xFF00, 0xFA62, |
| 62 CONTROL_ARRAY_SIZE, kRGB_565_GrPixelConfig); |
| 63 } |
| 64 |
| 65 #endif |
OLD | NEW |