blob: ed689bd6f1748d66e718ea8db8a74a4b9d2ba052 [file] [log] [blame]
sergeyv71c44772016-11-29 20:27:25 -08001/*
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) };
Mike Reedd20f2c22017-04-05 17:36:00 -040032 sk_sp<SkColorTable> ctable = SkColorTable::Make(c, SK_ARRAY_COUNT(c));
sergeyv71c44772016-11-29 20:27:25 -080033
34 SkBitmap* bm = new SkBitmap();
35 bm->allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType),
Mike Reedd20f2c22017-04-05 17:36:00 -040036 ctable);
Mike Reed0a8fb522017-04-13 15:31:32 -040037 sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(bm, ctable);
sergeyv71c44772016-11-29 20:27:25 -080038 EXPECT_FALSE(ctable->unique());
39 delete bm;
40 bitmap.reset();
41 EXPECT_TRUE(ctable->unique());
sergeyv71c44772016-11-29 20:27:25 -080042}
43