2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-03-05 13:43:15 +00:00
|
|
|
|
2009-05-01 04:00:01 +00:00
|
|
|
#include "SkBitmap.h"
|
2009-05-05 23:13:23 +00:00
|
|
|
#include "SkRect.h"
|
2015-12-10 18:44:13 +00:00
|
|
|
#include "SkTemplates.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2009-05-01 04:00:01 +00:00
|
|
|
|
|
|
|
static const char* boolStr(bool value) {
|
|
|
|
return value ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2014-03-05 13:43:15 +00:00
|
|
|
// these are in the same order as the SkColorType enum
|
2014-02-23 03:59:35 +00:00
|
|
|
static const char* gColorTypeName[] = {
|
|
|
|
"None", "A8", "565", "4444", "RGBA", "BGRA", "Index8"
|
2009-05-01 04:00:01 +00:00
|
|
|
};
|
|
|
|
|
2009-08-22 03:44:57 +00:00
|
|
|
static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src,
|
|
|
|
const SkBitmap& dst) {
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "src %s opaque:%d, dst %s opaque:%d",
|
2014-02-23 03:59:35 +00:00
|
|
|
gColorTypeName[src.colorType()], src.isOpaque(),
|
|
|
|
gColorTypeName[dst.colorType()], dst.isOpaque());
|
2009-08-22 03:44:57 +00:00
|
|
|
}
|
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
static bool canHaveAlpha(SkColorType ct) {
|
|
|
|
return kRGB_565_SkColorType != ct;
|
2009-08-22 03:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// copyTo() should preserve isOpaque when it makes sense
|
2013-10-10 14:44:56 +00:00
|
|
|
static void test_isOpaque(skiatest::Reporter* reporter,
|
|
|
|
const SkBitmap& srcOpaque, const SkBitmap& srcPremul,
|
2014-02-23 03:59:35 +00:00
|
|
|
SkColorType dstColorType) {
|
2009-08-22 03:44:57 +00:00
|
|
|
SkBitmap dst;
|
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
if (canHaveAlpha(srcPremul.colorType()) && canHaveAlpha(dstColorType)) {
|
|
|
|
REPORTER_ASSERT(reporter, srcPremul.copyTo(&dst, dstColorType));
|
|
|
|
REPORTER_ASSERT(reporter, dst.colorType() == dstColorType);
|
2013-10-10 14:44:56 +00:00
|
|
|
if (srcPremul.isOpaque() != dst.isOpaque()) {
|
|
|
|
report_opaqueness(reporter, srcPremul, dst);
|
2009-08-22 03:44:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, srcOpaque.copyTo(&dst, dstColorType));
|
|
|
|
REPORTER_ASSERT(reporter, dst.colorType() == dstColorType);
|
2013-10-10 14:44:56 +00:00
|
|
|
if (srcOpaque.isOpaque() != dst.isOpaque()) {
|
|
|
|
report_opaqueness(reporter, srcOpaque, dst);
|
2009-08-22 03:44:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-10 14:44:56 +00:00
|
|
|
static void init_src(const SkBitmap& bitmap) {
|
2009-05-03 18:23:30 +00:00
|
|
|
SkAutoLockPixels lock(bitmap);
|
2009-05-01 04:00:01 +00:00
|
|
|
if (bitmap.getPixels()) {
|
2013-10-10 14:44:56 +00:00
|
|
|
if (bitmap.getColorTable()) {
|
2011-01-10 14:04:07 +00:00
|
|
|
sk_bzero(bitmap.getPixels(), bitmap.getSize());
|
|
|
|
} else {
|
|
|
|
bitmap.eraseColor(SK_ColorWHITE);
|
|
|
|
}
|
2009-05-01 04:00:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 19:10:27 +00:00
|
|
|
static SkColorTable* init_ctable() {
|
2009-05-01 04:00:01 +00:00
|
|
|
static const SkColor colors[] = {
|
|
|
|
SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE
|
|
|
|
};
|
2014-09-29 19:10:27 +00:00
|
|
|
return new SkColorTable(colors, SK_ARRAY_COUNT(colors));
|
2009-05-01 04:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Pair {
|
2014-02-23 03:59:35 +00:00
|
|
|
SkColorType fColorType;
|
|
|
|
const char* fValid;
|
2009-05-01 04:00:01 +00:00
|
|
|
};
|
|
|
|
|
2010-11-16 20:22:41 +00:00
|
|
|
// Utility functions for copyPixelsTo()/copyPixelsFrom() tests.
|
|
|
|
// getPixel()
|
|
|
|
// setPixel()
|
|
|
|
// getSkConfigName()
|
|
|
|
// struct Coordinates
|
|
|
|
// reportCopyVerification()
|
|
|
|
// writeCoordPixels()
|
|
|
|
|
|
|
|
// Utility function to read the value of a given pixel in bm. All
|
|
|
|
// values converted to uint32_t for simplification of comparisons.
|
2012-06-06 12:03:39 +00:00
|
|
|
static uint32_t getPixel(int x, int y, const SkBitmap& bm) {
|
2010-11-16 20:22:41 +00:00
|
|
|
uint32_t val = 0;
|
|
|
|
uint16_t val16;
|
2013-12-02 13:50:38 +00:00
|
|
|
uint8_t val8;
|
2010-11-16 20:22:41 +00:00
|
|
|
SkAutoLockPixels lock(bm);
|
|
|
|
const void* rawAddr = bm.getAddr(x,y);
|
|
|
|
|
2014-03-05 13:43:15 +00:00
|
|
|
switch (bm.bytesPerPixel()) {
|
|
|
|
case 4:
|
2010-11-16 20:22:41 +00:00
|
|
|
memcpy(&val, rawAddr, sizeof(uint32_t));
|
|
|
|
break;
|
2014-03-05 13:43:15 +00:00
|
|
|
case 2:
|
2010-11-16 20:22:41 +00:00
|
|
|
memcpy(&val16, rawAddr, sizeof(uint16_t));
|
|
|
|
val = val16;
|
|
|
|
break;
|
2014-03-05 13:43:15 +00:00
|
|
|
case 1:
|
2010-11-16 20:22:41 +00:00
|
|
|
memcpy(&val8, rawAddr, sizeof(uint8_t));
|
|
|
|
val = val8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Utility function to set value of any pixel in bm.
|
|
|
|
// bm.getConfig() specifies what format 'val' must be
|
|
|
|
// converted to, but at present uint32_t can handle all formats.
|
2012-06-06 12:03:39 +00:00
|
|
|
static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) {
|
2010-11-16 20:22:41 +00:00
|
|
|
uint16_t val16;
|
2013-12-02 13:50:38 +00:00
|
|
|
uint8_t val8;
|
2010-11-16 20:22:41 +00:00
|
|
|
SkAutoLockPixels lock(bm);
|
|
|
|
void* rawAddr = bm.getAddr(x,y);
|
|
|
|
|
2014-03-05 13:43:15 +00:00
|
|
|
switch (bm.bytesPerPixel()) {
|
|
|
|
case 4:
|
2010-11-16 20:22:41 +00:00
|
|
|
memcpy(rawAddr, &val, sizeof(uint32_t));
|
|
|
|
break;
|
2014-03-05 13:43:15 +00:00
|
|
|
case 2:
|
2010-11-16 20:22:41 +00:00
|
|
|
val16 = val & 0xFFFF;
|
|
|
|
memcpy(rawAddr, &val16, sizeof(uint16_t));
|
|
|
|
break;
|
2014-03-05 13:43:15 +00:00
|
|
|
case 1:
|
2010-11-16 20:22:41 +00:00
|
|
|
val8 = val & 0xFF;
|
|
|
|
memcpy(rawAddr, &val8, sizeof(uint8_t));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Ignore.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper struct to contain pixel locations, while avoiding need for STL.
|
|
|
|
struct Coordinates {
|
|
|
|
|
|
|
|
const int length;
|
|
|
|
SkIPoint* const data;
|
|
|
|
|
|
|
|
explicit Coordinates(int _length): length(_length)
|
|
|
|
, data(new SkIPoint[length]) { }
|
|
|
|
|
|
|
|
~Coordinates(){
|
|
|
|
delete [] data;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkIPoint* operator[](int i) const {
|
|
|
|
// Use with care, no bounds checking.
|
|
|
|
return data + i;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// A function to verify that two bitmaps contain the same pixel values
|
|
|
|
// at all coordinates indicated by coords. Simplifies verification of
|
|
|
|
// copied bitmaps.
|
2012-06-06 12:03:39 +00:00
|
|
|
static void reportCopyVerification(const SkBitmap& bm1, const SkBitmap& bm2,
|
2010-11-16 20:22:41 +00:00
|
|
|
Coordinates& coords,
|
|
|
|
const char* msg,
|
|
|
|
skiatest::Reporter* reporter){
|
|
|
|
// Confirm all pixels in the list match.
|
2012-08-22 15:00:05 +00:00
|
|
|
for (int i = 0; i < coords.length; ++i) {
|
2015-05-22 15:06:21 +00:00
|
|
|
uint32_t p1 = getPixel(coords[i]->fX, coords[i]->fY, bm1);
|
|
|
|
uint32_t p2 = getPixel(coords[i]->fX, coords[i]->fY, bm2);
|
|
|
|
// SkDebugf("[%d] (%d %d) p1=%x p2=%x\n", i, coords[i]->fX, coords[i]->fY, p1, p2);
|
|
|
|
if (p1 != p2) {
|
|
|
|
ERRORF(reporter, "%s [colortype = %s]", msg, gColorTypeName[bm1.colorType()]);
|
|
|
|
break;
|
|
|
|
}
|
2010-11-16 20:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes unique pixel values at locations specified by coords.
|
2012-06-06 12:03:39 +00:00
|
|
|
static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) {
|
2010-11-16 20:22:41 +00:00
|
|
|
for (int i = 0; i < coords.length; ++i)
|
|
|
|
setPixel(coords[i]->fX, coords[i]->fY, i, bm);
|
|
|
|
}
|
|
|
|
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
static const Pair gPairs[] = {
|
2014-02-23 03:59:35 +00:00
|
|
|
{ kUnknown_SkColorType, "000000" },
|
2016-11-28 22:17:38 +00:00
|
|
|
{ kAlpha_8_SkColorType, "010000" },
|
2017-01-23 17:15:09 +00:00
|
|
|
{ kIndex_8_SkColorType, "010111" },
|
2014-02-23 03:59:35 +00:00
|
|
|
{ kRGB_565_SkColorType, "010101" },
|
|
|
|
{ kARGB_4444_SkColorType, "010111" },
|
2014-04-11 17:15:40 +00:00
|
|
|
{ kN32_SkColorType, "010111" },
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
};
|
2010-11-16 20:22:41 +00:00
|
|
|
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
static const int W = 20;
|
|
|
|
static const int H = 33;
|
2009-05-03 18:23:30 +00:00
|
|
|
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul,
|
2014-02-23 03:59:35 +00:00
|
|
|
SkColorType ct) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkColorTable* ctable = nullptr;
|
2014-02-23 03:59:35 +00:00
|
|
|
if (kIndex_8_SkColorType == ct) {
|
2014-09-29 19:10:27 +00:00
|
|
|
ctable = init_ctable();
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
}
|
2014-02-23 03:59:35 +00:00
|
|
|
|
|
|
|
srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr, ctable);
|
2014-02-23 03:59:35 +00:00
|
|
|
srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr, ctable);
|
2014-09-29 19:10:27 +00:00
|
|
|
SkSafeUnref(ctable);
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
init_src(*srcOpaque);
|
|
|
|
init_src(*srcPremul);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(BitmapCopy_extractSubset, reporter) {
|
2009-05-01 04:00:01 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
SkBitmap srcOpaque, srcPremul;
|
2014-02-23 03:59:35 +00:00
|
|
|
setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType);
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
|
|
|
|
SkBitmap bitmap(srcOpaque);
|
|
|
|
SkBitmap subset;
|
|
|
|
SkIRect r;
|
|
|
|
// Extract a subset which has the same width as the original. This
|
|
|
|
// catches a bug where we cloned the genID incorrectly.
|
|
|
|
r.set(0, 1, W, 3);
|
|
|
|
bitmap.setIsVolatile(true);
|
2014-02-23 03:59:35 +00:00
|
|
|
// Relies on old behavior of extractSubset failing if colortype is unknown
|
|
|
|
if (kUnknown_SkColorType != bitmap.colorType() && bitmap.extractSubset(&subset, r)) {
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
REPORTER_ASSERT(reporter, subset.width() == W);
|
|
|
|
REPORTER_ASSERT(reporter, subset.height() == 2);
|
|
|
|
REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
|
|
|
|
REPORTER_ASSERT(reporter, subset.isVolatile() == true);
|
|
|
|
|
|
|
|
// Test copying an extracted subset.
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
|
|
|
|
SkBitmap copy;
|
2014-02-23 03:59:35 +00:00
|
|
|
bool success = subset.copyTo(©, gPairs[j].fColorType);
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
if (!success) {
|
|
|
|
// Skip checking that success matches fValid, which is redundant
|
|
|
|
// with the code below.
|
2017-01-23 17:15:09 +00:00
|
|
|
REPORTER_ASSERT(reporter, kIndex_8_SkColorType == gPairs[i].fColorType ||
|
|
|
|
gPairs[i].fColorType != gPairs[j].fColorType);
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When performing a copy of an extracted subset, the gen id should
|
|
|
|
// change.
|
|
|
|
REPORTER_ASSERT(reporter, copy.getGenerationID() != subset.getGenerationID());
|
2013-10-11 07:01:39 +00:00
|
|
|
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
REPORTER_ASSERT(reporter, copy.width() == W);
|
|
|
|
REPORTER_ASSERT(reporter, copy.height() == 2);
|
2013-10-10 14:44:56 +00:00
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
if (gPairs[i].fColorType == gPairs[j].fColorType) {
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
SkAutoLockPixels alp0(subset);
|
|
|
|
SkAutoLockPixels alp1(copy);
|
|
|
|
// they should both have, or both not-have, a colortable
|
2015-08-27 14:41:13 +00:00
|
|
|
bool hasCT = subset.getColorTable() != nullptr;
|
|
|
|
REPORTER_ASSERT(reporter, (copy.getColorTable() != nullptr) == hasCT);
|
2013-10-10 14:44:56 +00:00
|
|
|
}
|
2009-05-01 04:00:01 +00:00
|
|
|
}
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bitmap = srcPremul;
|
|
|
|
bitmap.setIsVolatile(false);
|
|
|
|
if (bitmap.extractSubset(&subset, r)) {
|
|
|
|
REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
|
|
|
|
REPORTER_ASSERT(reporter, subset.isVolatile() == false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(BitmapCopy, reporter) {
|
|
|
|
static const bool isExtracted[] = {
|
|
|
|
false, true
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
|
|
|
|
SkBitmap srcOpaque, srcPremul;
|
2014-02-23 03:59:35 +00:00
|
|
|
setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType);
|
Reland "Fix genID cloning bugs."
SkBitmap.cpp:
When copyTo calls readPixels, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a
bug where copying an SkBitmap representing the subset of an SkPixelRef
(which implements onReadPixels) would result in the copy sharing the
genID. (Thanks to r6710, this case can only happen using setPixelRef,
so the updated GpuBitmapCopyTest checks for that.)
Move some unnecessary NULL checks to asserts.
When copyTo performs a memcpy, only clone the genID if the resulting
SkPixelRef has the same dimensions as the original. This catches a bug
where copying an extracted SkBitmap with the same width as its original
SkPixelRef would incorrectly have the same genID.
Add a comment and assert in deepCopyTo, when cloning the genID, since
that case correctly clones it.
BitmapCopyTest.cpp:
Pull redundant work out of the inner loop (setting up the source bitmaps
and testing extractSubset). Create a new inner loop for extractSubset, to
test copying the result to each different config.
Extract a subset that has the same width as the original, to catch the
bug mentioned above.
Remove the reporter assert which checks for the resulting rowbytes.
Add checks to ensure that copying the extracted subset changes the genID.
GpuBitmapCopyTest:
Create an SkBitmap that shares an existing SkPixelRef, but only represents
a subset. This is to test the first call to cloneGenID in SkBitmap::copyTo.
In this case, the genID should NOT be copied, since only a portion of the
SkPixelRef was copied.
Also test deepCopy on this subset.
TestIndividualCopy now takes a parameter stating whether the genID should
change in the copy. It also does a read back using the appropriate subset.
It no longer differentiates between copyTo and deepCopyTo, since that
distinction was only necessary for copying from/to configs other than 8888
(which are no longer being tested), where copyTo did a read back in 8888 and
then drew the result to the desired config (resulting in an imperfect copy).
BUG=skia:1742
Committed: http://code.google.com/p/skia/source/detail?r=13021
R=mtklein@google.com
Review URL: https://codereview.chromium.org/112113005
git-svn-id: http://skia.googlecode.com/svn/trunk@13090 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-15 16:56:52 +00:00
|
|
|
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
|
|
|
|
SkBitmap dst;
|
2009-05-01 04:00:01 +00:00
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
bool success = srcPremul.copyTo(&dst, gPairs[j].fColorType);
|
2009-05-01 04:00:01 +00:00
|
|
|
bool expected = gPairs[i].fValid[j] != '0';
|
|
|
|
if (success != expected) {
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "SkBitmap::copyTo from %s to %s. expected %s "
|
2014-02-23 03:59:35 +00:00
|
|
|
"returned %s", gColorTypeName[i], gColorTypeName[j],
|
2014-01-10 14:58:10 +00:00
|
|
|
boolStr(expected), boolStr(success));
|
2009-05-01 04:00:01 +00:00
|
|
|
}
|
2011-01-05 15:50:27 +00:00
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
bool canSucceed = srcPremul.canCopyTo(gPairs[j].fColorType);
|
2009-05-06 17:44:34 +00:00
|
|
|
if (success != canSucceed) {
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "SkBitmap::copyTo from %s to %s. returned %s "
|
2014-02-23 03:59:35 +00:00
|
|
|
"canCopyTo %s", gColorTypeName[i], gColorTypeName[j],
|
2014-01-10 14:58:10 +00:00
|
|
|
boolStr(success), boolStr(canSucceed));
|
2009-05-06 17:44:34 +00:00
|
|
|
}
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2009-05-01 04:00:01 +00:00
|
|
|
if (success) {
|
2013-10-10 14:44:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, srcPremul.width() == dst.width());
|
|
|
|
REPORTER_ASSERT(reporter, srcPremul.height() == dst.height());
|
2014-02-23 03:59:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, dst.colorType() == gPairs[j].fColorType);
|
|
|
|
test_isOpaque(reporter, srcOpaque, srcPremul, dst.colorType());
|
2014-03-05 13:43:15 +00:00
|
|
|
if (srcPremul.colorType() == dst.colorType()) {
|
2013-10-10 14:44:56 +00:00
|
|
|
SkAutoLockPixels srcLock(srcPremul);
|
2009-05-01 04:00:01 +00:00
|
|
|
SkAutoLockPixels dstLock(dst);
|
2013-10-10 14:44:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, srcPremul.readyToDraw());
|
2009-05-01 04:00:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, dst.readyToDraw());
|
2013-10-10 14:44:56 +00:00
|
|
|
const char* srcP = (const char*)srcPremul.getAddr(0, 0);
|
2009-05-01 04:00:01 +00:00
|
|
|
const char* dstP = (const char*)dst.getAddr(0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, srcP != dstP);
|
|
|
|
REPORTER_ASSERT(reporter, !memcmp(srcP, dstP,
|
2013-10-10 14:44:56 +00:00
|
|
|
srcPremul.getSize()));
|
|
|
|
REPORTER_ASSERT(reporter, srcPremul.getGenerationID() == dst.getGenerationID());
|
2012-08-22 15:00:05 +00:00
|
|
|
} else {
|
2013-10-10 14:44:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, srcPremul.getGenerationID() != dst.getGenerationID());
|
2009-05-01 04:00:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// dst should be unchanged from its initial state
|
2014-03-05 13:43:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, dst.colorType() == kUnknown_SkColorType);
|
2009-05-01 04:00:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, dst.width() == 0);
|
|
|
|
REPORTER_ASSERT(reporter, dst.height() == 0);
|
|
|
|
}
|
2010-11-16 20:22:41 +00:00
|
|
|
} // for (size_t j = ...
|
|
|
|
|
|
|
|
// Tests for getSafeSize(), getSafeSize64(), copyPixelsTo(),
|
|
|
|
// copyPixelsFrom().
|
|
|
|
//
|
|
|
|
for (size_t copyCase = 0; copyCase < SK_ARRAY_COUNT(isExtracted);
|
|
|
|
++copyCase) {
|
|
|
|
// Test copying to/from external buffer.
|
|
|
|
// Note: the tests below have hard-coded values ---
|
|
|
|
// Please take care if modifying.
|
|
|
|
|
2013-06-26 14:35:02 +00:00
|
|
|
// Tests for getSafeSize64().
|
|
|
|
// Test with a very large configuration without pixel buffer
|
|
|
|
// attached.
|
|
|
|
SkBitmap tstSafeSize;
|
2014-05-30 13:26:10 +00:00
|
|
|
tstSafeSize.setInfo(SkImageInfo::Make(100000000U, 100000000U,
|
|
|
|
gPairs[i].fColorType, kPremul_SkAlphaType));
|
2013-12-30 14:40:38 +00:00
|
|
|
int64_t safeSize = tstSafeSize.computeSafeSize64();
|
|
|
|
if (safeSize < 0) {
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "getSafeSize64() negative: %s",
|
2014-03-05 13:43:15 +00:00
|
|
|
gColorTypeName[tstSafeSize.colorType()]);
|
2013-06-26 14:35:02 +00:00
|
|
|
}
|
|
|
|
bool sizeFail = false;
|
|
|
|
// Compare against hand-computed values.
|
2014-02-23 03:59:35 +00:00
|
|
|
switch (gPairs[i].fColorType) {
|
|
|
|
case kUnknown_SkColorType:
|
2013-06-26 14:35:02 +00:00
|
|
|
break;
|
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
case kAlpha_8_SkColorType:
|
|
|
|
case kIndex_8_SkColorType:
|
2013-12-30 14:40:38 +00:00
|
|
|
if (safeSize != 0x2386F26FC10000LL) {
|
2013-06-26 14:35:02 +00:00
|
|
|
sizeFail = true;
|
2013-12-20 14:24:21 +00:00
|
|
|
}
|
2013-06-26 14:35:02 +00:00
|
|
|
break;
|
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
case kRGB_565_SkColorType:
|
|
|
|
case kARGB_4444_SkColorType:
|
2013-12-30 14:40:38 +00:00
|
|
|
if (safeSize != 0x470DE4DF820000LL) {
|
2013-06-26 14:35:02 +00:00
|
|
|
sizeFail = true;
|
2013-12-20 14:24:21 +00:00
|
|
|
}
|
2013-06-26 14:35:02 +00:00
|
|
|
break;
|
|
|
|
|
2014-04-11 17:15:40 +00:00
|
|
|
case kN32_SkColorType:
|
2013-12-30 14:40:38 +00:00
|
|
|
if (safeSize != 0x8E1BC9BF040000LL) {
|
2013-06-26 14:35:02 +00:00
|
|
|
sizeFail = true;
|
2013-12-20 14:24:21 +00:00
|
|
|
}
|
2013-06-26 14:35:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sizeFail) {
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "computeSafeSize64() wrong size: %s",
|
2014-03-05 13:43:15 +00:00
|
|
|
gColorTypeName[tstSafeSize.colorType()]);
|
2013-06-26 14:35:02 +00:00
|
|
|
}
|
2010-11-16 20:22:41 +00:00
|
|
|
|
2013-12-02 13:50:38 +00:00
|
|
|
int subW = 2;
|
|
|
|
int subH = 2;
|
2010-11-16 20:22:41 +00:00
|
|
|
|
2013-06-26 14:35:02 +00:00
|
|
|
// Create bitmap to act as source for copies and subsets.
|
|
|
|
SkBitmap src, subset;
|
2015-08-27 14:41:13 +00:00
|
|
|
SkColorTable* ct = nullptr;
|
2014-03-05 13:43:15 +00:00
|
|
|
if (kIndex_8_SkColorType == src.colorType()) {
|
2014-09-29 19:10:27 +00:00
|
|
|
ct = init_ctable();
|
2013-06-26 14:35:02 +00:00
|
|
|
}
|
2010-11-16 20:22:41 +00:00
|
|
|
|
2014-09-02 19:50:45 +00:00
|
|
|
int localSubW;
|
2014-02-23 03:59:35 +00:00
|
|
|
if (isExtracted[copyCase]) { // A larger image to extract from.
|
2014-09-02 19:50:45 +00:00
|
|
|
localSubW = 2 * subW + 1;
|
2014-02-23 03:59:35 +00:00
|
|
|
} else { // Tests expect a 2x2 bitmap, so make smaller.
|
2014-09-02 19:50:45 +00:00
|
|
|
localSubW = subW;
|
|
|
|
}
|
|
|
|
// could fail if we pass kIndex_8 for the colortype
|
|
|
|
if (src.tryAllocPixels(SkImageInfo::Make(localSubW, subH, gPairs[i].fColorType,
|
|
|
|
kPremul_SkAlphaType))) {
|
|
|
|
// failure is fine, as we will notice later on
|
2014-02-23 03:59:35 +00:00
|
|
|
}
|
2013-06-26 14:35:02 +00:00
|
|
|
SkSafeUnref(ct);
|
2010-11-16 20:22:41 +00:00
|
|
|
|
2013-06-26 14:35:02 +00:00
|
|
|
// Either copy src or extract into 'subset', which is used
|
|
|
|
// for subsequent calls to copyPixelsTo/From.
|
|
|
|
bool srcReady = false;
|
2014-02-23 03:59:35 +00:00
|
|
|
// Test relies on older behavior that extractSubset will fail on
|
2014-03-05 13:43:15 +00:00
|
|
|
// kUnknown_SkColorType
|
2014-02-23 03:59:35 +00:00
|
|
|
if (kUnknown_SkColorType != src.colorType() &&
|
|
|
|
isExtracted[copyCase]) {
|
2013-06-26 14:35:02 +00:00
|
|
|
// The extractedSubset() test case allows us to test copy-
|
|
|
|
// ing when src and dst mave possibly different strides.
|
|
|
|
SkIRect r;
|
2013-12-02 13:50:38 +00:00
|
|
|
r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap
|
2013-06-26 14:35:02 +00:00
|
|
|
|
|
|
|
srcReady = src.extractSubset(&subset, r);
|
|
|
|
} else {
|
2014-02-23 03:59:35 +00:00
|
|
|
srcReady = src.copyTo(&subset);
|
2013-06-26 14:35:02 +00:00
|
|
|
}
|
2010-11-16 20:22:41 +00:00
|
|
|
|
2013-06-26 14:35:02 +00:00
|
|
|
// Not all configurations will generate a valid 'subset'.
|
|
|
|
if (srcReady) {
|
|
|
|
|
|
|
|
// Allocate our target buffer 'buf' for all copies.
|
|
|
|
// To simplify verifying correctness of copies attach
|
|
|
|
// buf to a SkBitmap, but copies are done using the
|
|
|
|
// raw buffer pointer.
|
2013-10-16 17:48:11 +00:00
|
|
|
const size_t bufSize = subH *
|
2014-03-05 13:43:15 +00:00
|
|
|
SkColorTypeMinRowBytes(src.colorType(), subW) * 2;
|
2015-12-10 18:44:13 +00:00
|
|
|
SkAutoTMalloc<uint8_t> autoBuf (bufSize);
|
|
|
|
uint8_t* buf = autoBuf.get();
|
2013-06-26 14:35:02 +00:00
|
|
|
|
|
|
|
SkBitmap bufBm; // Attach buf to this bitmap.
|
|
|
|
bool successExpected;
|
|
|
|
|
|
|
|
// Set up values for each pixel being copied.
|
|
|
|
Coordinates coords(subW * subH);
|
2013-10-16 17:48:11 +00:00
|
|
|
for (int x = 0; x < subW; ++x)
|
|
|
|
for (int y = 0; y < subH; ++y)
|
2013-06-26 14:35:02 +00:00
|
|
|
{
|
|
|
|
int index = y * subW + x;
|
|
|
|
SkASSERT(index < coords.length);
|
|
|
|
coords[index]->fX = x;
|
|
|
|
coords[index]->fY = y;
|
|
|
|
}
|
2010-11-16 20:22:41 +00:00
|
|
|
|
2013-06-26 14:35:02 +00:00
|
|
|
writeCoordPixels(subset, coords);
|
|
|
|
|
|
|
|
// Test #1 ////////////////////////////////////////////
|
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::Make(subW, subH,
|
|
|
|
gPairs[i].fColorType,
|
|
|
|
kPremul_SkAlphaType);
|
2013-06-26 14:35:02 +00:00
|
|
|
// Before/after comparisons easier if we attach buf
|
|
|
|
// to an appropriately configured SkBitmap.
|
|
|
|
memset(buf, 0xFF, bufSize);
|
|
|
|
// Config with stride greater than src but that fits in buf.
|
2014-02-23 03:59:35 +00:00
|
|
|
bufBm.installPixels(info, buf, info.minRowBytes() * 2);
|
2013-06-26 14:35:02 +00:00
|
|
|
successExpected = false;
|
|
|
|
// Then attempt to copy with a stride that is too large
|
|
|
|
// to fit in the buffer.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes() * 3)
|
|
|
|
== successExpected);
|
|
|
|
|
|
|
|
if (successExpected)
|
|
|
|
reportCopyVerification(subset, bufBm, coords,
|
|
|
|
"copyPixelsTo(buf, bufSize, 1.5*maxRowBytes)",
|
2010-11-16 20:22:41 +00:00
|
|
|
reporter);
|
|
|
|
|
2013-06-26 14:35:02 +00:00
|
|
|
// Test #2 ////////////////////////////////////////////
|
|
|
|
// This test should always succeed, but in the case
|
|
|
|
// of extracted bitmaps only because we handle the
|
|
|
|
// issue of getSafeSize(). Without getSafeSize()
|
|
|
|
// buffer overrun/read would occur.
|
|
|
|
memset(buf, 0xFF, bufSize);
|
2014-02-23 03:59:35 +00:00
|
|
|
bufBm.installPixels(info, buf, subset.rowBytes());
|
2013-06-26 14:35:02 +00:00
|
|
|
successExpected = subset.getSafeSize() <= bufSize;
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
subset.copyPixelsTo(buf, bufSize) ==
|
|
|
|
successExpected);
|
|
|
|
if (successExpected)
|
|
|
|
reportCopyVerification(subset, bufBm, coords,
|
|
|
|
"copyPixelsTo(buf, bufSize)", reporter);
|
|
|
|
|
|
|
|
// Test #3 ////////////////////////////////////////////
|
|
|
|
// Copy with different stride between src and dst.
|
|
|
|
memset(buf, 0xFF, bufSize);
|
2014-02-23 03:59:35 +00:00
|
|
|
bufBm.installPixels(info, buf, subset.rowBytes()+1);
|
2013-06-26 14:35:02 +00:00
|
|
|
successExpected = true; // Should always work.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
subset.copyPixelsTo(buf, bufSize,
|
|
|
|
subset.rowBytes()+1) == successExpected);
|
|
|
|
if (successExpected)
|
|
|
|
reportCopyVerification(subset, bufBm, coords,
|
|
|
|
"copyPixelsTo(buf, bufSize, rowBytes+1)", reporter);
|
|
|
|
|
|
|
|
// Test #4 ////////////////////////////////////////////
|
|
|
|
// Test copy with stride too small.
|
|
|
|
memset(buf, 0xFF, bufSize);
|
2014-02-23 03:59:35 +00:00
|
|
|
bufBm.installPixels(info, buf, info.minRowBytes());
|
2013-06-26 14:35:02 +00:00
|
|
|
successExpected = false;
|
|
|
|
// Request copy with stride too small.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
subset.copyPixelsTo(buf, bufSize, bufBm.rowBytes()-1)
|
|
|
|
== successExpected);
|
|
|
|
if (successExpected)
|
|
|
|
reportCopyVerification(subset, bufBm, coords,
|
|
|
|
"copyPixelsTo(buf, bufSize, rowBytes()-1)", reporter);
|
|
|
|
|
|
|
|
#if 0 // copyPixelsFrom is gone
|
|
|
|
// Test #5 ////////////////////////////////////////////
|
|
|
|
// Tests the case where the source stride is too small
|
|
|
|
// for the source configuration.
|
|
|
|
memset(buf, 0xFF, bufSize);
|
2014-02-23 03:59:35 +00:00
|
|
|
bufBm.installPixels(info, buf, info.minRowBytes());
|
2013-06-26 14:35:02 +00:00
|
|
|
writeCoordPixels(bufBm, coords);
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
subset.copyPixelsFrom(buf, bufSize, 1) == false);
|
|
|
|
|
|
|
|
// Test #6 ///////////////////////////////////////////
|
|
|
|
// Tests basic copy from an external buffer to the bitmap.
|
|
|
|
// If the bitmap is "extracted", this also tests the case
|
|
|
|
// where the source stride is different from the dest.
|
|
|
|
// stride.
|
|
|
|
// We've made the buffer large enough to always succeed.
|
2014-02-23 03:59:35 +00:00
|
|
|
bufBm.installPixels(info, buf, info.minRowBytes());
|
2013-06-26 14:35:02 +00:00
|
|
|
writeCoordPixels(bufBm, coords);
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
subset.copyPixelsFrom(buf, bufSize, bufBm.rowBytes()) ==
|
|
|
|
true);
|
|
|
|
reportCopyVerification(bufBm, subset, coords,
|
|
|
|
"copyPixelsFrom(buf, bufSize)",
|
|
|
|
reporter);
|
|
|
|
|
|
|
|
// Test #7 ////////////////////////////////////////////
|
|
|
|
// Tests the case where the source buffer is too small
|
|
|
|
// for the transfer.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
subset.copyPixelsFrom(buf, 1, subset.rowBytes()) ==
|
|
|
|
false);
|
2010-11-16 20:22:41 +00:00
|
|
|
|
2011-11-01 16:03:35 +00:00
|
|
|
#endif
|
2010-11-16 20:22:41 +00:00
|
|
|
}
|
|
|
|
} // for (size_t copyCase ...
|
2009-05-01 04:00:01 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-13 11:32:32 +00:00
|
|
|
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkUtils.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct 4x4 pixels where we can look at a color and determine where it should be in the grid.
|
|
|
|
* alpha = 0xFF, blue = 0x80, red = x, green = y
|
|
|
|
*/
|
|
|
|
static void fill_4x4_pixels(SkPMColor colors[16]) {
|
|
|
|
for (int y = 0; y < 4; ++y) {
|
|
|
|
for (int x = 0; x < 4; ++x) {
|
|
|
|
colors[y*4+x] = SkPackARGB32(0xFF, x, y, 0x80);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_4x4_pixel(SkPMColor color, unsigned x, unsigned y) {
|
|
|
|
SkASSERT(x < 4 && y < 4);
|
|
|
|
return 0xFF == SkGetPackedA32(color) &&
|
|
|
|
x == SkGetPackedR32(color) &&
|
|
|
|
y == SkGetPackedG32(color) &&
|
|
|
|
0x80 == SkGetPackedB32(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill with all zeros, which will never match any value from fill_4x4_pixels
|
|
|
|
*/
|
|
|
|
static void clear_4x4_pixels(SkPMColor colors[16]) {
|
|
|
|
sk_memset32(colors, 0, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Much of readPixels is exercised by copyTo testing, since readPixels is the backend for that
|
|
|
|
// method. Here we explicitly test subset copies.
|
|
|
|
//
|
|
|
|
DEF_TEST(BitmapReadPixels, reporter) {
|
|
|
|
const int W = 4;
|
|
|
|
const int H = 4;
|
|
|
|
const size_t rowBytes = W * sizeof(SkPMColor);
|
|
|
|
const SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(W, H);
|
|
|
|
SkPMColor srcPixels[16];
|
|
|
|
fill_4x4_pixels(srcPixels);
|
|
|
|
SkBitmap srcBM;
|
|
|
|
srcBM.installPixels(srcInfo, srcPixels, rowBytes);
|
|
|
|
|
|
|
|
SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(W, H);
|
|
|
|
SkPMColor dstPixels[16];
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
bool fExpectedSuccess;
|
|
|
|
SkIPoint fRequestedSrcLoc;
|
|
|
|
SkISize fRequestedDstSize;
|
|
|
|
// If fExpectedSuccess, check these, otherwise ignore
|
|
|
|
SkIPoint fExpectedDstLoc;
|
|
|
|
SkIRect fExpectedSrcR;
|
|
|
|
} gRec[] = {
|
|
|
|
{ true, { 0, 0 }, { 4, 4 }, { 0, 0 }, { 0, 0, 4, 4 } },
|
|
|
|
{ true, { 1, 1 }, { 2, 2 }, { 0, 0 }, { 1, 1, 3, 3 } },
|
|
|
|
{ true, { 2, 2 }, { 4, 4 }, { 0, 0 }, { 2, 2, 4, 4 } },
|
|
|
|
{ true, {-1,-1 }, { 2, 2 }, { 1, 1 }, { 0, 0, 1, 1 } },
|
|
|
|
{ false, {-1,-1 }, { 1, 1 }, { 0, 0 }, { 0, 0, 0, 0 } },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
|
|
|
|
clear_4x4_pixels(dstPixels);
|
|
|
|
|
2014-09-03 18:54:58 +00:00
|
|
|
dstInfo = dstInfo.makeWH(gRec[i].fRequestedDstSize.width(),
|
|
|
|
gRec[i].fRequestedDstSize.height());
|
2014-07-13 11:32:32 +00:00
|
|
|
bool success = srcBM.readPixels(dstInfo, dstPixels, rowBytes,
|
|
|
|
gRec[i].fRequestedSrcLoc.x(), gRec[i].fRequestedSrcLoc.y());
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-07-13 11:32:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, gRec[i].fExpectedSuccess == success);
|
|
|
|
if (success) {
|
|
|
|
const SkIRect srcR = gRec[i].fExpectedSrcR;
|
|
|
|
const int dstX = gRec[i].fExpectedDstLoc.x();
|
|
|
|
const int dstY = gRec[i].fExpectedDstLoc.y();
|
|
|
|
// Walk the dst pixels, and check if we got what we expected
|
|
|
|
for (int y = 0; y < H; ++y) {
|
|
|
|
for (int x = 0; x < W; ++x) {
|
|
|
|
SkPMColor dstC = dstPixels[y*4+x];
|
|
|
|
// get into src coordinates
|
|
|
|
int sx = x - dstX + srcR.x();
|
|
|
|
int sy = y - dstY + srcR.y();
|
|
|
|
if (srcR.contains(sx, sy)) {
|
|
|
|
REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy));
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 0 == dstC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|