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