Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 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 #include "SkImage.h" | |
|
Justin Novosad
2014/07/10 19:24:36
Alphabetical order please.
Rémi Piotaix
2014/07/10 20:16:04
Done.
| |
| 9 #include "SkSurface.h" | |
| 10 #include "SkCanvas.h" | |
| 11 #include "SkShader.h" | |
| 12 #include "GrContextFactory.h" | |
|
Justin Novosad
2014/07/10 19:24:36
The include of GrContextFactory should be guarded
Rémi Piotaix
2014/07/10 20:16:04
Done.
| |
| 13 | |
| 14 #include "Test.h" | |
| 15 | |
| 16 void testBitmapEquality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& b m2, int width, int height) { | |
| 17 for (int x = 0; x < width; x++) { | |
| 18 for (int y = 0; y < height; y++) { | |
| 19 REPORTER_ASSERT(reporter, 5 >= x && 5 >= y); | |
|
Justin Novosad
2014/07/10 19:24:36
Where does the 5 come from? I don't think this is
Rémi Piotaix
2014/07/10 20:16:04
Done.
| |
| 20 REPORTER_ASSERT(reporter, bm1.getColor(x, y) == bm2.getColor(x, y)); | |
|
Justin Novosad
2014/07/10 19:24:36
This is OK, but it would be more efficient to do a
Rémi Piotaix
2014/07/10 20:16:04
Done.
| |
| 21 } | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 void runShaderTest(skiatest::Reporter* reporter, SkSurface* source, SkSurface* d estination, SkImageInfo& info) { | |
| 26 SkCanvas* rasterCanvas = source->getCanvas(); | |
| 27 rasterCanvas->drawColor(0xFFDEDEDE, SkXfermode::kSrc_Mode); | |
| 28 | |
| 29 SkAutoTUnref<SkImage> rasterImage(source->newImageSnapshot()); | |
| 30 SkAutoTUnref<SkShader> rasterShader(rasterImage->newShader( | |
| 31 SkShader::kRepeat_TileMode, | |
| 32 SkShader::kRepeat_TileMode)); | |
| 33 | |
| 34 SkPaint paint; | |
| 35 paint.setShader(rasterShader); | |
| 36 SkCanvas* canvasDest = destination->getCanvas(); | |
| 37 canvasDest->drawPaint(paint); | |
|
Justin Novosad
2014/07/10 19:24:36
To make the test more robust, consider clearing th
Rémi Piotaix
2014/07/10 20:16:04
Done.
| |
| 38 | |
| 39 SkIRect rect = SkIRect::MakeXYWH(0, 0, 5, 5); | |
| 40 | |
| 41 SkBitmap bmOrig; | |
| 42 rasterCanvas->readPixels(rect, &bmOrig); | |
| 43 | |
| 44 SkBitmap bm; | |
| 45 canvasDest->readPixels(rect, &bm); | |
| 46 | |
| 47 testBitmapEquality(reporter, bmOrig, bm, info.fWidth, info.fHeight); | |
| 48 } | |
| 49 | |
| 50 DEF_TEST(ImageNewShader, reporter) { | |
| 51 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); | |
| 52 | |
| 53 SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRaster(info)); | |
| 54 SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRaster(info)); | |
| 55 | |
| 56 runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); | |
| 57 } | |
| 58 | |
| 59 #if SK_SUPPORT_GPU | |
| 60 | |
| 61 void gpuToGpu(skiatest::Reporter* reporter, GrContext* context) { | |
| 62 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); | |
| 63 | |
| 64 SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRenderTarget(context, info) ); | |
| 65 SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRenderTarget(context, info) ); | |
| 66 | |
| 67 runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); | |
| 68 } | |
| 69 | |
| 70 void gpuToRaster(skiatest::Reporter* reporter, GrContext* context) { | |
| 71 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); | |
| 72 | |
| 73 SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRenderTarget(context, info) ); | |
| 74 SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRaster(info)); | |
| 75 | |
| 76 runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); | |
| 77 } | |
| 78 | |
| 79 void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) { | |
| 80 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); | |
| 81 | |
| 82 SkAutoTUnref<SkSurface> srcSurface(SkSurface::NewRaster(info)); | |
| 83 SkAutoTUnref<SkSurface> dstSurface(SkSurface::NewRenderTarget(context, info) ); | |
| 84 | |
| 85 runShaderTest(reporter, srcSurface.get(), dstSurface.get(), info); | |
| 86 } | |
| 87 | |
| 88 DEF_GPUTEST(ImageNewSHader_GPU, reporter, factory) { | |
|
Justin Novosad
2014/07/10 19:24:36
"H" -> "h"
Rémi Piotaix
2014/07/10 20:16:04
Done.
| |
| 89 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); | |
| 90 | |
| 91 // GPU -> GPU | |
| 92 gpuToGpu(reporter, context); | |
| 93 | |
| 94 // GPU -> RASTER | |
| 95 gpuToRaster(reporter, context); | |
| 96 | |
| 97 | |
| 98 // RASTER -> GPU | |
| 99 rasterToGpu(reporter, context); | |
| 100 } | |
| 101 | |
| 102 #endif | |
| OLD | NEW |