Home | History | Annotate | Download | only in unit
      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 <gtest/gtest.h>
     20 #include <SkShader.h>
     21 #include <SkColorMatrixFilter.h>
     22 
     23 using namespace android;
     24 using namespace android::uirenderer;
     25 
     26 /**
     27  * 1x1 bitmaps must not be optimized into solid color shaders, since HWUI can't
     28  * compose/render color shaders
     29  */
     30 TEST(SkiaBehavior, CreateBitmapShader1x1) {
     31     SkBitmap origBitmap = TestUtils::createSkBitmap(1, 1);
     32     SkAutoTUnref<SkShader> s(SkShader::CreateBitmapShader(
     33             origBitmap,
     34             SkShader::kClamp_TileMode,
     35             SkShader::kRepeat_TileMode));
     36 
     37     SkBitmap bitmap;
     38     SkShader::TileMode xy[2];
     39     ASSERT_TRUE(s->isABitmap(&bitmap, nullptr, xy))
     40         << "1x1 bitmap shader must query as bitmap shader";
     41     EXPECT_EQ(SkShader::kClamp_TileMode, xy[0]);
     42     EXPECT_EQ(SkShader::kRepeat_TileMode, xy[1]);
     43     EXPECT_EQ(origBitmap.pixelRef(), bitmap.pixelRef());
     44 }
     45 
     46 TEST(SkiaBehavior, genIds) {
     47     SkBitmap bitmap = TestUtils::createSkBitmap(100, 100);
     48     uint32_t genId = bitmap.getGenerationID();
     49     bitmap.notifyPixelsChanged();
     50     EXPECT_NE(genId, bitmap.getGenerationID());
     51 }
     52 
     53 TEST(SkiaBehavior, lightingColorFilter_simplify) {
     54     {
     55         SkAutoTUnref<SkColorFilter> filter(
     56                 SkColorMatrixFilter::CreateLightingFilter(0x11223344, 0));
     57 
     58         SkColor observedColor;
     59         SkXfermode::Mode observedMode;
     60         ASSERT_TRUE(filter->asColorMode(&observedColor, &observedMode));
     61         EXPECT_EQ(0xFF223344, observedColor);
     62         EXPECT_EQ(SkXfermode::Mode::kModulate_Mode, observedMode);
     63     }
     64 
     65     {
     66         SkAutoTUnref<SkColorFilter> failFilter(
     67                 SkColorMatrixFilter::CreateLightingFilter(0x11223344, 0x1));
     68         EXPECT_FALSE(failFilter->asColorMode(nullptr, nullptr));
     69     }
     70 }
     71