void bbCopyRect( int sx,int sy,int w,int h,int dx,int dy,gxCanvas *src,gxCanvas *dest ){ if( src ) debugCanvas( src ); else src=gx_canvas; if( dest ) debugCanvas( dest ); else dest=gx_canvas; dest->blit( dx,dy,src,sx,sy,w,h,true ); }
// Extract the command ops from the input SkPicture static void gets_ops(SkPicture& input, SkTDArray<DrawType>* ops) { SkDebugCanvas debugCanvas(input.width(), input.height()); debugCanvas.setBounds(input.width(), input.height()); input.draw(&debugCanvas); ops->setCount(debugCanvas.getSize()); for (int i = 0; i < debugCanvas.getSize(); ++i) { (*ops)[i] = debugCanvas.getDrawCommandAt(i)->getType(); } }
void bbSetBuffer( gxCanvas *buff ){ debugCanvas( buff ); gx_canvas=buff; curs_x=curs_y=0; gx_canvas->setOrigin( 0,0 ); gx_canvas->setViewport( 0,0,gx_canvas->getWidth(),gx_canvas->getHeight() ); gx_canvas->setColor( curr_color ); gx_canvas->setClsColor( curr_clsColor ); gx_canvas->setFont( curr_font ); }
// Do the commands in 'input' match the supplied pattern? Note: this is a pretty // heavy-weight operation since we are drawing the picture into a debug canvas // to extract the commands. static bool check_pattern(SkPicture& input, const SkTDArray<DrawType> &pattern) { SkDebugCanvas debugCanvas(input.width(), input.height()); debugCanvas.setBounds(input.width(), input.height()); input.draw(&debugCanvas); if (pattern.count() != debugCanvas.getSize()) { return false; } for (int i = 0; i < pattern.count(); ++i) { if (pattern[i] != debugCanvas.getDrawCommandAt(i)->getType()) { return false; } } return true; }
int bbLoadBuffer( gxCanvas *c,BBStr *str ){ debugCanvas( c ); string s=*str;delete str; gxCanvas *t=gx_graphics->loadCanvas( s,0 ); if( !t ) return 0; float m[2][2]; m[0][0]=(float)c->getWidth()/(float)t->getWidth(); m[1][1]=(float)c->getHeight()/(float)t->getHeight(); m[1][0]=m[0][1]=0; gxCanvas *p=tformCanvas( t,m,0,0 ); gx_graphics->freeCanvas( t ); int ox,oy; c->getOrigin( &ox,&oy );c->setOrigin( 0,0 ); c->blit( 0,0,p,0,0,p->getWidth(),p->getHeight(),true ); gx_graphics->freeCanvas( p ); return 1; }
static int getPixel( gxCanvas *c,float x,float y ){ debugCanvas( c ); x-=.5f;y-=.5f; float fx=floor(x),fy=floor(y); int ix=fx,iy=fy;fx=x-fx;fy=y-fy; int tl=c->getPixel( ix,iy ); int tr=c->getPixel( ix+1,iy ); int br=c->getPixel( ix+1,iy+1 ); int bl=c->getPixel( ix,iy+1 ); float w1=(1-fx)*(1-fy),w2=fx*(1-fy),w3=(1-fx)*fy,w4=fx*fy; float r=RED(tl)*w1+RED(tr)*w2+RED(bl)*w3+RED(br)*w4; float g=GRN(tl)*w1+GRN(tr)*w2+GRN(bl)*w3+GRN(br)*w4; float b=BLU(tl)*w1+BLU(tr)*w2+BLU(bl)*w3+BLU(br)*w4; return (int(r+.5f)<<16)|(int(g+.5f)<<8)|int(b+.5f); }
/* If you execute skp_parser with one argument, it spits out a json representation of the skp, but that's incomplete since it's missing many binary blobs (these could represent images or typefaces or just anything that doesn't currently have a json representation). Each unique blob is labeled with a string in the form "data/%d". So for example: tools/git-sync-deps bin/gn gen out/debug ninja -C out/debug dm skp_parser out/debug/dm -m grayscale -w /tmp/dm --config skp out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp | less out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp | grep data out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp data/0 | file - out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp data/0 > /tmp/data0.png "data/0" is an image that the SKP serializer has encoded as PNG. */ int main(int argc, char** argv) { if (argc < 2) { SkDebugf("Usage:\n %s SKP_FILE [DATA_URL]\n", argv[0]); return 1; } SkFILEStream input(argv[1]); if (!input.isValid()) { SkDebugf("Bad file: '%s'\n", argv[1]); return 2; } sk_sp<SkPicture> pic = SkPicture::MakeFromStream(&input); if (!pic) { SkDebugf("Bad skp: '%s'\n", argv[1]); return 3; } SkISize size = pic->cullRect().roundOut().size(); SkDebugCanvas debugCanvas(size.width(), size.height()); pic->playback(&debugCanvas); std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas(); UrlDataManager dataManager(SkString("data")); Json::Value json = debugCanvas.toJSON( dataManager, debugCanvas.getSize(), nullCanvas.get()); if (argc > 2) { if (UrlDataManager::UrlData* data = dataManager.getDataFromUrl(SkString(argv[2]))) { SkData* skdata = data->fData.get(); SkASSERT(skdata); #ifdef SK_BUILD_FOR_WIN fflush(stdout); (void)_setmode(_fileno(stdout), _O_BINARY); #endif fwrite(skdata->data(), skdata->size(), 1, stdout); } else { SkDebugf("Bad data url.\n"); return 4; } } else { Json::StyledStreamWriter(" ").write(std::cout, json); } return 0; }
static int filter_picture(const SkString& inFile, const SkString& outFile) { SkAutoTDelete<SkPicture> inPicture; SkFILEStream inStream(inFile.c_str()); if (inStream.isValid()) { inPicture.reset(SkPicture::CreateFromStream(&inStream)); } if (NULL == inPicture.get()) { SkDebugf("Could not read file %s\n", inFile.c_str()); return -1; } int localCount[SK_ARRAY_COUNT(gOptTable)]; memset(localCount, 0, sizeof(localCount)); SkDebugCanvas debugCanvas(inPicture->width(), inPicture->height()); debugCanvas.setBounds(inPicture->width(), inPicture->height()); inPicture->draw(&debugCanvas); // delete the initial save and restore since replaying the commands will // re-add them if (debugCanvas.getSize() > 1) { debugCanvas.deleteDrawCommandAt(0); debugCanvas.deleteDrawCommandAt(debugCanvas.getSize()-1); } bool changed = true; int numBefore = debugCanvas.getSize(); while (changed) { changed = false; for (int i = 0; i < debugCanvas.getSize(); ++i) { for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { if ((*gOptTable[opt].fCheck)(&debugCanvas, i)) { (*gOptTable[opt].fApply)(&debugCanvas, i); ++gOptTable[opt].fNumTimesApplied; ++localCount[opt]; if (debugCanvas.getSize() == i) { // the optimization removed all the remaining operations break; } opt = 0; // try all the opts all over again changed = true; } } } } int numAfter = debugCanvas.getSize(); if (!outFile.isEmpty()) { SkPicture outPicture; SkCanvas* canvas = outPicture.beginRecording(inPicture->width(), inPicture->height()); debugCanvas.draw(canvas); outPicture.endRecording(); SkFILEWStream outStream(outFile.c_str()); outPicture.serialize(&outStream); } bool someOptFired = false; for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { if (0 != localCount[opt]) { SkDebugf("%d: %d ", opt, localCount[opt]); someOptFired = true; } } if (!someOptFired) { SkDebugf("No opts fired\n"); } else { SkDebugf("\t before: %d after: %d delta: %d\n", numBefore, numAfter, numBefore-numAfter); } return 0; }
void bbWritePixel( int x,int y,int argb,gxCanvas *buff ){ if( buff ) debugCanvas( buff ); (buff ? buff : gx_canvas)->setPixel( x,y,argb ); }
int bbReadPixel( int x,int y,gxCanvas *buff ){ if( buff ) debugCanvas( buff ); return (buff ? buff : gx_canvas)->getPixel( x,y ); }
void bbUnlockBuffer( gxCanvas *buff ){ if( buff ) debugCanvas( buff ); (buff ? buff : gx_canvas)->unlock(); }
void bbBufferDirty( gxCanvas *c ){ debugCanvas( c ); c->backup(); }
int bbSaveBuffer( gxCanvas *c,BBStr *str ){ debugCanvas( c ); string t=*str;delete str; return saveCanvas( c,t ) ? 1 : 0; }