本文整理汇总了C++中SkPicture::unref方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPicture::unref方法的具体用法?C++ SkPicture::unref怎么用?C++ SkPicture::unref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPicture
的用法示例。
在下文中一共展示了SkPicture::unref方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: afterChildren
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);
}
}
示例2: onDraw
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
SkMatrix matrix;
SkGroupShape* gs = new SkGroupShape;
SkAutoUnref aur(gs);
gs->appendShape(&fGroup);
matrix.setScale(-SK_Scalar1, SK_Scalar1);
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
gs->appendShape(&fGroup, matrix);
matrix.setTranslate(SkIntToScalar(240), 0);
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 1
SkPicture* pict = new SkPicture;
SkCanvas* cv = pict->beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
gs->draw(cv);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
gs->draw(cv);
pict->endRecording();
canvas->drawPicture(*pict);
pict->unref();
#endif
}
示例3: test_clone_empty
static void test_clone_empty(skiatest::Reporter* reporter) {
// This is a regression test for crbug.com/172062
// Before the fix, we used to crash accessing a null pointer when we
// had a picture with no paints. This test passes by not crashing.
{
SkPicture picture;
picture.beginRecording(1, 1);
picture.endRecording();
SkPicture* destPicture = picture.clone();
REPORTER_ASSERT(reporter, NULL != destPicture);
destPicture->unref();
}
{
// Test without call to endRecording
SkPicture picture;
picture.beginRecording(1, 1);
SkPicture* destPicture = picture.clone();
REPORTER_ASSERT(reporter, NULL != destPicture);
destPicture->unref();
}
}
示例4: drawpicture
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
}
示例5: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
SkScalar angle = SampleCode::GetAnimScalar(SkIntToScalar(180),
SkIntToScalar(360));
SkMatrix saveM = *fMatrixRefs[3];
SkScalar c = SkIntToScalar(50);
fMatrixRefs[3]->preRotate(angle, c, c);
const SkScalar dx = 350;
const SkScalar dy = 500;
const int N = 1;
for (int v = -N; v <= N; v++) {
for (int h = -N; h <= N; h++) {
SkAutoCanvasRestore acr(canvas, true);
canvas->translate(h * dx, v * dy);
SkMatrix matrix;
SkGroupShape* gs = new SkGroupShape;
SkAutoUnref aur(gs);
gs->appendShape(&fGroup);
matrix.setScale(-SK_Scalar1, SK_Scalar1);
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
gs->appendShape(&fGroup, matrix);
matrix.setTranslate(SkIntToScalar(240), 0);
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 1
SkPicture* pict = new SkPicture;
SkCanvas* cv = pict->beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
gs->draw(cv);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
gs->draw(cv);
pict->endRecording();
drawpicture(canvas, *pict);
pict->unref();
#endif
}}
*fMatrixRefs[3] = saveM;
this->inval(NULL);
}
示例6: testOne
void TestResult::testOne() {
SkPicture* pic = nullptr;
{
#if DEBUG_SHOW_TEST_NAME
if (fTestStep == kCompareBits) {
SkString testName(fFilename);
const char http[] = "http";
if (testName.startsWith(http)) {
testName.remove(0, sizeof(http) - 1);
}
while (testName.startsWith("_")) {
testName.remove(0, 1);
}
const char dotSkp[] = ".skp";
if (testName.endsWith(dotSkp)) {
size_t len = testName.size();
testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
}
testName.prepend("skp");
testName.append("1");
strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH);
} else if (fTestStep == kEncodeFiles) {
strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
}
#endif
SkString path = get_in_path(fDirNo, fFilename);
SkFILEStream stream(path.c_str());
if (!stream.isValid()) {
SkDebugf("invalid stream %s\n", path.c_str());
goto finish;
}
pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory);
if (!pic) {
SkDebugf("unable to decode %s\n", fFilename);
goto finish;
}
SkScalar width = pic->cullRect().width();
SkScalar height = pic->cullRect().height();
SkBitmap oldBitmap, opBitmap;
fScale = 1;
while (width / fScale > 32767 || height / fScale > 32767) {
++fScale;
}
do {
int dimX = SkScalarCeilToInt(width / fScale);
int dimY = SkScalarCeilToInt(height / fScale);
if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32Pixels(dimX, dimY)) {
break;
}
SkDebugf("-%d-", fScale);
} while (++fScale < 256);
if (fScale >= 256) {
SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename,
width, height);
goto finish;
}
oldBitmap.eraseColor(SK_ColorWHITE);
SkCanvas oldCanvas(oldBitmap);
oldCanvas.setAllowSimplifyClip(false);
opBitmap.eraseColor(SK_ColorWHITE);
SkCanvas opCanvas(opBitmap);
opCanvas.setAllowSimplifyClip(true);
drawPict(pic, &oldCanvas, fScale);
drawPict(pic, &opCanvas, fScale);
if (fTestStep == kCompareBits) {
fPixelError = similarBits(oldBitmap, opBitmap);
int oldTime = timePict(pic, &oldCanvas);
int opTime = timePict(pic, &opCanvas);
fTime = SkTMax(0, oldTime - opTime);
} else if (fTestStep == kEncodeFiles) {
SkString pngStr = make_png_name(fFilename);
const char* pngName = pngStr.c_str();
writePict(oldBitmap, outOldDir, pngName);
writePict(opBitmap, outOpDir, pngName);
}
}
finish:
if (pic) {
pic->unref();
}
}
示例7: killPicture
static void killPicture(JNIEnv* env, jobject, jlong pictureHandle) {
SkPicture* picture = reinterpret_cast<SkPicture*>(pictureHandle);
SkASSERT(picture);
picture->unref();
}
示例8: HandleMessage
virtual void HandleMessage(const pp::Var& var_message) {
// Receive a message from javascript.
if (var_message.is_string()) {
SkString msg(var_message.AsString().c_str());
if (msg.startsWith("init")) {
} else if (msg.startsWith("LoadSKP")) {
size_t startIndex = strlen("LoadSKP");
size_t dataSize = msg.size()/sizeof(char) - startIndex;
SkBase64 decodedData;
decodedData.decode(msg.c_str() + startIndex, dataSize);
size_t decodedSize = 3 * (dataSize / 4);
SkDebugf("Got size: %d\n", decodedSize);
if (!decodedData.getData()) {
SkDebugf("Failed to decode SKP\n");
return;
}
SkMemoryStream pictureStream(decodedData.getData(), decodedSize);
SkPicture* picture = SkPicture::CreateFromStream(&pictureStream);
if (NULL == picture) {
SkDebugf("Failed to create SKP.\n");
return;
}
fDebugger.loadPicture(picture);
picture->unref();
// Set up the command list.
SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
PostMessage("ClearCommands");
for (int i = 0; i < commands->count(); ++i) {
SkString addCommand("AddCommand:");
addCommand.append((*commands)[i]);
PostMessage(addCommand.c_str());
}
PostMessage("UpdateCommands");
// Set the overview text.
SkString overviewText;
fDebugger.getOverviewText(NULL, 0.0, &overviewText, 1);
overviewText.prepend("SetOverview:");
PostMessage(overviewText.c_str());
// Draw the SKP.
if (!fFlushLoopRunning) {
Paint();
}
} else if (msg.startsWith("CommandSelected:")) {
size_t startIndex = strlen("CommandSelected:");
int index = atoi(msg.c_str() + startIndex);
fDebugger.setIndex(index);
if (!fFlushLoopRunning) {
Paint();
}
} else if (msg.startsWith("Rewind")) {
fCanvas->clear(SK_ColorWHITE);
fDebugger.setIndex(0);
if (!fFlushLoopRunning) {
Paint();
}
} else if (msg.startsWith("StepBack")) {
fCanvas->clear(SK_ColorWHITE);
int currentIndex = fDebugger.index();
if (currentIndex > 1) {
fDebugger.setIndex(currentIndex - 1);
if (!fFlushLoopRunning) {
Paint();
}
}
} else if (msg.startsWith("Pause")) {
// TODO(borenet)
} else if (msg.startsWith("StepForward")) {
int currentIndex = fDebugger.index();
if (currentIndex < fDebugger.getSize() -1) {
fDebugger.setIndex(currentIndex + 1);
if (!fFlushLoopRunning) {
Paint();
}
}
} else if (msg.startsWith("Play")) {
fDebugger.setIndex(fDebugger.getSize() - 1);
if (!fFlushLoopRunning) {
Paint();
}
}
}
}
示例9:
~TilingView() {
fTextPicture->unref();
}