// Ensure that serializing an empty picture does not assert. Likewise only runs in debug mode. static void test_serializing_empty_picture() { SkPicture picture; picture.beginRecording(0, 0); picture.endRecording(); SkDynamicMemoryWStream stream; picture.serialize(&stream); }
static bool nativeSerializeViewState(JNIEnv* env, jobject, jint jbaseLayer, jobject jstream, jbyteArray jstorage) { BaseLayerAndroid* baseLayer = (BaseLayerAndroid*) jbaseLayer; if (!baseLayer) return false; SkWStream *stream = CreateJavaOutputStreamAdaptor(env, jstream, jstorage); #if USE(ACCELERATED_COMPOSITING) // SAMSUNG CHANGE >> White flickering issue. // WAS:stream->write32(baseLayer->getBackgroundColor().rgb()); stream->write32(baseLayer->getBackgroundColor()); // SAMSUNG CHANGE << #else stream->write32(0); #endif SkPicture picture; PictureSet* content = baseLayer->content(); baseLayer->drawCanvas(picture.beginRecording(content->width(), content->height(), SkPicture::kUsePathBoundsForClip_RecordingFlag)); picture.endRecording(); if (!stream) return false; picture.serialize(stream); int childCount = baseLayer->countChildren(); XLOG("BaseLayer has %d child(ren)", childCount); stream->write32(childCount); for (int i = 0; i < childCount; i++) { LayerAndroid* layer = static_cast<LayerAndroid*>(baseLayer->getChild(i)); serializeLayer(layer, stream); } delete stream; return true; }
static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { SkPicture picture; SkCanvas* canvas = picture.beginRecording(bitmap.width(), bitmap.height()); canvas->drawBitmap(bitmap, 0, 0); SkDynamicMemoryWStream wStream; picture.serialize(&wStream, &encode_bitmap_to_data); return wStream.copyToData(); }
void PicturePileLayerContent::serialize(SkWStream* stream) { if (!stream) return; SkPicture picture; draw(picture.beginRecording(width(), height(), SkPicture::kUsePathBoundsForClip_RecordingFlag)); picture.endRecording(); picture.serialize(stream); }
static jboolean serialize(JNIEnv* env, jobject, jlong pictureHandle, jobject jstream, jbyteArray jstorage) { SkPicture* picture = reinterpret_cast<SkPicture*>(pictureHandle); SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage); if (NULL != strm) { picture->serialize(strm); delete strm; return JNI_TRUE; } return JNI_FALSE; }
void drawpicture(SkCanvas* canvas, SkPicture& pict) { #if 0 SkDynamicMemoryWStream ostream; pict.serialize(&ostream); SkMemoryStream istream(ostream.getStream(), ostream.getOffset()); SkPicture* newPict = new SkPicture(&istream); canvas->drawPicture(*newPict); newPict->unref(); #else canvas->drawPicture(pict); #endif }
void SampleWindow::afterChildren(SkCanvas* orig) { switch (fCanvasType) { case kRaster_CanvasType: break; case kPicture_CanvasType: if (true) { SkPicture* pict = new SkPicture(*fPicture); fPicture->unref(); orig->drawPicture(*pict); pict->unref(); } else if (true) { SkDynamicMemoryWStream ostream; fPicture->serialize(&ostream); fPicture->unref(); SkMemoryStream istream(ostream.getStream(), ostream.getOffset()); SkPicture pict(&istream); orig->drawPicture(pict); } else { fPicture->draw(orig); fPicture->unref(); } fPicture = NULL; break; #ifdef SK_SUPPORT_GL case kOpenGL_CanvasType: glFlush(); delete fGLCanvas; fGLCanvas = NULL; #ifdef USE_OFFSCREEN reverseRedAndBlue(orig->getDevice()->accessBitmap(true)); #endif break; #endif } // if ((fScrollTestX | fScrollTestY) != 0) { const SkBitmap& bm = orig->getDevice()->accessBitmap(true); int dx = fScrollTestX * 7; int dy = fScrollTestY * 7; SkIRect r; SkRegion inval; r.set(50, 50, 50+100, 50+100); bm.scrollRect(&r, dx, dy, &inval); paint_rgn(bm, r, inval); } }
void SerializeTask::draw() { SkPicture recorded; RecordPicture(fGM.get(), &recorded); SkDynamicMemoryWStream wStream; recorded.serialize(&wStream, &trivial_bitmap_encoder); SkAutoTUnref<SkStream> rStream(wStream.detachAsStream()); SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream)); SkBitmap bitmap; SetupBitmap(fReference.config(), fGM.get(), &bitmap); DrawPicture(reconstructed, &bitmap); if (!BitmapsEqual(bitmap, fReference)) { this->fail(); this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); } }
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; }