本文整理汇总了C++中SkData::unref方法的典型用法代码示例。如果您正苦于以下问题:C++ SkData::unref方法的具体用法?C++ SkData::unref怎么用?C++ SkData::unref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkData
的用法示例。
在下文中一共展示了SkData::unref方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strlen
DEF_TEST(Data, reporter) {
const char* str = "We the people, in order to form a more perfect union.";
const int N = 10;
SkAutoTUnref<SkData> r0(SkData::NewEmpty());
SkAutoTUnref<SkData> r1(SkData::NewWithCopy(str, strlen(str)));
SkAutoTUnref<SkData> r2(SkData::NewWithProc(new int[N], N*sizeof(int),
delete_int_proc, gGlobal));
SkAutoTUnref<SkData> r3(SkData::NewSubset(r1, 7, 6));
assert_len(reporter, r0, 0);
assert_len(reporter, r1, strlen(str));
assert_len(reporter, r2, N * sizeof(int));
assert_len(reporter, r3, 6);
assert_data(reporter, r1, str, strlen(str));
assert_data(reporter, r3, "people", 6);
SkData* tmp = SkData::NewSubset(r1, strlen(str), 10);
assert_len(reporter, tmp, 0);
tmp->unref();
tmp = SkData::NewSubset(r1, 0, 0);
assert_len(reporter, tmp, 0);
tmp->unref();
test_cstring(reporter);
test_files(reporter);
}
示例2: TestDataRef
void TestDataRef(skiatest::Reporter* reporter) {
const char* str = "We the people, in order to form a more perfect union.";
const int N = 10;
SkData* r0 = SkData::NewEmpty();
SkData* r1 = SkData::NewWithCopy(str, strlen(str));
SkData* r2 = SkData::NewWithProc(new int[N], N*sizeof(int),
delete_int_proc, gGlobal);
SkData* r3 = SkData::NewSubset(r1, 7, 6);
SkAutoUnref aur0(r0);
SkAutoUnref aur1(r1);
SkAutoUnref aur2(r2);
SkAutoUnref aur3(r3);
assert_len(reporter, r0, 0);
assert_len(reporter, r1, strlen(str));
assert_len(reporter, r2, N * sizeof(int));
assert_len(reporter, r3, 6);
assert_data(reporter, r1, str, strlen(str));
assert_data(reporter, r3, "people", 6);
SkData* tmp = SkData::NewSubset(r1, strlen(str), 10);
assert_len(reporter, tmp, 0);
tmp->unref();
tmp = SkData::NewSubset(r1, 0, 0);
assert_len(reporter, tmp, 0);
tmp->unref();
}
示例3: setFrameStatus
TEST_F(ImageFrameGeneratorTest, incompleteDecodeBecomesCompleteMultiThreaded)
{
setFrameStatus(ImageFrame::FramePartial);
char buffer[100 * 100 * 4];
m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4);
EXPECT_EQ(1, m_decodeRequestCount);
EXPECT_EQ(0, m_decodersDestroyed);
SkData* data = m_generator->refEncodedData();
EXPECT_EQ(nullptr, data);
// LocalFrame can now be decoded completely.
setFrameStatus(ImageFrame::FrameComplete);
addNewData();
// addNewData is calling m_generator->setData with allDataReceived == false, which means that
// refEncodedData should return null.
data = m_generator->refEncodedData();
EXPECT_EQ(nullptr, data);
OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("DecodeThread"));
thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&decodeThreadMain, AllowCrossThreadAccess(m_generator.get()))));
thread.clear();
EXPECT_EQ(2, m_decodeRequestCount);
EXPECT_EQ(1, m_decodersDestroyed);
// Decoder created again.
m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4);
EXPECT_EQ(3, m_decodeRequestCount);
addNewData(true);
data = m_generator->refEncodedData();
ASSERT_TRUE(data);
// To prevent data writting, SkData::unique() should be false.
ASSERT_TRUE(!data->unique());
// Thread will also ref and unref the data.
thread = adoptPtr(Platform::current()->createThread("RefEncodedDataThread"));
thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&decodeThreadWithRefEncodedMain, AllowCrossThreadAccess(m_generator.get()))));
thread.clear();
EXPECT_EQ(4, m_decodeRequestCount);
data->unref();
// m_generator is holding the only reference to SkData now.
ASSERT_TRUE(data->unique());
data = m_generator->refEncodedData();
ASSERT_TRUE(data && !data->unique());
// Delete generator, and SkData should have the only reference.
m_generator = nullptr;
ASSERT_TRUE(data->unique());
data->unref();
}
示例4: flatten
static bool SK_WARN_UNUSED_RESULT flatten(const SkImage& image, Json::Value* target,
bool sendBinaries) {
if (sendBinaries) {
SkData* encoded = image.encode(SkImageEncoder::kPNG_Type, 100);
if (encoded == nullptr) {
// PNG encode doesn't necessarily support all color formats, convert to a different
// format
size_t rowBytes = 4 * image.width();
void* buffer = sk_malloc_throw(rowBytes * image.height());
SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(),
kN32_SkColorType, kPremul_SkAlphaType);
if (!image.readPixels(dstInfo, buffer, rowBytes, 0, 0)) {
SkDebugf("readPixels failed\n");
return false;
}
SkImage* converted = SkImage::NewRasterCopy(dstInfo, buffer, rowBytes);
encoded = converted->encode(SkImageEncoder::kPNG_Type, 100);
if (encoded == nullptr) {
SkDebugf("image encode failed\n");
return false;
}
free(converted);
free(buffer);
}
Json::Value bytes;
encode_data(encoded->data(), encoded->size(), &bytes);
(*target)[SKJSONCANVAS_ATTRIBUTE_BYTES] = bytes;
encoded->unref();
}
else {
SkString description = SkStringPrintf("%dx%d pixel image", image.width(), image.height());
(*target)[SKJSONCANVAS_ATTRIBUTE_DESCRIPTION] = Json::Value(description.c_str());
}
return true;
}
示例5: TestWStream
static void TestWStream(skiatest::Reporter* reporter) {
SkDynamicMemoryWStream ds;
const char s[] = "abcdefghijklmnopqrstuvwxyz";
int i;
for (i = 0; i < 100; i++) {
REPORTER_ASSERT(reporter, ds.write(s, 26));
}
REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26);
char* dst = new char[100 * 26 + 1];
dst[100*26] = '*';
ds.copyTo(dst);
REPORTER_ASSERT(reporter, dst[100*26] == '*');
// char* p = dst;
for (i = 0; i < 100; i++) {
REPORTER_ASSERT(reporter, memcmp(&dst[i * 26], s, 26) == 0);
}
{
SkData* data = ds.copyToData();
REPORTER_ASSERT(reporter, 100 * 26 == data->size());
REPORTER_ASSERT(reporter, memcmp(dst, data->data(), data->size()) == 0);
data->unref();
}
delete[] dst;
}
示例6: decodeThreadWithRefEncodedMain
static void decodeThreadWithRefEncodedMain(ImageFrameGenerator* generator)
{
// Image must be complete - refEncodedData otherwise returns null.
char buffer[100 * 100 * 4];
SkData* data = generator->refEncodedData();
generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4);
data->unref();
}
示例7:
DEF_TEST(ImageDataRef, reporter) {
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
size_t rowBytes = info.minRowBytes();
size_t size = info.getSafeSize(rowBytes);
SkData* data = SkData::NewUninitialized(size);
REPORTER_ASSERT(reporter, data->unique());
SkImage* image = SkImage::NewRasterData(info, data, rowBytes);
REPORTER_ASSERT(reporter, !data->unique());
image->unref();
REPORTER_ASSERT(reporter, data->unique());
data->unref();
}
示例8: ensureLua
lua_State* ensureLua() {
if (NULL == fLua) {
fLua = SkNEW(SkLua);
SkString str = GetResourcePath(LUA_FILENAME);
SkData* data = SkData::NewFromFileName(str.c_str());
if (data) {
fLua->runCode(data->data(), data->size());
data->unref();
this->setImageFilename(fLua->get());
} else {
fLua->runCode(gMissingCode);
}
}
return fLua->get();
}
示例9: CompressBitmapToFormat
SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) {
int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixmap.height());
if (compressedDataSize < 0) {
return NULL;
}
const uint8_t* src = reinterpret_cast<const uint8_t*>(pixmap.addr());
SkData* dst = SkData::NewUninitialized(compressedDataSize);
if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, pixmap.colorType(),
pixmap.width(), pixmap.height(), pixmap.rowBytes(), format)) {
dst->unref();
dst = NULL;
}
return dst;
}
示例10: toDataURL
String ImageBuffer::toDataURL(const String&, const double*) const
{
// Encode the image into a vector.
SkDynamicMemoryWStream pngStream;
const SkBitmap& dst = imageBufferCanvas(this)->getDevice()->accessBitmap(true);
SkImageEncoder::EncodeStream(&pngStream, dst, SkImageEncoder::kPNG_Type, 100);
// Convert it into base64.
Vector<char> pngEncodedData;
SkData* streamData = pngStream.copyToData();
pngEncodedData.append((char*)streamData->data(), streamData->size());
streamData->unref();
Vector<char> base64EncodedData;
base64Encode(pngEncodedData, base64EncodedData);
// Append with a \0 so that it's a valid string.
base64EncodedData.append('\0');
// And the resulting string.
return String::format("data:image/png;base64,%s", base64EncodedData.data());
}
示例11: sk_dataref_releaseproc
// assumes context is a SkData
static void sk_dataref_releaseproc(const void*, size_t, void* context) {
SkData* src = reinterpret_cast<SkData*>(context);
src->unref();
}
示例12: readPacket
int SkSocket::readPacket(void (*onRead)(int, const void*, size_t, DataType,
void*), void* context) {
if (!fConnected || !fReady || NULL == onRead || NULL == context
|| fReadSuspended)
return -1;
int totalBytesRead = 0;
char packet[PACKET_SIZE];
for (int i = 0; i <= fMaxfd; ++i) {
if (!FD_ISSET (i, &fMasterSet))
continue;
memset(packet, 0, PACKET_SIZE);
SkDynamicMemoryWStream stream;
int attempts = 0;
bool failure = false;
int bytesReadInTransfer = 0;
int bytesReadInPacket = 0;
header h;
h.done = false;
h.bytes = 0;
while (!h.done && fConnected && !failure) {
int retval = read(i, packet + bytesReadInPacket,
PACKET_SIZE - bytesReadInPacket);
++attempts;
if (retval < 0) {
#ifdef NONBLOCKING_SOCKETS
if (errno == EWOULDBLOCK || errno == EAGAIN) {
if (bytesReadInPacket > 0 || bytesReadInTransfer > 0)
continue; //incomplete packet or frame, keep tring
else
break; //nothing to read
}
#endif
//SkDebugf("Read() failed with error: %s\n", strerror(errno));
failure = true;
break;
}
if (retval == 0) {
//SkDebugf("Peer closed connection or connection failed\n");
failure = true;
break;
}
SkASSERT(retval > 0);
bytesReadInPacket += retval;
if (bytesReadInPacket < PACKET_SIZE) {
//SkDebugf("Read %d/%d\n", bytesReadInPacket, PACKET_SIZE);
continue; //incomplete packet, keep trying
}
SkASSERT((bytesReadInPacket == PACKET_SIZE) && !failure);
memcpy(&h.done, packet, sizeof(bool));
memcpy(&h.bytes, packet + sizeof(bool), sizeof(int));
memcpy(&h.type, packet + sizeof(bool) + sizeof(int), sizeof(DataType));
if (h.bytes > CONTENT_SIZE || h.bytes <= 0) {
//SkDebugf("bad packet\n");
failure = true;
break;
}
//SkDebugf("read packet(done:%d, bytes:%d) from fd:%d in %d tries\n",
// h.done, h.bytes, fSockfd, attempts);
stream.write(packet + HEADER_SIZE, h.bytes);
bytesReadInPacket = 0;
attempts = 0;
bytesReadInTransfer += h.bytes;
}
if (failure) {
onRead(i, NULL, 0, h.type, context);
this->onFailedConnection(i);
continue;
}
if (bytesReadInTransfer > 0) {
SkData* data = stream.copyToData();
SkASSERT(data->size() == bytesReadInTransfer);
onRead(i, data->data(), data->size(), h.type, context);
data->unref();
totalBytesRead += bytesReadInTransfer;
}
}
return totalBytesRead;
}
示例13: EmitPath
// static
void SkPDFUtils::EmitPath(const SkPath& path, SkPaint::Style paintStyle,
SkWStream* content) {
// Filling a path with no area results in a drawing in PDF renderers but
// Chrome expects to be able to draw some such entities with no visible
// result, so we detect those cases and discard the drawing for them.
// Specifically: moveTo(X), lineTo(Y) and moveTo(X), lineTo(X), lineTo(Y).
enum SkipFillState {
kEmpty_SkipFillState = 0,
kSingleLine_SkipFillState = 1,
kNonSingleLine_SkipFillState = 2,
};
SkipFillState fillState = kEmpty_SkipFillState;
if (paintStyle != SkPaint::kFill_Style) {
fillState = kNonSingleLine_SkipFillState;
}
SkPoint lastMovePt = SkPoint::Make(0,0);
SkDynamicMemoryWStream currentSegment;
SkPoint args[4];
SkPath::Iter iter(path, false);
for (SkPath::Verb verb = iter.next(args);
verb != SkPath::kDone_Verb;
verb = iter.next(args)) {
// args gets all the points, even the implicit first point.
switch (verb) {
case SkPath::kMove_Verb:
MoveTo(args[0].fX, args[0].fY, ¤tSegment);
lastMovePt = args[0];
fillState = kEmpty_SkipFillState;
break;
case SkPath::kLine_Verb:
AppendLine(args[1].fX, args[1].fY, ¤tSegment);
if (fillState == kEmpty_SkipFillState) {
if (args[0] != lastMovePt) {
fillState = kSingleLine_SkipFillState;
}
} else if (fillState == kSingleLine_SkipFillState) {
fillState = kNonSingleLine_SkipFillState;
}
break;
case SkPath::kQuad_Verb: {
SkPoint cubic[4];
SkConvertQuadToCubic(args, cubic);
AppendCubic(cubic[1].fX, cubic[1].fY, cubic[2].fX, cubic[2].fY,
cubic[3].fX, cubic[3].fY, ¤tSegment);
fillState = kNonSingleLine_SkipFillState;
break;
}
case SkPath::kCubic_Verb:
AppendCubic(args[1].fX, args[1].fY, args[2].fX, args[2].fY,
args[3].fX, args[3].fY, ¤tSegment);
fillState = kNonSingleLine_SkipFillState;
break;
case SkPath::kClose_Verb:
if (fillState != kSingleLine_SkipFillState) {
ClosePath(¤tSegment);
SkData* data = currentSegment.copyToData();
content->write(data->data(), data->size());
data->unref();
}
currentSegment.reset();
break;
default:
SkASSERT(false);
break;
}
}
if (currentSegment.bytesWritten() > 0) {
SkData* data = currentSegment.copyToData();
content->write(data->data(), data->size());
data->unref();
}
}
示例14: main
//.........这里部分代码省略.........
if (argc == 0) {
fd = dup(STDOUT_FILENO);
} else if (argc == 1) {
const char* fn = argv[0];
fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0664);
if (fd == -1) {
fprintf(stderr, "Error opening file: %s (%s)\n", fn, strerror(errno));
return 1;
}
const int len = strlen(fn);
if (len >= 4 && 0 == strcmp(fn+len-4, ".png")) {
png = true;
}
}
if (fd == -1) {
usage(pname);
return 1;
}
void const* mapbase = MAP_FAILED;
ssize_t mapsize = -1;
void const* base = 0;
uint32_t w, s, h, f;
size_t size = 0;
ScreenshotClient screenshot;
sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(displayId);
if (display != NULL && screenshot.update(display, Rect(), false) == NO_ERROR) {
base = screenshot.getPixels();
w = screenshot.getWidth();
h = screenshot.getHeight();
s = screenshot.getStride();
f = screenshot.getFormat();
size = screenshot.getSize();
#ifdef MTK_AOSP_ENHANCEMENT
ALOGD("[Screencap] screenshot w:%d h:%d s:%d f:%d", w, h, s, f);
#endif
} else {
const char* fbpath = "/dev/graphics/fb0";
int fb = open(fbpath, O_RDONLY);
if (fb >= 0) {
struct fb_var_screeninfo vinfo;
if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) == 0) {
uint32_t bytespp;
if (vinfoToPixelFormat(vinfo, &bytespp, &f) == NO_ERROR) {
#ifdef MTK_AOSP_ENHANCEMENT
size_t offset = (vinfo.xoffset + vinfo.yoffset*vinfo.xres_virtual) * bytespp;
w = vinfo.xres;
h = vinfo.yres;
s = vinfo.xres_virtual;
ALOGD("[Screencap] VSCREENINFO w:%d h:%d s:%d f:%d", w, h, s, f);
#else
size_t offset = (vinfo.xoffset + vinfo.yoffset*vinfo.xres) * bytespp;
w = vinfo.xres;
h = vinfo.yres;
s = vinfo.xres;
#endif
size = w*h*bytespp;
mapsize = offset + size;
mapbase = mmap(0, mapsize, PROT_READ, MAP_PRIVATE, fb, 0);
if (mapbase != MAP_FAILED) {
base = (void const *)((char const *)mapbase + offset);
}
}
}
close(fb);
}
}
if (base) {
if (png) {
const SkImageInfo info = SkImageInfo::Make(w, h, flinger2skia(f),
kPremul_SkAlphaType);
SkBitmap b;
b.installPixels(info, const_cast<void*>(base), s*bytesPerPixel(f));
SkDynamicMemoryWStream stream;
SkImageEncoder::EncodeStream(&stream, b,
SkImageEncoder::kPNG_Type, SkImageEncoder::kDefaultQuality);
SkData* streamData = stream.copyToData();
write(fd, streamData->data(), streamData->size());
streamData->unref();
} else {
write(fd, &w, 4);
write(fd, &h, 4);
write(fd, &f, 4);
size_t Bpp = bytesPerPixel(f);
for (size_t y=0 ; y<h ; y++) {
write(fd, base, w*Bpp);
base = (void *)((char *)base + s*Bpp);
}
}
}
close(fd);
if (mapbase != MAP_FAILED) {
munmap((void *)mapbase, mapsize);
}
return 0;
}