ImageBitmapTest.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  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. #include "tests/Test.h"
  8. #include "include/core/SkBitmap.h"
  9. #include "include/core/SkImage.h"
  10. // https://bug.skia.org/5096
  11. // Test that when we make an image from a subset of a bitmap, that it
  12. // has a diff (ID, dimensions) from an image made from the entire
  13. // bitmap or a different subset of the image.
  14. DEF_TEST(ImageBitmapIdentity, r) {
  15. SkBitmap bm, a, b;
  16. bm.allocN32Pixels(32, 64);
  17. bm.eraseColor(SK_ColorBLACK);
  18. bm.setImmutable();
  19. (void)bm.extractSubset(&a, SkIRect::MakeXYWH(0, 0, 32, 32));
  20. (void)bm.extractSubset(&b, SkIRect::MakeXYWH(0, 32, 32, 32));
  21. REPORTER_ASSERT(r, a.getGenerationID() == b.getGenerationID());
  22. auto img = SkImage::MakeFromBitmap(bm);
  23. auto imgA = SkImage::MakeFromBitmap(a);
  24. auto imgB = SkImage::MakeFromBitmap(b);
  25. REPORTER_ASSERT(r, img->uniqueID() == bm.getGenerationID());
  26. REPORTER_ASSERT(r, img->uniqueID() != imgA->uniqueID());
  27. REPORTER_ASSERT(r, img->uniqueID() != imgB->uniqueID());
  28. REPORTER_ASSERT(r, imgA->uniqueID() != imgB->uniqueID());
  29. REPORTER_ASSERT(r, imgA->uniqueID() != a.getGenerationID());
  30. REPORTER_ASSERT(r, imgB->uniqueID() != b.getGenerationID());
  31. }