Correction of texture domain calculation. Review=http://codereview.appspot.com/4517126

git-svn-id: http://skia.googlecode.com/svn/trunk@1483 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
twiz@google.com 2011-06-02 20:30:02 +00:00
parent 0a030cde4e
commit 76b8274242
2 changed files with 37 additions and 11 deletions

View File

@ -342,20 +342,19 @@ void GrGpuGLShaders::flushViewMatrix() {
void GrGpuGLShaders::flushTextureDomain(int s) {
const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTexDomUni;
if (GrGLProgram::kUnusedUniform != uni) {
const GrRect &texDom =
const GrRect &texDom =
fCurrDrawState.fSamplerStates[s].getTextureDomain();
if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
fProgramData->fTextureDomain[s] != texDom)
if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
fProgramData->fTextureDomain[s] != texDom) {
{
fProgramData->fTextureDomain[s] = texDom;
float values[4] = {
GrScalarToFloat(texDom.left()),
GrScalarToFloat(texDom.top()),
GrScalarToFloat(texDom.right()),
GrScalarToFloat(texDom.bottom())
GrScalarToFloat(texDom.left()),
GrScalarToFloat(texDom.top()),
GrScalarToFloat(texDom.right()),
GrScalarToFloat(texDom.bottom())
};
GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
@ -365,6 +364,9 @@ void GrGpuGLShaders::flushTextureDomain(int s) {
if (GrGLTexture::kBottomUp_Orientation == orientation) {
values[1] = 1.0f - values[1];
values[3] = 1.0f - values[3];
// The top and bottom were just flipped, so correct the ordering
// of elements so that values = (l, t, r, b).
SkTSwap(values[1], values[3]);
}
values[0] *= SkScalarToFloat(texture->contentScaleX());

View File

@ -1,10 +1,11 @@
#include "SampleCode.h"
#include "SkCanvas.h"
#include "SkDevice.h"
namespace {
SkBitmap make_bitmap() {
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config , 10, 10);
bm.setConfig(SkBitmap::kARGB_8888_Config , 5, 5);
bm.allocPixels();
for (int y = 0; y < bm.height(); y++) {
@ -41,9 +42,32 @@ protected:
SkRect dstRect;
SkPaint paint;
paint.setFilterBitmap(true);
srcRect.setXYWH(1, 1, 8, 8);
dstRect.setXYWH(10.0f, 10.0f, 810.0f, 810.0f);
// Test that bitmap draws from malloc-backed bitmaps respect
// the constrained texture domain.
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(5.0f, 5.0f, 305.0f, 305.0f);
canvas->drawBitmapRect(fBM, &srcRect, dstRect, &paint);
// Test that bitmap draws across separate devices also respect
// the constrainted texture domain.
// Note: GPU-backed bitmaps follow a different rendering path
// when copying from one GPU device to another.
SkRefPtr<SkDevice> primaryDevice(canvas->getDevice());
SkRefPtr<SkDevice> secondDevice(canvas->createDevice(
SkBitmap::kARGB_8888_Config, 5, 5, true, true));
secondDevice->unref();
SkCanvas secondCanvas(secondDevice.get());
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(1.0f, 1.0f, 3.0f, 3.0f);
secondCanvas.drawBitmapRect(fBM, &srcRect, dstRect, &paint);
SkBitmap deviceBitmap = secondDevice->accessBitmap(false);
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(405.0f, 5.0f, 305.0f, 305.0f);
canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
}
private:
typedef SkView INHERITED;