From 76b82742421dc29c69badfb21974f836f8e47b3b Mon Sep 17 00:00:00 2001 From: "twiz@google.com" Date: Thu, 2 Jun 2011 20:30:02 +0000 Subject: 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 --- samplecode/SampleTextureDomain.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'samplecode/SampleTextureDomain.cpp') diff --git a/samplecode/SampleTextureDomain.cpp b/samplecode/SampleTextureDomain.cpp index 4debacc6d7..be000f95f2 100755 --- a/samplecode/SampleTextureDomain.cpp +++ b/samplecode/SampleTextureDomain.cpp @@ -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 primaryDevice(canvas->getDevice()); + SkRefPtr 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; -- cgit v1.2.3