本文整理汇总了C++中SkData::size方法的典型用法代码示例。如果您正苦于以下问题:C++ SkData::size方法的具体用法?C++ SkData::size怎么用?C++ SkData::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkData
的用法示例。
在下文中一共展示了SkData::size方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: tool_main
int tool_main(int argc, char** argv) {
SkAutoGraphics ag;
SkLua L;
for (int i = 1; i < argc; ++i) {
SkData* data = nullptr;
const void* ptr;
size_t len;
if (!strcmp(argv[i], "--lua") && i < argc-1) {
ptr = argv[i + 1];
len = strlen(argv[i + 1]);
i += 1;
} else {
data = read_into_data(argv[i]);
ptr = data->data();
len = data->size();
}
if (!L.runCode(ptr, len)) {
SkDebugf("failed to load %s\n", argv[i]);
exit(-1);
}
SkSafeUnref(data);
}
return 0;
}
示例3: 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;
}
示例4: send_picture
static void send_picture(int socket, const PictureHeader& header, const SkData& skp) {
// Vectored IO lets us send header and skp contiguously without first
// copying them to a contiguous buffer.
struct nn_iovec iov[] = {
create_iov(&header, sizeof(header)),
create_iov(skp.data(), skp.size()),
};
struct nn_msghdr msg;
sk_bzero(&msg, sizeof(msg));
msg.msg_iov = iov;
msg.msg_iovlen = SK_ARRAY_COUNT(iov);
nn_sendmsg(socket, &msg, 0/*flags*/);
}
示例5: 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();
}
示例6: 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());
}
示例7: main
/*
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;
}
示例8: 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;
}
示例9: 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();
}
}
示例10: main
int main(int argc, char** argv)
{
#ifdef MTK_AOSP_ENHANCEMENT
// work around for SIGPIPE NE caused by abnormal system status
signal(SIGPIPE, SIG_IGN);
ALOGD("[Screencap] main");
#endif
ProcessState::self()->startThreadPool();
const char* pname = argv[0];
bool png = false;
int32_t displayId = DEFAULT_DISPLAY_ID;
int c;
while ((c = getopt(argc, argv, "phd:")) != -1) {
switch (c) {
case 'p':
png = true;
break;
case 'd':
displayId = atoi(optarg);
break;
case '?':
case 'h':
usage(pname);
return 1;
}
}
argc -= optind;
argv += optind;
int fd = -1;
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);
}
}
}
//.........这里部分代码省略.........
示例11: test_gatherpixelrefs
static void test_gatherpixelrefs(skiatest::Reporter* reporter) {
const int IW = 8;
const int IH = IW;
const SkScalar W = SkIntToScalar(IW);
const SkScalar H = W;
static const int N = 4;
SkBitmap bm[N];
SkPixelRef* refs[N];
const SkPoint pos[] = {
{ 0, 0 }, { W, 0 }, { 0, H }, { W, H }
};
// Our convention is that the color components contain the index of their
// corresponding bitmap/pixelref
for (int i = 0; i < N; ++i) {
make_bm(&bm[i], IW, IH, SkColorSetARGB(0xFF, i, i, i), true);
refs[i] = bm[i].pixelRef();
}
static const DrawBitmapProc procs[] = {
drawbitmap_proc, drawbitmaprect_proc, drawshader_proc
};
SkRandom rand;
for (size_t k = 0; k < SK_ARRAY_COUNT(procs); ++k) {
SkAutoTUnref<SkPicture> pic(record_bitmaps(bm, pos, N, procs[k]));
REPORTER_ASSERT(reporter, pic->willPlayBackBitmaps() || N == 0);
// quick check for a small piece of each quadrant, which should just
// contain 1 bitmap.
for (size_t i = 0; i < SK_ARRAY_COUNT(pos); ++i) {
SkRect r;
r.set(2, 2, W - 2, H - 2);
r.offset(pos[i].fX, pos[i].fY);
SkAutoDataUnref data(SkPictureUtils::GatherPixelRefs(pic, r));
REPORTER_ASSERT(reporter, data);
if (data) {
int count = static_cast<int>(data->size() / sizeof(SkPixelRef*));
REPORTER_ASSERT(reporter, 1 == count);
REPORTER_ASSERT(reporter, *(SkPixelRef**)data->data() == refs[i]);
}
}
// Test a bunch of random (mostly) rects, and compare the gather results
// with a deduced list of refs by looking at the colors drawn.
for (int j = 0; j < 100; ++j) {
SkRect r;
rand_rect(&r, rand, 2*W, 2*H);
SkBitmap result;
draw(pic, r, &result);
SkTDArray<SkPixelRef*> array;
SkData* data = SkPictureUtils::GatherPixelRefs(pic, r);
size_t dataSize = data ? data->size() : 0;
int gatherCount = static_cast<int>(dataSize / sizeof(SkPixelRef*));
SkASSERT(gatherCount * sizeof(SkPixelRef*) == dataSize);
SkPixelRef** gatherRefs = data ? (SkPixelRef**)(data->data()) : NULL;
SkAutoDataUnref adu(data);
gather_from_colors(result, refs, N, &array);
/*
* GatherPixelRefs is conservative, so it can return more bitmaps
* that we actually can see (usually because of conservative bounds
* inflation for antialiasing). Thus our check here is only that
* Gather didn't miss any that we actually saw. Even that isn't
* a strict requirement on Gather, which is meant to be quick and
* only mostly-correct, but at the moment this test should work.
*/
for (int i = 0; i < array.count(); ++i) {
bool found = find(gatherRefs, array[i], gatherCount);
REPORTER_ASSERT(reporter, found);
#if 0
// enable this block of code to debug failures, as it will rerun
// the case that failed.
if (!found) {
SkData* data = SkPictureUtils::GatherPixelRefs(pic, r);
size_t dataSize = data ? data->size() : 0;
}
#endif
}
}
}
}