BitmapTests.cpp revision 71c4477bee8297189e12a666bbb178f461ad2859
1/* 2 * Copyright (C) 2016 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 <gtest/gtest.h> 18 19#include "hwui/Bitmap.h" 20 21#include <SkBitmap.h> 22#include <SkColorTable.h> 23#include <SkImageInfo.h> 24 25#include <tests/common/TestUtils.h> 26 27using namespace android; 28using namespace android::uirenderer; 29 30TEST(Bitmap, colorTableRefCounting) { 31 const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) }; 32 SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c)); 33 34 SkBitmap* bm = new SkBitmap(); 35 bm->allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType), 36 nullptr, ctable); 37 sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(bm, ctable); 38 EXPECT_FALSE(ctable->unique()); 39 delete bm; 40 bitmap.reset(); 41 EXPECT_TRUE(ctable->unique()); 42 ctable->unref(); 43} 44 45