piotaixr | d2a3522 | 2014-08-19 14:29:02 -0700 | [diff] [blame] | 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 | #include "SkTypes.h" |
| 9 | #if SK_SUPPORT_GPU |
| 10 | #include "GrContextFactory.h" |
| 11 | #endif |
| 12 | #include "SkImage.h" |
| 13 | #include "SkSurface.h" |
| 14 | |
| 15 | #include "Test.h" |
| 16 | |
reed | b888136 | 2014-08-20 07:24:01 -0700 | [diff] [blame] | 17 | static void check_isopaque(skiatest::Reporter* reporter, SkSurface* surface, bool expectedOpaque) { |
| 18 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 19 | REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque); |
| 20 | } |
| 21 | |
piotaixr | d2a3522 | 2014-08-19 14:29:02 -0700 | [diff] [blame] | 22 | DEF_TEST(ImageIsOpaqueTest, reporter) { |
| 23 | SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5); |
| 24 | SkAutoTUnref<SkSurface> surfaceTransparent(SkSurface::NewRaster(infoTransparent)); |
reed | b888136 | 2014-08-20 07:24:01 -0700 | [diff] [blame] | 25 | check_isopaque(reporter, surfaceTransparent, false); |
piotaixr | d2a3522 | 2014-08-19 14:29:02 -0700 | [diff] [blame] | 26 | |
| 27 | SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); |
| 28 | SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRaster(infoOpaque)); |
reed | b888136 | 2014-08-20 07:24:01 -0700 | [diff] [blame] | 29 | check_isopaque(reporter, surfaceOpaque, true); |
piotaixr | d2a3522 | 2014-08-19 14:29:02 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | #if SK_SUPPORT_GPU |
| 33 | |
| 34 | DEF_GPUTEST(ImageIsOpaqueTest_GPU, reporter, factory) { |
| 35 | for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 36 | GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i; |
| 37 | |
| 38 | if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | GrContext* context = factory->get(glCtxType); |
| 43 | |
| 44 | if (NULL == context) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5); |
| 49 | SkAutoTUnref<SkSurface> surfaceTransparent(SkSurface::NewRenderTarget(context, infoTransparent)); |
reed | b888136 | 2014-08-20 07:24:01 -0700 | [diff] [blame] | 50 | check_isopaque(reporter, surfaceTransparent, false); |
piotaixr | d2a3522 | 2014-08-19 14:29:02 -0700 | [diff] [blame] | 51 | |
| 52 | SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); |
| 53 | SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRenderTarget(context, infoOpaque)); |
reed | b888136 | 2014-08-20 07:24:01 -0700 | [diff] [blame] | 54 | #if 0 |
| 55 | // this is failing right now : TODO fix me |
| 56 | check_isopaque(reporter, surfaceOpaque, true); |
| 57 | #endif |
piotaixr | d2a3522 | 2014-08-19 14:29:02 -0700 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | #endif |