171c4477bee8297189e12a666bbb178f461ad2859sergeyv/*
271c4477bee8297189e12a666bbb178f461ad2859sergeyv * Copyright (C) 2016 The Android Open Source Project
371c4477bee8297189e12a666bbb178f461ad2859sergeyv *
471c4477bee8297189e12a666bbb178f461ad2859sergeyv * Licensed under the Apache License, Version 2.0 (the "License");
571c4477bee8297189e12a666bbb178f461ad2859sergeyv * you may not use this file except in compliance with the License.
671c4477bee8297189e12a666bbb178f461ad2859sergeyv * You may obtain a copy of the License at
771c4477bee8297189e12a666bbb178f461ad2859sergeyv *
871c4477bee8297189e12a666bbb178f461ad2859sergeyv *      http://www.apache.org/licenses/LICENSE-2.0
971c4477bee8297189e12a666bbb178f461ad2859sergeyv *
1071c4477bee8297189e12a666bbb178f461ad2859sergeyv * Unless required by applicable law or agreed to in writing, software
1171c4477bee8297189e12a666bbb178f461ad2859sergeyv * distributed under the License is distributed on an "AS IS" BASIS,
1271c4477bee8297189e12a666bbb178f461ad2859sergeyv * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1371c4477bee8297189e12a666bbb178f461ad2859sergeyv * See the License for the specific language governing permissions and
1471c4477bee8297189e12a666bbb178f461ad2859sergeyv * limitations under the License.
1571c4477bee8297189e12a666bbb178f461ad2859sergeyv */
1671c4477bee8297189e12a666bbb178f461ad2859sergeyv
1771c4477bee8297189e12a666bbb178f461ad2859sergeyv#include <gtest/gtest.h>
1871c4477bee8297189e12a666bbb178f461ad2859sergeyv
1971c4477bee8297189e12a666bbb178f461ad2859sergeyv#include "hwui/Bitmap.h"
2071c4477bee8297189e12a666bbb178f461ad2859sergeyv
2171c4477bee8297189e12a666bbb178f461ad2859sergeyv#include <SkBitmap.h>
2271c4477bee8297189e12a666bbb178f461ad2859sergeyv#include <SkColorTable.h>
2371c4477bee8297189e12a666bbb178f461ad2859sergeyv#include <SkImageInfo.h>
2471c4477bee8297189e12a666bbb178f461ad2859sergeyv
2571c4477bee8297189e12a666bbb178f461ad2859sergeyv#include <tests/common/TestUtils.h>
2671c4477bee8297189e12a666bbb178f461ad2859sergeyv
2771c4477bee8297189e12a666bbb178f461ad2859sergeyvusing namespace android;
2871c4477bee8297189e12a666bbb178f461ad2859sergeyvusing namespace android::uirenderer;
2971c4477bee8297189e12a666bbb178f461ad2859sergeyv
3071c4477bee8297189e12a666bbb178f461ad2859sergeyvTEST(Bitmap, colorTableRefCounting) {
3171c4477bee8297189e12a666bbb178f461ad2859sergeyv    const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) };
3271c4477bee8297189e12a666bbb178f461ad2859sergeyv    SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c));
3371c4477bee8297189e12a666bbb178f461ad2859sergeyv
3471c4477bee8297189e12a666bbb178f461ad2859sergeyv    SkBitmap* bm = new SkBitmap();
3571c4477bee8297189e12a666bbb178f461ad2859sergeyv    bm->allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType),
3671c4477bee8297189e12a666bbb178f461ad2859sergeyv            nullptr, ctable);
3771c4477bee8297189e12a666bbb178f461ad2859sergeyv    sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(bm, ctable);
3871c4477bee8297189e12a666bbb178f461ad2859sergeyv    EXPECT_FALSE(ctable->unique());
3971c4477bee8297189e12a666bbb178f461ad2859sergeyv    delete bm;
4071c4477bee8297189e12a666bbb178f461ad2859sergeyv    bitmap.reset();
4171c4477bee8297189e12a666bbb178f461ad2859sergeyv    EXPECT_TRUE(ctable->unique());
4271c4477bee8297189e12a666bbb178f461ad2859sergeyv    ctable->unref();
4371c4477bee8297189e12a666bbb178f461ad2859sergeyv}
4471c4477bee8297189e12a666bbb178f461ad2859sergeyv
45