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"
|
2018-03-09 19:41:36 +00:00
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkColorSpace.h"
|
|
|
|
#include "SkImageInfo.h"
|
|
|
|
#include "SkPoint.h"
|
2009-05-05 23:13:23 +00:00
|
|
|
#include "SkRect.h"
|
2018-03-09 19:41:36 +00:00
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkSize.h"
|
|
|
|
#include "SkTypes.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2017-04-28 15:15:22 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2009-05-01 04:00:01 +00:00
|
|
|
|
2013-10-10 14:44:56 +00:00
|
|
|
static void init_src(const SkBitmap& bitmap) {
|
2009-05-01 04:00:01 +00:00
|
|
|
if (bitmap.getPixels()) {
|
2017-07-18 14:53:11 +00:00
|
|
|
bitmap.eraseColor(SK_ColorWHITE);
|
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()
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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[] = {
|
2017-04-05 19:41:53 +00:00
|
|
|
{ kUnknown_SkColorType, "0000000" },
|
|
|
|
{ kAlpha_8_SkColorType, "0100000" },
|
|
|
|
{ kRGB_565_SkColorType, "0101011" },
|
|
|
|
{ kARGB_4444_SkColorType, "0101111" },
|
|
|
|
{ kN32_SkColorType, "0101111" },
|
|
|
|
{ kRGBA_F16_SkColorType, "0101011" },
|
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) {
|
2017-04-05 19:41:53 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace = nullptr;
|
|
|
|
if (kRGBA_F16_SkColorType == ct) {
|
2018-08-27 19:16:02 +00:00
|
|
|
colorSpace = SkColorSpace::MakeSRGB();
|
2017-04-05 19:41:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 19:10:28 +00:00
|
|
|
srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType, colorSpace));
|
|
|
|
srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType, colorSpace));
|
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;
|
2017-04-28 15:15:22 +00:00
|
|
|
bool success = sk_tool_utils::copy_to(©, gPairs[j].fColorType, subset);
|
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-07-12 19:10:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, 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);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|