bool SkWStream::writeBigDecAsText(int64_t dec, int minDigits) { SkString tmp; tmp.appendS64(dec, minDigits); return this->write(tmp.c_str(), tmp.size()); }
DEF_TEST(SkpSkGr, reporter) { SkTArray<TestResult, true> errors; if (!initTest()) { return; } SkpSkGrThreadState state; state.init(0); int smallCount = 0; for (int dirNo = 1; dirNo <= 100; ++dirNo) { SkString pictDir = make_in_dir_name(dirNo); SkASSERT(pictDir.size()); if (reporter->verbose()) { SkDebugf("dirNo=%d\n", dirNo); } SkOSFile::Iter iter(pictDir.c_str(), "skp"); SkString filename; int testCount = 0; PreParser preParser(dirNo); SkFILEWStream statusStream(makeStatusString(dirNo).c_str()); while (iter.next(&filename)) { for (size_t index = 0; index < skipOverSkGrCount; ++index) { if (skipOverSkGr[index].directory == dirNo && strcmp(filename.c_str(), skipOverSkGr[index].filename) == 0) { goto skipOver; } } if (preParser.match(filename, &statusStream, &state.fResult)) { addError(&state); ++testCount; goto checkEarlyExit; } if (state.fSmallestError > 5000000) { goto breakOut; } { TestResult& result = state.fResult; result.test(dirNo, filename); SkString outStr(result.status()); statusStream.write(outStr.c_str(), outStr.size()); statusStream.flush(); if (1) { SkDebugf("%s", outStr.c_str()); } bool noMatch = addError(&state); if (noMatch) { smallCount = 0; } else if (++smallCount > 10000) { goto breakOut; } } ++testCount; if (reporter->verbose()) { if (testCount % 100 == 0) { SkDebugf("#%d\n", testCount); } } skipOver: reporter->bumpTestCount(); checkEarlyExit: if (1 && testCount == 20) { break; } } } breakOut: if (reporter->verbose()) { for (int index = 0; index < state.fFoundCount; ++index) { SkDebugf("%d %s %d\n", state.fDirsFound[index], state.fFilesFound[index], state.fError[index]); } } for (int index = 0; index < state.fFoundCount; ++index) { TestResult::Test(state.fDirsFound[index], state.fFilesFound[index], kEncodeFiles, reporter->verbose()); if (reporter->verbose()) SkDebugf("+"); } }
// "FooBar" -> "foobar". Obviously, ASCII only. static SkString lowercase(SkString s) { for (size_t i = 0; i < s.size(); i++) { s[i] = tolower(s[i]); } return s; }
bool CopyTilesRenderer::render(SkBitmap** out) { int i = 0; bool success = true; SkBitmap dst; for (int x = 0; x < this->getViewWidth(); x += fLargeTileWidth) { for (int y = 0; y < this->getViewHeight(); y += fLargeTileHeight) { SkAutoCanvasRestore autoRestore(fCanvas, true); // Translate so that we draw the correct portion of the picture. // Perform a postTranslate so that the scaleFactor does not interfere with the // positioning. SkMatrix mat(fCanvas->getTotalMatrix()); mat.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); fCanvas->setMatrix(mat); // Draw the picture if (fUseMultiPictureDraw) { SkMultiPictureDraw mpd; mpd.add(fCanvas, fPicture); mpd.draw(); } else { fCanvas->drawPicture(fPicture); } // Now extract the picture into tiles SkBitmap baseBitmap; fCanvas->readPixels(SkIRect::MakeSize(fCanvas->getBaseLayerSize()), &baseBitmap); SkIRect subset; for (int tileY = 0; tileY < fLargeTileHeight; tileY += this->getTileHeight()) { for (int tileX = 0; tileX < fLargeTileWidth; tileX += this->getTileWidth()) { subset.set(tileX, tileY, tileX + this->getTileWidth(), tileY + this->getTileHeight()); SkDEBUGCODE(bool extracted =) baseBitmap.extractSubset(&dst, subset); SkASSERT(extracted); if (!fWritePath.isEmpty()) { // Similar to write() in PictureRenderer.cpp, but just encodes // a bitmap directly. // TODO: Share more common code with write() to do this, to properly // write out the JSON summary, etc. SkString pathWithNumber = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_str()); pathWithNumber.remove(pathWithNumber.size() - 4, 4); pathWithNumber.appendf("%i.png", i++); SkBitmap copy; #if SK_SUPPORT_GPU if (isUsingGpuDevice()) { dst.pixelRef()->readPixels(©, &subset); } else { #endif dst.copyTo(©); #if SK_SUPPORT_GPU } #endif success &= SkImageEncoder::EncodeFile(pathWithNumber.c_str(), copy, SkImageEncoder::kPNG_Type, 100); } } } } } return success; }
int tool_main(int argc, char** argv) { SkCommandLineFlags::SetUsage("Render .skp files."); SkCommandLineFlags::Parse(argc, argv); if (FLAGS_readPath.isEmpty()) { SkDebugf(".skp files or directories are required.\n"); exit(-1); } if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) { SkDebugf("--maxComponentDiff must be between 0 and 256\n"); exit(-1); } if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) { SkDebugf("--maxComponentDiff requires --validate\n"); exit(-1); } if (FLAGS_writeEncodedImages) { if (FLAGS_writePath.isEmpty()) { SkDebugf("--writeEncodedImages requires --writePath\n"); exit(-1); } if (FLAGS_deferImageDecoding) { SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n"); exit(-1); } } SkString errorString; SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, kRender_PictureTool)); if (errorString.size() > 0) { SkDebugf("%s\n", errorString.c_str()); } if (renderer.get() == NULL) { exit(-1); } SkAutoGraphics ag; SkString writePath; if (FLAGS_writePath.count() == 1) { writePath.set(FLAGS_writePath[0]); } SkString mismatchPath; if (FLAGS_mismatchPath.count() == 1) { mismatchPath.set(FLAGS_mismatchPath[0]); } sk_tools::ImageResultsAndExpectations jsonSummary; sk_tools::ImageResultsAndExpectations* jsonSummaryPtr = NULL; if (FLAGS_writeJsonSummaryPath.count() == 1) { jsonSummaryPtr = &jsonSummary; if (FLAGS_readJsonSummaryPath.count() == 1) { SkASSERT(jsonSummary.readExpectationsFile(FLAGS_readJsonSummaryPath[0])); } } int failures = 0; for (int i = 0; i < FLAGS_readPath.count(); i ++) { failures += process_input(FLAGS_readPath[i], &writePath, &mismatchPath, *renderer.get(), jsonSummaryPtr); } if (failures != 0) { SkDebugf("Failed to render %i pictures.\n", failures); return 1; } #if GR_CACHE_STATS && SK_SUPPORT_GPU if (renderer->isUsingGpuDevice()) { GrContext* ctx = renderer->getGrContext(); ctx->printCacheStats(); } #endif #if GR_GPU_STATS && SK_SUPPORT_GPU if (FLAGS_gpuStats && renderer->isUsingGpuDevice()) { renderer->getGrContext()->printGpuStats(); } #endif if (FLAGS_writeJsonSummaryPath.count() == 1) { // If there were any descriptions on the command line, insert them now. for (int i=0; i<FLAGS_descriptions.count(); i++) { SkTArray<SkString> tokens; SkStrSplit(FLAGS_descriptions[i], "=", &tokens); SkASSERT(tokens.count() == 2); jsonSummary.addDescription(tokens[0].c_str(), tokens[1].c_str()); } if (FLAGS_imageBaseGSUrl.count() == 1) { jsonSummary.setImageBaseGSUrl(FLAGS_imageBaseGSUrl[0]); } jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]); } return 0; }
SkPDFString::SkPDFString(const SkString& value) : fValue(FormatString(value.c_str(), value.size())) { }
void addText(const SkString& text) { fWriter->addText(text.c_str(), text.size()); }
int tool_main(int argc, char** argv) { SkCommandLineFlags::SetUsage("Render .skp files."); SkCommandLineFlags::Parse(argc, argv); if (FLAGS_readPath.isEmpty()) { SkDebugf(".skp files or directories are required.\n"); exit(-1); } if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) { SkDebugf("--maxComponentDiff must be between 0 and 256\n"); exit(-1); } if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) { SkDebugf("--maxComponentDiff requires --validate\n"); exit(-1); } if (FLAGS_clone < 0) { SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone); exit(-1); } if (FLAGS_writeEncodedImages) { if (FLAGS_writePath.isEmpty()) { SkDebugf("--writeEncodedImages requires --writePath\n"); exit(-1); } if (FLAGS_deferImageDecoding) { SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n"); exit(-1); } } SkString errorString; SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, kRender_PictureTool)); if (errorString.size() > 0) { SkDebugf("%s\n", errorString.c_str()); } if (renderer.get() == NULL) { exit(-1); } SkAutoGraphics ag; SkString outputDir; if (FLAGS_writePath.count() == 1) { outputDir.set(FLAGS_writePath[0]); } sk_tools::ImageResultsSummary jsonSummary; sk_tools::ImageResultsSummary* jsonSummaryPtr = NULL; if (FLAGS_writeJsonSummaryPath.count() == 1) { jsonSummaryPtr = &jsonSummary; } int failures = 0; for (int i = 0; i < FLAGS_readPath.count(); i ++) { failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get(), jsonSummaryPtr); } if (failures != 0) { SkDebugf("Failed to render %i pictures.\n", failures); return 1; } #if SK_SUPPORT_GPU #if GR_CACHE_STATS if (renderer->isUsingGpuDevice()) { GrContext* ctx = renderer->getGrContext(); ctx->printCacheStats(); #ifdef SK_DEVELOPER ctx->dumpFontCache(); #endif } #endif #endif if (FLAGS_writeJsonSummaryPath.count() == 1) { jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]); } return 0; }
static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) { sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount]; sk_bzero(drawFilters, sizeof(drawFilters)); if (FLAGS_filter.count() > 0) { const char* filters = FLAGS_filter[0]; const char* colon = strchr(filters, ':'); if (colon) { int32_t type = -1; size_t typeLen = colon - filters; for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) { if (typeLen == strlen(gFilterTypes[tIndex]) && !strncmp(filters, gFilterTypes[tIndex], typeLen)) { type = SkToS32(tIndex); break; } } if (type < 0) { SkString err; err.printf("Unknown type for --filter %s\n", filters); gLogger.logError(err); exit(-1); } int flag = -1; size_t flagLen = strlen(filters) - typeLen - 1; for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) { if (flagLen == strlen(gFilterFlags[fIndex]) && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) { flag = 1 << fIndex; break; } } if (flag < 0) { SkString err; err.printf("Unknown flag for --filter %s\n", filters); gLogger.logError(err); exit(-1); } for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) { if (type != SkDrawFilter::kTypeCount && index != type) { continue; } drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags) (drawFilters[index] | flag); } } else { SkString err; err.printf("Unknown arg for --filter %s : missing colon\n", filters); gLogger.logError(err); exit(-1); } } if (FLAGS_timers.count() > 0) { size_t index = 0; bool timerWall = false; bool truncatedTimerWall = false; bool timerCpu = false; bool truncatedTimerCpu = false; bool timerGpu = false; while (index < strlen(FLAGS_timers[0])) { switch (FLAGS_timers[0][index]) { case 'w': timerWall = true; break; case 'c': timerCpu = true; break; case 'W': truncatedTimerWall = true; break; case 'C': truncatedTimerCpu = true; break; case 'g': timerGpu = true; break; default: SkDebugf("mystery character\n"); break; } index++; } benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu, timerGpu); } SkString errorString; SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, kBench_PictureTool)); if (errorString.size() > 0) { gLogger.logError(errorString); } if (NULL == renderer.get()) { exit(-1); } if (FLAGS_timeIndividualTiles) { sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer(); if (NULL == tiledRenderer) { gLogger.logError("--timeIndividualTiles requires tiled rendering.\n"); exit(-1); } if (!tiledRenderer->supportsTimingIndividualTiles()) { gLogger.logError("This renderer does not support --timeIndividualTiles.\n"); exit(-1); } benchmark->setTimeIndividualTiles(true); } benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex); benchmark->setPreprocess(FLAGS_preprocess); if (FLAGS_readPath.count() < 1) { gLogger.logError(".skp files or directories are required.\n"); exit(-1); } renderer->setDrawFilters(drawFilters, filtersName(drawFilters)); if (FLAGS_logPerIter) { benchmark->setTimerResultType(TimerData::kPerIter_Result); } else if (FLAGS_min) { benchmark->setTimerResultType(TimerData::kMin_Result); } else { benchmark->setTimerResultType(TimerData::kAvg_Result); } benchmark->setRenderer(renderer); benchmark->setRepeats(FLAGS_repeat); benchmark->setWriter(&gWriter); }
bool SkSVGPaint::writeChangedAttributes(SkSVGParser& parser, SkSVGPaint& current, bool* changed) { SkSVGPaint& lastState = parser.fLastFlush; for (int index = kInitial + 1; index < kTerminal; index++) { if (changed[index] == false) continue; SkString* topAttr = current[index]; size_t attrLength = topAttr->size(); if (attrLength == 0) continue; const char* attrValue = topAttr->c_str(); SkString* lastAttr = lastState[index]; switch(index) { case kClipPath: case kClipRule: case kEnableBackground: break; case kFill: if (topAttr->equals("none") == false && lastAttr->equals("none") == true) parser._addAttribute("stroke", "false"); goto fillStrokeAttrCommon; case kFillRule: case kFilter: case kFontFamily: break; case kFontSize: parser._addAttributeLen("textSize", attrValue, attrLength); break; case kLetterSpacing: parser._addAttributeLen("textTracking", attrValue, attrLength); break; case kMask: break; case kOpacity: break; case kStopColor: break; case kStopOpacity: break; case kStroke: if (topAttr->equals("none") == false && lastAttr->equals("none") == true) parser._addAttribute("stroke", "true"); fillStrokeAttrCommon: if (strncmp(attrValue, "url(", 4) == 0) { SkASSERT(attrValue[4] == '#'); const char* idStart = attrValue + 5; const char* idEnd = strrchr(attrValue, ')'); SkASSERT(idStart < idEnd); SkString id(idStart, idEnd - idStart); SkSVGElement* found; if (strncmp(id.c_str(), "mask", 4) != 0) { bool itsFound = parser.fIDs.find(id.c_str(), &found); SkASSERT(itsFound); SkASSERT(found->getType() == SkSVGType_LinearGradient || found->getType() == SkSVGType_RadialGradient); } parser._addAttribute("shader", id.c_str()); } break; case kStroke_Dasharray: break; case kStroke_Linecap: parser._addAttributeLen("strokeCap", attrValue, attrLength); break; case kStroke_Linejoin: parser._addAttributeLen("strokeJoin", attrValue, attrLength); break; case kStroke_Miterlimit: parser._addAttributeLen("strokeMiter", attrValue, attrLength); break; case kStroke_Width: parser._addAttributeLen("strokeWidth", attrValue, attrLength); case kStyle: case kTransform: break; default: SkASSERT(0); return false; } } return true; }
bool SkSVGPaint::writeChangedElements(SkSVGParser& parser, SkSVGPaint& current, bool* changed) { SkSVGPaint& lastState = parser.fLastFlush; for (int index = kInitial + 1; index < kTerminal; index++) { SkString* topAttr = current[index]; size_t attrLength = topAttr->size(); if (attrLength == 0) continue; const char* attrValue = topAttr->c_str(); SkString* lastAttr = lastState[index]; switch(index) { case kClipPath: case kClipRule: // !!! need to add this outside of paint break; case kEnableBackground: // !!! don't know what to do with this break; case kFill: goto addColor; case kFillRule: case kFilter: break; case kFontFamily: parser._startElement("typeface"); parser._addAttributeLen("fontName", attrValue, attrLength); parser._endElement(); // typeface break; case kFontSize: case kLetterSpacing: break; case kMask: case kOpacity: if (changed[kStroke] == false && changed[kFill] == false) { parser._startElement("color"); SkString& opacity = current.f_opacity; parser._addAttributeLen("color", parser.fLastColor.c_str(), parser.fLastColor.size()); parser._addAttributeLen("alpha", opacity.c_str(), opacity.size()); parser._endElement(); // color } break; case kStopColor: break; case kStopOpacity: break; case kStroke: addColor: if (strncmp(lastAttr->c_str(), "url(", 4) == 0 && strncmp(attrValue, "url(", 4) != 0) { parser._startElement("shader"); parser._endElement(); } if (topAttr->equals(*lastAttr)) continue; { bool urlRef = strncmp(attrValue, "url(", 4) == 0; bool colorNone = strcmp(attrValue, "none") == 0; bool lastEqual = parser.fLastColor.equals(attrValue, attrLength); bool newColor = urlRef == false && colorNone == false && lastEqual == false; if (newColor || changed[kOpacity]) { parser._startElement("color"); if (newColor || changed[kOpacity]) { parser._addAttributeLen("color", attrValue, attrLength); parser.fLastColor.set(attrValue, attrLength); } if (changed[kOpacity]) { SkString& opacity = current.f_opacity; parser._addAttributeLen("alpha", opacity.c_str(), opacity.size()); } parser._endElement(); // color } } break; case kStroke_Dasharray: parser._startElement("dash"); SkSVGParser::ConvertToArray(*topAttr); parser._addAttribute("intervals", topAttr->c_str()); parser._endElement(); // dash break; case kStroke_Linecap: case kStroke_Linejoin: case kStroke_Miterlimit: case kStroke_Width: case kStyle: case kTransform: break; default: SkASSERT(0); return false; } } return true; }
void SkSVGPaint::setSave(SkSVGParser& parser) { SkTDArray<SkString*> clips; SkSVGPaint* walking = parser.fHead; int index; SkMatrix sum; sum.reset(); while (walking != NULL) { for (index = kInitial + 1; index < kTerminal; index++) { SkString* lastAttr = (*walking)[index]; if (lastAttr->size() == 0) continue; if (index == kTransform) { const char* str = lastAttr->c_str(); SkASSERT(strncmp(str, "matrix(", 7) == 0); str += 6; const char* strEnd = strrchr(str, ')'); SkASSERT(strEnd != NULL); SkString mat(str, strEnd - str); SkSVGParser::ConvertToArray(mat); SkScalar values[6]; SkParse::FindScalars(mat.c_str() + 1, values, 6); SkMatrix matrix; matrix.reset(); matrix.setScaleX(values[0]); matrix.setSkewY(values[1]); matrix.setSkewX(values[2]); matrix.setScaleY(values[3]); matrix.setTranslateX(values[4]); matrix.setTranslateY(values[5]); sum.setConcat(matrix, sum); continue; } if ( index == kClipPath) *clips.insert(0) = lastAttr; } walking = walking->fNext; } if ((sum == parser.fLastTransform) == false) { SkMatrix inverse; bool success = parser.fLastTransform.invert(&inverse); SkASSERT(success == true); SkMatrix output; output.setConcat(inverse, sum); parser.fLastTransform = sum; SkString outputStr; outputStr.appendUnichar('['); outputStr.appendScalar(output.getScaleX()); outputStr.appendUnichar(','); outputStr.appendScalar(output.getSkewX()); outputStr.appendUnichar(','); outputStr.appendScalar(output.getTranslateX()); outputStr.appendUnichar(','); outputStr.appendScalar(output.getSkewY()); outputStr.appendUnichar(','); outputStr.appendScalar(output.getScaleY()); outputStr.appendUnichar(','); outputStr.appendScalar(output.getTranslateY()); outputStr.appendUnichar(','); outputStr.appendScalar(output.getPerspX()); outputStr.appendUnichar(','); outputStr.appendScalar(output.getPerspY()); outputStr.append(",1]"); parser._startElement("matrix"); parser._addAttributeLen("matrix", outputStr.c_str(), outputStr.size()); parser._endElement(); } #if 0 // incomplete if (parser.fTransformClips.size() > 0) { // need to reset the clip when the 'g' scope is ended parser._startElement("add"); const char* start = strchr(current->f_clipPath.c_str(), '#') + 1; SkASSERT(start); parser._addAttributeLen("use", start, strlen(start) - 1); parser._endElement(); // clip } #endif }
bool SkSVGPaint::flush(SkSVGParser& parser, bool isFlushable, bool isDef) { SkSVGPaint current; SkSVGPaint* walking = parser.fHead; int index; while (walking != NULL) { for (index = kInitial + 1; index < kTerminal; index++) { SkString* lastAttr = (*walking)[index]; if (lastAttr->size() == 0) continue; if (current[index]->size() > 0) continue; current[index]->set(*lastAttr); } walking = walking->fNext; } bool paintChanged = false; SkSVGPaint& lastState = parser.fLastFlush; if (isFlushable == false) { if (isDef == true) { if (current.f_mask.size() > 0 && current.f_mask.equals(lastState.f_mask) == false) { SkSVGElement* found; const char* idStart = strchr(current.f_mask.c_str(), '#'); SkASSERT(idStart); SkString id(idStart + 1, strlen(idStart) - 2); bool itsFound = parser.fIDs.find(id.c_str(), &found); SkASSERT(itsFound); SkSVGElement* gradient = found->getGradient(); if (gradient) { gradient->write(parser, current.f_fill); gradient->write(parser, current.f_stroke); } } } goto setLast; } { bool changed[kTerminal]; memset(changed, 0, sizeof(changed)); for (index = kInitial + 1; index < kTerminal; index++) { if (index == kTransform || index == kClipPath || index == kStopColor || index == kStopOpacity || index == kClipRule || index == kFillRule) continue; SkString* lastAttr = lastState[index]; SkString* currentAttr = current[index]; paintChanged |= changed[index] = lastAttr->equals(*currentAttr) == false; } if (paintChanged) { if (current.f_mask.size() > 0) { if (current.f_fill.equals("none") == false && strncmp(current.f_fill.c_str(), "url(#", 5) != 0) { SkASSERT(current.f_fill.c_str()[0] == '#'); SkString replacement("url(#mask"); replacement.append(current.f_fill.c_str() + 1); replacement.appendUnichar(')'); current.f_fill.set(replacement); } if (current.f_stroke.equals("none") == false && strncmp(current.f_stroke.c_str(), "url(#", 5) != 0) { SkASSERT(current.f_stroke.c_str()[0] == '#'); SkString replacement("url(#mask"); replacement.append(current.f_stroke.c_str() + 1); replacement.appendUnichar(')'); current.f_stroke.set(replacement); } } if (current.f_fill.equals("none") && current.f_stroke.equals("none")) current.f_opacity.set("0"); if (parser.fSuppressPaint == false) { parser._startElement("paint"); bool success = writeChangedAttributes(parser, current, changed); if (success == false) return paintChanged; success = writeChangedElements(parser, current, changed); if (success == false) return paintChanged; parser._endElement(); // paint } } } setLast: for (index = kInitial + 1; index < kTerminal; index++) { SkString* lastAttr = lastState[index]; SkString* currentAttr = current[index]; lastAttr->set(*currentAttr); } return paintChanged; }
static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x, SkScalar y, const SkFont& font) { SkPaint paint; canvas->drawString(text, x, y, font, paint); return x + font.measureText(text.c_str(), text.size(), SkTextEncoding::kUTF8); }
bool SkWStream::writeScalarAsText(SkScalar value) { SkString tmp; tmp.appendScalar(value); return this->write(tmp.c_str(), tmp.size()); }
void onDraw(SkCanvas* canvas) override { if (!fImage) { this->setupImage(canvas); } SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2); static const int kPadX = 30; static const int kPadY = 40; SkPaint paint; paint.setAlpha(0x20); canvas->drawBitmapRect(fLargeBitmap, SkRect::MakeIWH(gSize, gSize), &paint); canvas->translate(SK_Scalar1 * kPadX / 2, SK_Scalar1 * kPadY / 2); SkPaint blackPaint; SkScalar titleHeight = SK_Scalar1 * 24; blackPaint.setColor(SK_ColorBLACK); blackPaint.setTextSize(titleHeight); blackPaint.setAntiAlias(true); sk_tool_utils::set_portable_typeface(&blackPaint); SkString title; title.printf("Bitmap size: %d x %d", gBmpSize, gBmpSize); canvas->drawText(title.c_str(), title.size(), 0, titleHeight, blackPaint); canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); int rowCount = 0; canvas->save(); for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSize - h) / 2, w, h); fProc(canvas, fImage.get(), fLargeBitmap, srcRect, dstRect); SkString label; label.appendf("%d x %d", w, h); blackPaint.setAntiAlias(true); blackPaint.setStyle(SkPaint::kFill_Style); blackPaint.setTextSize(SK_Scalar1 * 10); SkScalar baseline = dstRect.height() + blackPaint.getTextSize() + SK_Scalar1 * 3; canvas->drawText(label.c_str(), label.size(), 0, baseline, blackPaint); blackPaint.setStyle(SkPaint::kStroke_Style); blackPaint.setStrokeWidth(SK_Scalar1); blackPaint.setAntiAlias(false); canvas->drawRect(dstRect, blackPaint); canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0); ++rowCount; if ((dstRect.width() + kPadX) * rowCount > gSize) { canvas->restore(); canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY); canvas->save(); rowCount = 0; } } } { // test the following code path: // SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter() SkIRect srcRect; SkPaint paint; SkBitmap bm; bm = make_chessbm(5, 5); paint.setFilterQuality(kLow_SkFilterQuality); srcRect.setXYWH(1, 1, 3, 3); SkMaskFilter* mf = SkBlurMaskFilter::Create( kNormal_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), SkBlurMaskFilter::kHighQuality_BlurFlag | SkBlurMaskFilter::kIgnoreTransform_BlurFlag); paint.setMaskFilter(mf)->unref(); canvas->drawBitmapRect(bm, srcRect, dstRect, &paint); } }
NULL)); SIMPLE_TEST_STEP(DrawBitmapRectSrcRect, drawBitmapRect(kTestBitmap, &kTestIRect, kTestRect, NULL)); SIMPLE_TEST_STEP(DrawBitmapRectPaint, drawBitmapRect(kTestBitmap, NULL, kTestRect, &kTestPaint)); SIMPLE_TEST_STEP(DrawBitmapMatrix, drawBitmapMatrix(kTestBitmap, kTestMatrix, NULL)); SIMPLE_TEST_STEP(DrawBitmapMatrixPaint, drawBitmapMatrix(kTestBitmap, kTestMatrix, &kTestPaint)); SIMPLE_TEST_STEP(DrawBitmapNine, drawBitmapNine(kTestBitmap, kTestIRect, kTestRect, NULL)); SIMPLE_TEST_STEP(DrawBitmapNinePaint, drawBitmapNine(kTestBitmap, kTestIRect, kTestRect, &kTestPaint)); SIMPLE_TEST_STEP(DrawSprite, drawSprite(kTestBitmap, 0, 0, NULL)); SIMPLE_TEST_STEP(DrawSpritePaint, drawSprite(kTestBitmap, 0, 0, &kTestPaint)); SIMPLE_TEST_STEP(DrawText, drawText(kTestText.c_str(), kTestText.size(), 0, 1, kTestPaint)); SIMPLE_TEST_STEP(DrawPosText, drawPosText(kTestText.c_str(), kTestText.size(), kTestPoints2, kTestPaint)); SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(kTestText.c_str(), kTestText.size(), kTestPath, NULL, kTestPaint)); SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(), kTestText.size(), kTestPath, &kTestMatrix, kTestPaint)); SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size())); SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(kTestText.c_str())); SIMPLE_TEST_STEP(AddComment, addComment(kTestText.c_str(), kTestText.c_str())); SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); /////////////////////////////////////////////////////////////////////////////// // Complex test steps
virtual void onDraw(SkCanvas* canvas) { SkRect r = { 0, 0, SkIntToScalar(gWidth*2), SkIntToScalar(gHeight*2) }; static const char* gConfigNames[] = { "8888", "565", "4444" }; static const bool gFilters[] = { false, true }; static const char* gFilterNames[] = { "point", "bilinear" }; static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; static const char* gModeNames[] = { "C", "R", "M" }; SkScalar y = SkIntToScalar(24); SkScalar x = SkIntToScalar(10); for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { SkPaint p; SkString str; p.setAntiAlias(true); p.setDither(true); p.setLooper(&fLooper); str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); p.setTextAlign(SkPaint::kCenter_Align); canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); x += r.width() * 4 / 3; } } y += SkIntToScalar(16); for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) { x = SkIntToScalar(10); for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { SkPaint paint; setup(&paint, fTexture[i], gFilters[j], gModes[kx], gModes[ky]); paint.setDither(true); canvas->save(); canvas->translate(x, y); canvas->drawRect(r, paint); canvas->restore(); x += r.width() * 4 / 3; } } { SkPaint p; SkString str; p.setAntiAlias(true); p.setLooper(&fLooper); str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); canvas->drawText(str.c_str(), str.size(), x, y + r.height() * 2 / 3, p); } y += r.height() * 4 / 3; } } }
static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x, SkScalar y, const SkPaint& paint) { canvas->drawText(text.c_str(), text.size(), x, y, paint); return x + paint.measureText(text.c_str(), text.size()); }
SkEvent::SkEvent(const SkString& type) { initialize(type.c_str(), type.size()); }
static bool eq(const SkString& str, const char* strPtr, size_t len) { return len == str.size() && 0 == memcmp(str.c_str(), strPtr, len); }
void SkStaticTextView::setText(const SkString& text) { this->setText(text.c_str(), text.size()); }
bool SkWStream::writeHexAsText(uint32_t hex, int digits) { SkString tmp; tmp.appendHex(hex, digits); return this->write(tmp.c_str(), tmp.size()); }
void onDraw(SkCanvas* canvas) override { int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; static const char* gConfigNames[] = { "8888", "565", "4444" }; static const bool gFilters[] = { false, true }; static const char* gFilterNames[] = { "point", "bilinear" }; static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; static const char* gModeNames[] = { "C", "R", "M" }; SkScalar y = SkIntToScalar(24); SkScalar x = SkIntToScalar(10); for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { SkPaint p; SkString str; p.setAntiAlias(true); sk_tool_utils::set_portable_typeface_always(&p); p.setDither(true); str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); p.setTextAlign(SkPaint::kCenter_Align); canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p); x += r.width() * 4 / 3; } } y += SkIntToScalar(16); for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) { for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) { x = SkIntToScalar(10); for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { SkPaint paint; #if 1 // Temporary change to regen bitmap before each draw. This may help tracking down an issue // on SGX where resizing NPOT textures to POT textures exhibits a driver bug. if (!fPowerOfTwoSize) { makebm(&fTexture[i], gColorTypes[i], size, size); } #endif setup(&paint, fTexture[i], gFilters[j], gModes[kx], gModes[ky]); paint.setDither(true); canvas->save(); canvas->translate(x, y); canvas->drawRect(r, paint); canvas->restore(); x += r.width() * 4 / 3; } } { SkPaint p; SkString str; p.setAntiAlias(true); sk_tool_utils::set_portable_typeface_always(&p); str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); canvas->drawText(str.c_str(), str.size(), x, y + r.height() * 2 / 3, p); } y += r.height() * 4 / 3; } } }
static SkString make_png_name(const char* filename) { SkString pngName = SkString(filename); pngName.remove(pngName.size() - 3, 3); pngName.append("png"); return pngName; }
bool SkWStream::writeDecAsText(int32_t dec) { SkString tmp; tmp.appendS32(dec); return this->write(tmp.c_str(), tmp.size()); }
DEF_TEST(SkpSkGrThreaded, reporter) { if (!initTest()) { return; } SkpSkGrThreadedTestRunner testRunner(reporter); for (int dirIndex = 1; dirIndex <= 100; ++dirIndex) { SkString pictDir = make_in_dir_name(dirIndex); if (pictDir.size() == 0) { continue; } SkOSFile::Iter iter(pictDir.c_str(), "skp"); SkString filename; while (iter.next(&filename)) { SkString pngName = make_png_name(filename.c_str()); SkString oldPng = make_filepath(dirIndex, outSkDir, pngName.c_str()); SkString newPng = make_filepath(dirIndex, outGrDir, pngName.c_str()); if (sk_exists(oldPng.c_str()) && sk_exists(newPng.c_str())) { bumpCount(reporter, true); continue; } for (size_t index = 0; index < skipOverSkGrCount; ++index) { if (skipOverSkGr[index].directory == dirIndex && strcmp(filename.c_str(), skipOverSkGr[index].filename) == 0) { bumpCount(reporter, true); goto skipOver; } } *testRunner.fRunnables.append() = new SkpSkGrThreadedRunnable( &testSkGrMain, dirIndex, filename.c_str(), &testRunner); skipOver: ; } } testRunner.render(); SkpSkGrThreadState& max = testRunner.fRunnables[0]->fState; for (int dirIndex = 2; dirIndex <= 100; ++dirIndex) { SkpSkGrThreadState& state = testRunner.fRunnables[dirIndex - 1]->fState; for (int index = 0; index < state.fFoundCount; ++index) { int maxIdx = max.fFoundCount; if (maxIdx < kMaxFiles) { max.fError[maxIdx] = state.fError[index]; strcpy(max.fFilesFound[maxIdx], state.fFilesFound[index]); max.fDirsFound[maxIdx] = state.fDirsFound[index]; ++max.fFoundCount; continue; } for (maxIdx = 0; maxIdx < max.fFoundCount; ++maxIdx) { if (max.fError[maxIdx] < state.fError[index]) { max.fError[maxIdx] = state.fError[index]; strcpy(max.fFilesFound[maxIdx], state.fFilesFound[index]); max.fDirsFound[maxIdx] = state.fDirsFound[index]; break; } } } } TestResult encoder; encoder.fTestStep = kEncodeFiles; for (int index = 0; index < max.fFoundCount; ++index) { encoder.fDirNo = max.fDirsFound[index]; strcpy(encoder.fFilename, max.fFilesFound[index]); encoder.testOne(); SkDebugf("+"); } }
SkString prettify(const SkString& input, bool countlines) { // setup pretty state fIndex = 0; fLength = input.size(); fInput = input; fCountlines = countlines; fTabs = 0; fLinecount = 1; fFreshline = true; int parensDepth = 0; // number 1st line this->lineNumbering(); while (fLength > fIndex) { /* the heart and soul of our prettification algorithm. The rules should hopefully be * self explanatory. For '#' and '//' tokens we parse until we reach a newline. * * For long style comments like this one, we search for the ending token. We also * preserve whitespace in these comments WITH THE CAVEAT that we do the newlines * ourselves. This allows us to remain in control of line numbers, and matching tabs * Existing tabs in the input string are copied over too, but this will look funny * * '{' and '}' are handled in basically the same way. We add a newline if we aren't * on a fresh line, dirty the line, then add a second newline, ie braces are always * on their own lines indented properly. The one funkiness here is structs print with * the semicolon on its own line. Its not a problem for a glsl compiler though * * '(' and ')' are basically ignored, except as a sign we need to ignore ';' ala * in for loops. * * ';' means add a new line * * '\t' and '\n' are ignored in general parsing for backwards compatability with * existing shader code and we also have a special case for handling whitespace * at the beginning of fresh lines. * * Otherwise just add the new character to the pretty string, indenting if necessary. */ if (this->hasToken("#") || this->hasToken("//")) { this->parseUntilNewline(); } else if (this->hasToken("/*")) { this->parseUntil("*/"); } else if ('{' == fInput[fIndex]) { this->newline(); this->appendChar('{'); fTabs++; this->newline(); } else if ('}' == fInput[fIndex]) { fTabs--; this->newline(); this->appendChar('}'); this->newline(); } else if (this->hasToken(")")) { parensDepth--; } else if (this->hasToken("(")) { parensDepth++; } else if (!parensDepth && this->hasToken(";")) { this->newline(); } else if ('\t' == fInput[fIndex] || '\n' == fInput[fIndex] || (fFreshline && ' ' == fInput[fIndex])) { fIndex++; } else { this->appendChar(input[fIndex]); } } return fPretty; }