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 #if SK_SUPPORT_GPU | |
| 9 #include "GrContextFactory.h" | |
| 10 #endif | |
| 11 #include "SkCanvas.h" | |
| 12 #include "SkImage.h" | |
| 13 #include "SkShader.h" | |
| 14 #include "SkSurface.h" | |
| 15 | |
| 16 #include "Test.h" | |
| 17 | |
| 18 void testBitmapEquality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& b m2) { | |
| 19 REPORTER_ASSERT(reporter, bm1.getSize() == bm2.getSize()); | |
| 20 REPORTER_ASSERT(reporter, 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1. getSize())); | |
|
Justin Novosad
2014/07/11 15:13:55
I don't understand why this does not crash. You ha
Rémi Piotaix
2014/07/11 15:33:51
Done.
| |
| 21 } | |
| 22 | |
| 23 void runShaderTest(skiatest::Reporter* reporter, SkSurface* source, SkSurface* d estination, SkImageInfo& info) { | |
| 24 SkCanvas* rasterCanvas = source->getCanvas(); | |
| 25 rasterCanvas->drawColor(0xFFDEDEDE, SkXfermode::kSrc_Mode); | |
| 26 | |
| 27 SkAutoTUnref<SkImage> rasterImage(source->newImageSnapshot()); | |
| 28 SkAutoTUnref<SkShader> rasterShader(rasterImage->newShader( | |
| 29 SkShader::kRepeat_TileMode, | |
| 30 SkShader::kRepeat_TileMode)); | |
| 31 | |
| 32 SkPaint paint; | |
| 33 paint.setShader(rasterShader); | |
| 34 SkCanvas* canvasDest = destination->getCanvas(); | |
| 35 canvasDest->clear(SK_ColorTRANSPARENT); | |
| 36 canvasDest->drawPaint(paint); | |
| 37 | |
| 38 SkIRect rect = SkIRect::MakeXYWH(0, 0, 5, 5); | |
| 39 | |
| 40 SkBitmap bmOrig; | |
| 41 rasterCanvas->readPixels(rect, &bmOrig); | |
| 42 | |
| 43 SkBitmap bm; | |
| 44 canvasDest->readPixels(rect, &bm); | |
| 45 | |
| 46 testBitmapEquality(reporter, bmOrig, bm); | |
| 47 } | |
| 48 | |
| 49 DEF_TEST(ImageNewShader, reporter) { | |
| 50 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); | |
| 51 | |
| 52 SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRaster(info)); | |
| 53 SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRaster(info)); | |
| 54 | |
| 55 runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); | |
| 56 } | |
| 57 | |
| 58 #if SK_SUPPORT_GPU | |
| 59 | |
| 60 void gpuToGpu(skiatest::Reporter* reporter, GrContext* context) { | |
| 61 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); | |
| 62 | |
| 63 SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRenderTarget(context, info) ); | |
| 64 SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRenderTarget(context, info) ); | |
| 65 | |
| 66 runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); | |
| 67 } | |
| 68 | |
| 69 void gpuToRaster(skiatest::Reporter* reporter, GrContext* context) { | |
| 70 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); | |
| 71 | |
| 72 SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRenderTarget(context, info) ); | |
| 73 SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRaster(info)); | |
| 74 | |
| 75 runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); | |
| 76 } | |
| 77 | |
| 78 void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) { | |
| 79 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); | |
| 80 | |
| 81 SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRaster(info)); | |
| 82 SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRenderTarget(context, info) ); | |
| 83 | |
| 84 runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); | |
| 85 } | |
| 86 | |
| 87 DEF_GPUTEST(ImageNewShader_GPU, reporter, factory) { | |
| 88 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); | |
| 89 | |
| 90 // GPU -> GPU | |
| 91 gpuToGpu(reporter, context); | |
| 92 | |
| 93 // GPU -> RASTER | |
| 94 gpuToRaster(reporter, context); | |
| 95 | |
| 96 | |
| 97 // RASTER -> GPU | |
| 98 rasterToGpu(reporter, context); | |
| 99 } | |
| 100 | |
| 101 #endif | |
| OLD | NEW |