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