blob: 8e2f7e09d4066730c07586b60ca1f0f4d0ece093 [file] [log] [blame]
Derek Sollenbergerd3e9eec2020-04-06 11:43:59 -04001/*
2 * Copyright 2020 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 "android/graphics/bitmap.h"
20#include "apex/TypeCast.h"
21#include "hwui/Bitmap.h"
22#include "tests/common/TestUtils.h"
23
24using namespace android;
25using namespace android::uirenderer;
26
27TEST(ABitmap, notifyPixelsChanged) {
28 // generate a bitmap and its public API handle
29 sk_sp<Bitmap> bitmap(TestUtils::createBitmap(1, 1));
30 ABitmap* abmp = android::TypeCast::toABitmap(bitmap.get());
31
32 // verify that notification changes the genID
33 uint32_t genID = bitmap->getGenerationID();
34 ABitmap_notifyPixelsChanged(abmp);
35 ASSERT_TRUE(bitmap->getGenerationID() != genID);
36
37 // mark the bitmap as immutable
38 ASSERT_FALSE(bitmap->isImmutable());
39 bitmap->setImmutable();
40 ASSERT_TRUE(bitmap->isImmutable());
41
42 // attempt to notify that the pixels have changed
43 genID = bitmap->getGenerationID();
44 ABitmap_notifyPixelsChanged(abmp);
45 ASSERT_TRUE(bitmap->getGenerationID() == genID);
46}