add gpu to gm tool

add pass-through read/write pixels API to canvas



git-svn-id: http://skia.googlecode.com/svn/trunk@660 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2010-12-23 19:29:18 +00:00
parent da96ea01fe
commit 51df9e3fe3
3 changed files with 45 additions and 3 deletions

View File

@ -181,12 +181,13 @@ static void write_pdf(GM* gm, const char writePath[]) {
static const struct {
SkBitmap::Config fConfig;
bool fUsePicture;
bool fUseGPU;
const char* fName;
} gRec[] = {
{ SkBitmap::kARGB_8888_Config, false, "8888" },
{ SkBitmap::kARGB_4444_Config, false, "4444" },
{ SkBitmap::kRGB_565_Config, false, "565" },
{ SkBitmap::kARGB_8888_Config, true, "gpu" },
};
int main (int argc, char * const argv[]) {
@ -242,12 +243,14 @@ int main (int argc, char * const argv[]) {
bitmap.eraseColor(0);
SkCanvas canvas(bitmap);
gm->draw(&canvas);
{
if (gRec[i].fUseGPU) {
SkGpuCanvas gc(context);
gc.setDevice(gc.createDevice(bitmap.config(), bitmap.width(), bitmap.height(),
bitmap.isOpaque(), false))->unref();
gm->draw(&gc);
gc.readPixels(&bitmap); // overwrite our previous allocation
} else {
gm->draw(&canvas);
}
SkString name = make_name(gm->shortName(), gRec[i].fName);

View File

@ -111,6 +111,20 @@ public:
*/
SkDevice* setBitmapDevice(const SkBitmap& bitmap, bool forLayer = false);
/**
* Copy the pixels from the device into bitmap. Returns true on success.
* If false is returned, then the bitmap parameter is left unchanged.
*/
bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
bool readPixels(SkBitmap* bitmap);
/**
* Similar to draw sprite, this method will copy the pixels in bitmap onto
* the device, with the top/left corner specified by (x, y). The pixel
* values in the device are completely replaced: there is no blending.
*/
void writePixels(const SkBitmap& bitmap, int x, int y);
///////////////////////////////////////////////////////////////////////////
enum SaveFlags {

View File

@ -549,6 +549,31 @@ SkDevice* SkCanvas::setBitmapDevice(const SkBitmap& bitmap, bool forLayer) {
return device;
}
bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
SkDevice* device = this->getDevice();
if (!device) {
return false;
}
return device->readPixels(srcRect, bitmap);
}
bool SkCanvas::readPixels(SkBitmap* bitmap) {
SkDevice* device = this->getDevice();
if (!device) {
return false;
}
SkIRect bounds;
bounds.set(0, 0, device->width(), device->height());
return this->readPixels(bounds, bitmap);
}
void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) {
SkDevice* device = this->getDevice();
if (device) {
device->writePixels(bitmap, x, y);
}
}
//////////////////////////////////////////////////////////////////////////////
bool SkCanvas::getViewport(SkIPoint* size) const {