1 /*
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 <SkBitmap.h>
20 #include <SkBlendMode.h>
21 #include <SkColor.h>
22 #include <SkColorMatrixFilter.h>
23 #include <SkColorSpace.h>
24 #include <SkImageInfo.h>
25 #include <SkPaint.h>
26 #include <SkPath.h>
27 #include <SkPathOps.h>
28 #include <SkShader.h>
29 #include <gtest/gtest.h>
30
31 using namespace android;
32 using namespace android::uirenderer;
33
createSkBitmap(int width,int height)34 SkBitmap createSkBitmap(int width, int height) {
35 SkBitmap bitmap;
36 SkImageInfo info = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
37 bitmap.setInfo(info);
38 bitmap.allocPixels(info);
39 return bitmap;
40 }
41
TEST(SkiaBehavior,genIds)42 TEST(SkiaBehavior, genIds) {
43 SkBitmap bitmap = createSkBitmap(100, 100);
44 uint32_t genId = bitmap.getGenerationID();
45 bitmap.notifyPixelsChanged();
46 EXPECT_NE(genId, bitmap.getGenerationID());
47 }
48
TEST(SkiaBehavior,lightingColorFilter_simplify)49 TEST(SkiaBehavior, lightingColorFilter_simplify) {
50 {
51 sk_sp<SkColorFilter> filter(SkColorMatrixFilter::MakeLightingFilter(0x11223344, 0));
52
53 SkColor observedColor;
54 SkBlendMode observedMode;
55 ASSERT_TRUE(filter->asAColorMode(&observedColor, &observedMode));
56 EXPECT_EQ(0xFF223344, observedColor);
57 EXPECT_EQ(SkBlendMode::kModulate, observedMode);
58 }
59
60 {
61 sk_sp<SkColorFilter> failFilter(SkColorMatrixFilter::MakeLightingFilter(0x11223344, 0x1));
62 EXPECT_FALSE(failFilter->asAColorMode(nullptr, nullptr));
63 }
64 }
65
TEST(SkiaBehavior,porterDuffCreateIsCached)66 TEST(SkiaBehavior, porterDuffCreateIsCached) {
67 SkPaint paint;
68 paint.setBlendMode(SkBlendMode::kOverlay);
69 auto expected = paint.asBlendMode();
70 paint.setBlendMode(SkBlendMode::kClear);
71 ASSERT_NE(expected, paint.asBlendMode());
72 paint.setBlendMode(SkBlendMode::kOverlay);
73 ASSERT_EQ(expected, paint.asBlendMode());
74 }
75
TEST(SkiaBehavior,pathIntersection)76 TEST(SkiaBehavior, pathIntersection) {
77 SkPath p0, p1, result;
78 p0.addRect(SkRect::MakeXYWH(-5.0f, 0.0f, 1080.0f, 242.0f));
79 p1.addRect(SkRect::MakeXYWH(0.0f, 0.0f, 1080.0f, 242.0f));
80 Op(p0, p1, kIntersect_SkPathOp, &result);
81 SkRect resultRect;
82 ASSERT_TRUE(result.isRect(&resultRect));
83 ASSERT_EQ(SkRect::MakeXYWH(0.0f, 0.0f, 1075.0f, 242.0f), resultRect);
84 }
85
TEST(SkiaBehavior,srgbColorSpaceIsSingleton)86 TEST(SkiaBehavior, srgbColorSpaceIsSingleton) {
87 sk_sp<SkColorSpace> sRGB1 = SkColorSpace::MakeSRGB();
88 sk_sp<SkColorSpace> sRGB2 = SkColorSpace::MakeSRGB();
89 ASSERT_EQ(sRGB1.get(), sRGB2.get());
90 }
91
92