Implement support for origin-TopLeft render targets in GL backend.

Committed: https://code.google.com/p/skia/source/detail?r=7545

Reverted in r7571; re-opening.

Review URL: https://codereview.appspot.com/7230049

git-svn-id: http://skia.googlecode.com/svn/trunk@7592 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
scroggo@google.com 2013-02-05 19:22:27 +00:00
parent 493c65f1aa
commit 9349101b6c
2 changed files with 9 additions and 36 deletions

View File

@ -828,10 +828,6 @@ void SkBitmap::eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const {
#define SUB_OFFSET_FAILURE ((size_t)-1)
// Declare these non-static so they can be tested by GpuBitmapCopyTest.
size_t getSubOffset(const SkBitmap& bm, int x, int y);
bool getUpperLeftFromOffset(const SkBitmap& bm, int* x, int* y);
/**
* Based on the Config and rowBytes() of bm, return the offset into an SkPixelRef of the pixel at
* (x, y).
@ -839,7 +835,7 @@ bool getUpperLeftFromOffset(const SkBitmap& bm, int* x, int* y);
* Also note that (x, y) may be outside the range of (0 - width(), 0 - height()), so long as it is
* within the bounds of the SkPixelRef being used.
*/
size_t getSubOffset(const SkBitmap& bm, int x, int y) {
static size_t getSubOffset(const SkBitmap& bm, int x, int y) {
switch (bm.getConfig()) {
case SkBitmap::kA8_Config:
case SkBitmap:: kIndex8_Config:
@ -868,7 +864,7 @@ size_t getSubOffset(const SkBitmap& bm, int x, int y) {
* upper left corner of bm relative to its SkPixelRef.
* x and y must be non-NULL.
*/
bool getUpperLeftFromOffset(const SkBitmap& bm, int* x, int* y) {
static bool getUpperLeftFromOffset(const SkBitmap& bm, int* x, int* y) {
SkASSERT(x != NULL && y != NULL);
const size_t offset = bm.pixelRefOffset();
if (0 == offset) {

View File

@ -33,19 +33,6 @@ struct Pair {
const char* fValid;
};
extern bool getUpperLeftFromOffset(const SkBitmap& bm, int* x, int* y);
extern size_t getSubOffset(const SkBitmap& bm, int x, int y);
/**
* Tests that getUpperLeftFromOffset and getSubOffset agree with each other.
*/
static void TestSubsetHelpers(skiatest::Reporter* reporter, const SkBitmap& bitmap){
int x, y;
bool upperLeft = getUpperLeftFromOffset(bitmap, &x, &y);
REPORTER_ASSERT(reporter, upperLeft);
REPORTER_ASSERT(reporter, getSubOffset(bitmap, x, y) == bitmap.pixelRefOffset());
}
/**
* Check to ensure that copying a GPU-backed SkBitmap behaved as expected.
* @param reporter Used to report failures.
@ -54,12 +41,10 @@ static void TestSubsetHelpers(skiatest::Reporter* reporter, const SkBitmap& bitm
* @param src A GPU-backed SkBitmap that had copyTo or deepCopyTo called on it.
* @param dst SkBitmap that was copied to.
* @param deepCopy True if deepCopyTo was used; false if copyTo was used.
* @param subset Portion of src's SkPixelRef that src represents. dst should represent the same
* portion after the copy. Pass NULL for all pixels.
*/
static void TestIndividualCopy(skiatest::Reporter* reporter, const SkBitmap::Config desiredConfig,
const bool success, const SkBitmap& src, const SkBitmap& dst,
const bool deepCopy = true, const SkIRect* subset = NULL) {
const bool deepCopy = true) {
if (success) {
REPORTER_ASSERT(reporter, src.width() == dst.width());
REPORTER_ASSERT(reporter, src.height() == dst.height());
@ -78,11 +63,11 @@ static void TestIndividualCopy(skiatest::Reporter* reporter, const SkBitmap::Con
SkBitmap srcReadBack, dstReadBack;
{
SkASSERT(src.getTexture() != NULL);
bool readBack = src.pixelRef()->readPixels(&srcReadBack, subset);
bool readBack = src.pixelRef()->readPixels(&srcReadBack);
REPORTER_ASSERT(reporter, readBack);
}
if (dst.getTexture() != NULL) {
bool readBack = dst.pixelRef()->readPixels(&dstReadBack, subset);
bool readBack = dst.pixelRef()->readPixels(&dstReadBack);
REPORTER_ASSERT(reporter, readBack);
} else {
// If dst is not a texture, do a copy instead, to the same config as srcReadBack.
@ -102,11 +87,6 @@ static void TestIndividualCopy(skiatest::Reporter* reporter, const SkBitmap::Con
} else {
REPORTER_ASSERT(reporter, src.getGenerationID() != dst.getGenerationID());
}
// If the copy used a subset, test the pixel offset calculation functions.
if (subset != NULL) {
TestSubsetHelpers(reporter, dst);
}
} else {
// dst should be unchanged from its initial state
REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config);
@ -170,9 +150,6 @@ static void TestGpuBitmapCopy(skiatest::Reporter* reporter, GrContextFactory* fa
// Extract a subset. If this succeeds we will test copying the subset.
SkBitmap subset;
const bool extracted = src.extractSubset(&subset, subsetRect);
if (extracted) {
TestSubsetHelpers(reporter, subset);
}
for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
dst.reset();
@ -204,16 +181,16 @@ static void TestGpuBitmapCopy(skiatest::Reporter* reporter, GrContextFactory* fa
success = subset.copyTo(&subsetCopy, gPairs[j].fConfig);
REPORTER_ASSERT(reporter, success == expected);
REPORTER_ASSERT(reporter, success == canSucceed);
TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy, false,
&subsetRect);
TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy,
false);
// Reset the bitmap so that a failed copyTo will leave it in the expected state.
subsetCopy.reset();
success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig);
REPORTER_ASSERT(reporter, success == expected);
REPORTER_ASSERT(reporter, success == canSucceed);
TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy, true,
&subsetRect);
TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy,
true);
}
} // for (size_t j = ...
} // for (size_t i = ...