blob: 5cab04d26c2a7fb135f11b3e0752061e657bb5c9 [file] [log] [blame]
Chris Craik07d8d592016-02-03 18:43:04 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "tests/common/TestUtils.h"
18
19#include <gtest/gtest.h>
Chris Craik20136f32016-04-29 17:38:31 -070020#include <SkColorMatrixFilter.h>
Romain Guy253f2c22016-09-28 17:34:42 -070021#include <SkColorSpace.h>
Matt Sarett62feb3a2016-09-20 10:34:11 -040022#include <SkImagePriv.h>
23#include <SkShader.h>
Chris Craik07d8d592016-02-03 18:43:04 -080024
25using namespace android;
26using namespace android::uirenderer;
27
28/**
29 * 1x1 bitmaps must not be optimized into solid color shaders, since HWUI can't
30 * compose/render color shaders
31 */
32TEST(SkiaBehavior, CreateBitmapShader1x1) {
33 SkBitmap origBitmap = TestUtils::createSkBitmap(1, 1);
Matt Sarett62feb3a2016-09-20 10:34:11 -040034 sk_sp<SkShader> s = SkMakeBitmapShader(
Chris Craik07d8d592016-02-03 18:43:04 -080035 origBitmap,
36 SkShader::kClamp_TileMode,
Matt Sarett62feb3a2016-09-20 10:34:11 -040037 SkShader::kRepeat_TileMode,
38 nullptr,
39 kNever_SkCopyPixelsMode,
40 nullptr);
Chris Craik07d8d592016-02-03 18:43:04 -080041
42 SkBitmap bitmap;
43 SkShader::TileMode xy[2];
44 ASSERT_TRUE(s->isABitmap(&bitmap, nullptr, xy))
45 << "1x1 bitmap shader must query as bitmap shader";
46 EXPECT_EQ(SkShader::kClamp_TileMode, xy[0]);
47 EXPECT_EQ(SkShader::kRepeat_TileMode, xy[1]);
48 EXPECT_EQ(origBitmap.pixelRef(), bitmap.pixelRef());
49}
Chris Craikbee60922016-03-25 10:27:03 -070050
51TEST(SkiaBehavior, genIds) {
52 SkBitmap bitmap = TestUtils::createSkBitmap(100, 100);
53 uint32_t genId = bitmap.getGenerationID();
54 bitmap.notifyPixelsChanged();
55 EXPECT_NE(genId, bitmap.getGenerationID());
56}
Chris Craik20136f32016-04-29 17:38:31 -070057
58TEST(SkiaBehavior, lightingColorFilter_simplify) {
Chris Craik36ce80d2016-05-12 17:50:34 -070059 {
60 SkAutoTUnref<SkColorFilter> filter(
61 SkColorMatrixFilter::CreateLightingFilter(0x11223344, 0));
Chris Craik20136f32016-04-29 17:38:31 -070062
Chris Craik36ce80d2016-05-12 17:50:34 -070063 SkColor observedColor;
64 SkXfermode::Mode observedMode;
65 ASSERT_TRUE(filter->asColorMode(&observedColor, &observedMode));
66 EXPECT_EQ(0xFF223344, observedColor);
67 EXPECT_EQ(SkXfermode::Mode::kModulate_Mode, observedMode);
68 }
Chris Craik20136f32016-04-29 17:38:31 -070069
Chris Craik36ce80d2016-05-12 17:50:34 -070070 {
71 SkAutoTUnref<SkColorFilter> failFilter(
72 SkColorMatrixFilter::CreateLightingFilter(0x11223344, 0x1));
73 EXPECT_FALSE(failFilter->asColorMode(nullptr, nullptr));
74 }
Chris Craik20136f32016-04-29 17:38:31 -070075}
John Reck5d31a292016-09-15 10:13:10 -070076
77TEST(SkiaBehavior, porterDuffCreateIsCached) {
78 SkPaint paint;
79 paint.setXfermodeMode(SkXfermode::kOverlay_Mode);
80 auto expected = paint.getXfermode();
81 paint.setXfermodeMode(SkXfermode::kClear_Mode);
82 ASSERT_NE(expected, paint.getXfermode());
83 paint.setXfermodeMode(SkXfermode::kOverlay_Mode);
84 ASSERT_EQ(expected, paint.getXfermode());
85}
Romain Guy253f2c22016-09-28 17:34:42 -070086
87TEST(SkiaBehavior, srgbColorSpaceIsSingleton) {
88 sk_sp<SkColorSpace> sRGB1 = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
89 sk_sp<SkColorSpace> sRGB2 = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
90 ASSERT_EQ(sRGB1.get(), sRGB2.get());
91}