1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2016 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "tests/Test.h"
9cb93a386Sopenharmony_ci
10cb93a386Sopenharmony_ci#include "include/core/SkBitmap.h"
11cb93a386Sopenharmony_ci#include "include/core/SkImage.h"
12cb93a386Sopenharmony_ci
13cb93a386Sopenharmony_ci// https://bug.skia.org/5096
14cb93a386Sopenharmony_ci// Test that when we make an image from a subset of a bitmap, that it
15cb93a386Sopenharmony_ci// has a diff (ID, dimensions) from an image made from the entire
16cb93a386Sopenharmony_ci// bitmap or a different subset of the image.
17cb93a386Sopenharmony_ciDEF_TEST(ImageBitmapIdentity, r) {
18cb93a386Sopenharmony_ci    SkBitmap bm, a, b;
19cb93a386Sopenharmony_ci    bm.allocN32Pixels(32, 64);
20cb93a386Sopenharmony_ci    bm.eraseColor(SK_ColorBLACK);
21cb93a386Sopenharmony_ci    bm.setImmutable();
22cb93a386Sopenharmony_ci    (void)bm.extractSubset(&a, SkIRect::MakeXYWH(0, 0, 32, 32));
23cb93a386Sopenharmony_ci    (void)bm.extractSubset(&b, SkIRect::MakeXYWH(0, 32, 32, 32));
24cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, a.getGenerationID() == b.getGenerationID());
25cb93a386Sopenharmony_ci    auto img = bm.asImage();
26cb93a386Sopenharmony_ci    auto imgA = a.asImage();
27cb93a386Sopenharmony_ci    auto imgB = b.asImage();
28cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, img->uniqueID() == bm.getGenerationID());
29cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, img->uniqueID() != imgA->uniqueID());
30cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, img->uniqueID() != imgB->uniqueID());
31cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, imgA->uniqueID() != imgB->uniqueID());
32cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, imgA->uniqueID() != a.getGenerationID());
33cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, imgB->uniqueID() != b.getGenerationID());
34cb93a386Sopenharmony_ci}
35