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
17static 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
22DEF_TEST(ImageIsOpaqueTest, reporter) {
23    SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
24    SkAutoTUnref<SkSurface> surfaceTransparent(SkSurface::NewRaster(infoTransparent));
25    check_isopaque(reporter, surfaceTransparent, false);
26
27    SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
28    SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRaster(infoOpaque));
29    check_isopaque(reporter, surfaceOpaque, true);
30}
31
32#if SK_SUPPORT_GPU
33
34DEF_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));
50        check_isopaque(reporter, surfaceTransparent, false);
51
52        SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
53        SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRenderTarget(context, infoOpaque));
54#if 0
55        // this is failing right now : TODO fix me
56        check_isopaque(reporter, surfaceOpaque, true);
57#endif
58    }
59}
60
61#endif
62