Flutter Engine
The Flutter Engine
ImageBitmapTest.cpp
Go to the documentation of this file.
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
11#include "include/core/SkRect.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.
19DEF_TEST(ImageBitmapIdentity, r) {
20 SkBitmap bm, a, b;
21 bm.allocN32Pixels(32, 64);
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}
DEF_TEST(ImageBitmapIdentity, r)
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void setImmutable()
Definition: SkBitmap.cpp:400
bool extractSubset(SkBitmap *dst, const SkIRect &subset) const
Definition: SkBitmap.cpp:453
uint32_t getGenerationID() const
Definition: SkBitmap.cpp:361
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
static bool b
struct MyStruct a[10]
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104