blob: 3fe5b3db0c725808ef8858433ac83d390d071f95 [file] [log] [blame]
piotaixrd2a35222014-08-19 14:29:02 -07001/*
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
reedb8881362014-08-20 07:24:01 -070017static 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
piotaixrd2a35222014-08-19 14:29:02 -070022DEF_TEST(ImageIsOpaqueTest, reporter) {
23 SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
24 SkAutoTUnref<SkSurface> surfaceTransparent(SkSurface::NewRaster(infoTransparent));
reedb8881362014-08-20 07:24:01 -070025 check_isopaque(reporter, surfaceTransparent, false);
piotaixrd2a35222014-08-19 14:29:02 -070026
27 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
28 SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRaster(infoOpaque));
reedb8881362014-08-20 07:24:01 -070029 check_isopaque(reporter, surfaceOpaque, true);
piotaixrd2a35222014-08-19 14:29:02 -070030}
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));
reedb8881362014-08-20 07:24:01 -070050 check_isopaque(reporter, surfaceTransparent, false);
piotaixrd2a35222014-08-19 14:29:02 -070051
52 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
53 SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRenderTarget(context, infoOpaque));
reedb8881362014-08-20 07:24:01 -070054#if 0
55 // this is failing right now : TODO fix me
56 check_isopaque(reporter, surfaceOpaque, true);
57#endif
piotaixrd2a35222014-08-19 14:29:02 -070058 }
59}
60
61#endif