Esempio n. 1
0
void SampleWindow::updateTitle() {
    SkString title;

    SkView::F2BIter iter(this);
    SkView* view = iter.next();
    SkEvent evt(gTitleEvtName);
    if (view->doQuery(&evt)) {
        title.set(evt.findString(gTitleEvtName));
    }
    if (title.size() == 0) {
        title.set("<unknown>");
    }

    title.prepend(gCanvasTypePrefix[fCanvasType]);

    title.prepend(" ");
    title.prepend(configToString(this->getBitmap().config()));

    if (fAnimating) {
        title.prepend("<A> ");
    }
    if (fScale) {
        title.prepend("<S> ");
    }
    if (fRotate) {
        title.prepend("<R> ");
    }
    if (fNClip) {
        title.prepend("<C> ");
    }
    this->setTitle(title.c_str());
}
 SkString BaseName() override {
     SkString name;
     if (fInfo.gammaCloseToSRGB()) {
         name.set("sRGB");
     } else {
         name.set("Linr");
     }
     return name;
 }
Esempio n. 3
0
/**
 *  Set up the name for writing encoded data to a file.
 *  Sets gInputFileName to name, minus any extension ".*"
 *  Sets gImageNo to 0, so images from file "X.skp" will
 *  look like "X_<gImageNo>.<suffix>", beginning with 0
 *  for each new skp.
 */
static void reset_image_file_base_name(const SkString& name) {
    gImageNo = 0;
    // Remove ".skp"
    const char* cName = name.c_str();
    const char* dot = strrchr(cName, '.');
    if (dot != NULL) {
        gInputFileName.set(cName, dot - cName);
    } else {
        gInputFileName.set(name);
    }
}
Esempio n. 4
0
    TextBench(void* param, const char text[], int ps,
              SkColor color, FontQuality fq, bool doPos = false) : INHERITED(param) {
        fPos = NULL;
        fFQ = fq;
        fDoPos = doPos;
        fText.set(text);

        fPaint.setAntiAlias(kBW != fq);
        fPaint.setLCDRenderText(kLCD == fq);
        fPaint.setTextSize(SkIntToScalar(ps));
        fPaint.setColor(color);

        if (doPos) {
            size_t len = strlen(text);
            SkScalar* adv = new SkScalar[len];
            fPaint.getTextWidths(text, len, adv);
            fPos = new SkPoint[len];
            SkScalar x = 0;
            for (size_t i = 0; i < len; ++i) {
                fPos[i].set(x, SkIntToScalar(50));
                x += adv[i];
            }
            delete[] adv;
        }
    }
Esempio n. 5
0
    VertBench() {
        const SkScalar dx = SkIntToScalar(W) / COL;
        const SkScalar dy = SkIntToScalar(H) / COL;

        SkPoint* pts = fPts;
        uint16_t* idx = fIdx;

        SkScalar yy = 0;
        for (int y = 0; y <= ROW; y++) {
            SkScalar xx = 0;
            for (int x = 0; x <= COL; ++x) {
                pts->set(xx, yy);
                pts += 1;
                xx += dx;

                if (x < COL && y < ROW) {
                    load_2_tris(idx, x, y, COL + 1);
                    for (int i = 0; i < 6; i++) {
                        SkASSERT(idx[i] < PTS);
                    }
                    idx += 6;
                }
            }
            yy += dy;
        }
        SkASSERT(PTS == pts - fPts);
        SkASSERT(IDX == idx - fIdx);

        SkRandom rand;
        for (int i = 0; i < PTS; ++i) {
            fColors[i] = rand.nextU() | (0xFF << 24);
        }

        fName.set("verts");
    }
Esempio n. 6
0
int tool_main(int argc, char** argv) {
    SkCommandLineFlags::SetUsage("Parse and Render .pdf files (pdf viewer).");
    SkCommandLineFlags::Parse(argc, argv);

    if (FLAGS_readPath.isEmpty()) {
        SkDebugf(".pdf files or directories are required.\n");
        exit(-1);
    }

    SkString outputDir;
    if (FLAGS_writePath.count() == 1) {
        outputDir.set(FLAGS_writePath[0]);
    }

    int failures = 0;
    for (int i = 0; i < FLAGS_readPath.count(); i ++) {
        failures += process_input(FLAGS_readPath[i], outputDir);
    }

    reportPdfRenderStats();

    if (failures != 0) {
        SkDebugf("Failed to render %i PDFs.\n", failures);
        return 1;
    }

    return 0;
}
Esempio n. 7
0
void SkDisplayEvent::dumpEvent(SkAnimateMaker* maker) {
    dumpBase(maker);
    SkString str;
    SkDump::GetEnumString(SkType_EventKind, kind, &str);
    SkDebugf("kind=\"%s\" ", str.c_str());
    if (kind == SkDisplayEvent::kKeyPress || kind == SkDisplayEvent::kKeyPressUp) {
        if (code >= 0)
            SkDump::GetEnumString(SkType_EventCode, code, &str);
        else
            str.set("none");
        SkDebugf("code=\"%s\" ", str.c_str());
    }
    if (kind == SkDisplayEvent::kKeyChar) {
        if (fMax != (SkKey) -1 && fMax != code)
            SkDebugf("keys=\"%c - %c\" ", code, fMax);
        else
            SkDebugf("key=\"%c\" ", code);
    }
    if (fTarget != NULL) {
        SkDebugf("target=\"%s\" ", fTarget->id);
    }
    if (kind >= SkDisplayEvent::kMouseDown && kind <= SkDisplayEvent::kMouseUp) {
        SkDebugf("x=\"%g\" y=\"%g\" ", SkScalarToFloat(x), SkScalarToFloat(y));
    }
    if (disable)
        SkDebugf("disable=\"true\" ");
    SkDebugf("/>\n");
}
/**
 * Use the current system locale (language and region) to open the best matching
 * customization. For example, when the language is Japanese, the sequence might be:
 *      /system/etc/fallback_fonts-ja-JP.xml
 *      /system/etc/fallback_fonts-ja.xml
 *      /system/etc/fallback_fonts.xml
 */
FILE* openLocalizedFile(const char* origname) {
    FILE* file = 0;

#if !defined(SK_BUILD_FOR_ANDROID_NDK)
    SkString basename;
    SkString filename;
    char language[3] = "";
    char region[3] = "";

    basename.set(origname);
    // Remove the .xml suffix. We'll add it back in a moment.
    if (basename.endsWith(".xml")) {
        basename.resize(basename.size()-4);
    }
    getLocale(language, region);
    // Try first with language and region
    filename.printf("%s-%s-%s.xml", basename.c_str(), language, region);
    file = fopen(filename.c_str(), "r");
    if (!file) {
        // If not found, try next with just language
        filename.printf("%s-%s.xml", basename.c_str(), language);
        file = fopen(filename.c_str(), "r");
    }
#endif

    if (!file) {
        // If still not found, try just the original name
        file = fopen(origname, "r");
    }
    return file;
}
Esempio n. 9
0
void
SkFontData::deleteFiles()
{
    SkString delCmdFiles;
    delCmdFiles.set( "rm " );
    delCmdFiles.append( SYSTEM_DL_FONTAPP_DST_DIR );
    delCmdFiles.append( mFontAppName );
    delCmdFiles.append( "/*" );
    system( delCmdFiles.c_str() );

    SkString delCmdDir;
    delCmdDir.set( "rmdir " );
    delCmdDir.append( SYSTEM_DL_FONTAPP_DST_DIR );
    delCmdDir.append( mFontAppName );
    system( delCmdDir.c_str() );
}
/**
 * This function parses the given filename and stores the results in the given
 * families array.
 */
static void parseConfigFile(const char *filename, SkTDArray<FontFamily*> &families) {

    FILE* file = NULL;

#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
    // if we are using a version of Android prior to Android 4.2 (JellyBean MR1
    // at API Level 17) then we need to look for files with a different suffix.
    char sdkVersion[PROP_VALUE_MAX];
    __system_property_get("ro.build.version.sdk", sdkVersion);
    const int sdkVersionInt = atoi(sdkVersion);

    if (0 != *sdkVersion && sdkVersionInt < 17) {
        SkString basename;
        SkString updatedFilename;
        SkString locale = SkFontConfigParser::GetLocale();

        basename.set(filename);
        // Remove the .xml suffix. We'll add it back in a moment.
        if (basename.endsWith(".xml")) {
            basename.resize(basename.size()-4);
        }
        // Try first with language and region
        updatedFilename.printf("%s-%s.xml", basename.c_str(), locale.c_str());
        file = fopen(updatedFilename.c_str(), "r");
        if (!file) {
            // If not found, try next with just language
            updatedFilename.printf("%s-%.2s.xml", basename.c_str(), locale.c_str());
            file = fopen(updatedFilename.c_str(), "r");
        }
    }
#endif

    if (NULL == file) {
        file = fopen(filename, "r");
    }

    // Some of the files we attempt to parse (in particular, /vendor/etc/fallback_fonts.xml)
    // are optional - failure here is okay because one of these optional files may not exist.
    if (NULL == file) {
        return;
    }

    XML_Parser parser = XML_ParserCreate(NULL);
    FamilyData *familyData = new FamilyData(&parser, families);
    XML_SetUserData(parser, familyData);
    XML_SetElementHandler(parser, startElementHandler, endElementHandler);

    char buffer[512];
    bool done = false;
    while (!done) {
        fgets(buffer, sizeof(buffer), file);
        int len = strlen(buffer);
        if (feof(file) != 0) {
            done = true;
        }
        XML_Parse(parser, buffer, len, done);
    }
    XML_ParserFree(parser);
    fclose(file);
}
/**
 * Use the current system locale (language and region) to open the best matching
 * customization. For example, when the language is Japanese, the sequence might be:
 *      /system/etc/fallback_fonts-ja-JP.xml
 *      /system/etc/fallback_fonts-ja.xml
 *      /system/etc/fallback_fonts.xml
 */
FILE* openLocalizedFile(const char* origname) {
    FILE* file = 0;
    SkString basename;
    SkString filename;
    AndroidLocale locale;

    basename.set(origname);
    // Remove the .xml suffix. We'll add it back in a moment.
    if (basename.endsWith(".xml")) {
        basename.resize(basename.size()-4);
    }
    getLocale(locale);
    // Try first with language and region
    filename.printf("%s-%s-%s.xml", basename.c_str(), locale.language, locale.region);
    file = fopen(filename.c_str(), "r");
    if (!file) {
        // If not found, try next with just language
        filename.printf("%s-%s.xml", basename.c_str(), locale.language);
        file = fopen(filename.c_str(), "r");

        if (!file) {
            // If still not found, try just the original name
            file = fopen(origname, "r");
        }
    }
    return file;
}
Esempio n. 12
0
    ShaderMaskBench(bool isOpaque, FontQuality fq)  {
        fFQ = fq;
        fText.set(STR);

        fPaint.setAntiAlias(kBW != fq);
        fPaint.setLCDRenderText(kLCD == fq);
        fPaint.setShader(SkShader::MakeColorShader(isOpaque ? 0xFFFFFFFF : 0x80808080));
    }
Esempio n. 13
0
void
SkFontManager::setPermission( SkFontData * src )
{
    SkString path;
    SkString file;

    path.set( SYSTEM_FONT_PERMISSION_SET );
    path.append( SYSTEM_DL_FONTAPP_DST_DIR );
    path.append( src->getFontAppName() );

    file.set( SYSTEM_FONT_PERMISSION_SET );
    file.append( SYSTEM_DL_FONTAPP_DST_DIR );
    file.append( src->getFontAppName() );
    file.append( "/*" );

    system( path.c_str() );
    system( file.c_str() );
}
    ShaderMaskBench(void* param, bool isOpaque, FontQuality fq) : INHERITED(param) {
        fFQ = fq;
        fText.set(STR);

        fPaint.setAntiAlias(kBW != fq);
        fPaint.setLCDRenderText(kLCD == fq);
        fPaint.setAlpha(isOpaque ? 0xFF : 0x80);
        fPaint.setShader(new SkColorShader)->unref();
    }
Esempio n. 15
0
 TalkGM(int index, bool showGL, int flags = 0) {
     fProc = gRec[index].fProc;
     fName.set(gRec[index].fName);
     if (showGL) {
         fName.append("-gl");
     }
     fShowGL = showGL;
     fFlags = flags;
 }
/**
 * This function is the sink to which all work ends up going.
 * Renders the picture into the renderer. It may or may not use an RTree.
 * The renderer is chosen upstream. If we want to measure recording, we will
 * use a RecordPictureRenderer. If we want to measure rendering, we eill use a
 * TiledPictureRenderer.
 */
static void do_benchmark_work(sk_tools::PictureRenderer* renderer,
        int benchmarkType, const SkString& path, SkPicture* pic,
        const int numRepeats, const char *msg, BenchTimer* timer) {
    SkString msgPrefix;

    switch (benchmarkType){
        case kNormal_BenchmarkType:
            msgPrefix.set("Normal");
            renderer->setBBoxHierarchyType(sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
            break;
        case kRTree_BenchmarkType:
            msgPrefix.set("RTree");
            renderer->setBBoxHierarchyType(sk_tools::PictureRenderer::kRTree_BBoxHierarchyType);
            break;
        default:
            SkASSERT(0);
            break;
    }

    renderer->init(pic);

    /**
     * If the renderer is not tiled, assume we are measuring recording.
     */
    bool isPlayback = (NULL != renderer->getTiledRenderer());

    SkDebugf("%s %s %s %d times...\n", msgPrefix.c_str(), msg, path.c_str(), numRepeats);
    for (int i = 0; i < numRepeats; ++i) {
        renderer->setup();
        // Render once to fill caches.
        renderer->render(NULL);
        // Render again to measure
        timer->start();
        bool result = renderer->render(NULL);
        timer->end();
        // We only care about a false result on playback. RecordPictureRenderer::render will always
        // return false because we are passing a NULL file name on purpose; which is fine.
        if(isPlayback && !result) {
            SkDebugf("Error rendering during playback.\n");
        }
    }
    renderer->end();
}
template<typename T> bool SkRTConfRegistry::parse(const char *name, T* value) {
    SkString *str = NULL;

    for (int i = fConfigFileKeys.count() - 1 ; i >= 0; i--) {
        if (fConfigFileKeys[i]->equals(name)) {
            str = fConfigFileValues[i];
            break;
        }
    }

    SkString environment_variable("skia.");
    environment_variable.append(name);

    const char *environment_value = getenv(environment_variable.c_str());
    if (environment_value) {
        str->set(environment_value);
    } else {
        // apparently my shell doesn't let me have environment variables that
        // have periods in them, so also let the user substitute underscores.
        SkString underscore_environment_variable("skia_");
        char *underscore_name = SkStrDup(name);
        str_replace(underscore_name,'.','_');
        underscore_environment_variable.append(underscore_name);
        sk_free(underscore_name);
        environment_value = getenv(underscore_environment_variable.c_str());
        if (environment_value) {
            str->set(environment_value);
        }
    }

    if (!str) {
        return false;
    }

    bool success;
    T new_value = doParse<T>(str->c_str(),&success);
    if (success) {
        *value = new_value;
    } else {
        SkDebugf("WARNING: Couldn't parse value \'%s\' for variable \'%s\'\n", str->c_str(), name);
    }
    return success;
}
Esempio n. 18
0
    virtual const char* onGetName() {
        fFullName.set(INHERITED::onGetName());
        if (fScale)
            fFullName.append("_scale");
        if (fRotate)
            fFullName.append("_rotate");
        if (fFilter)
            fFullName.append("_filter");

        return fFullName.c_str();
    }
void SkXMLParserError::getErrorString(SkString* str) const
{
    SkASSERT(str);
    SkString temp;
    if (fCode != kNoError) {
        if ((unsigned)fCode < SK_ARRAY_COUNT(gErrorStrings))
            temp.set(gErrorStrings[fCode - 1]);
        temp.append(fNoun);
    } else
        SkXMLParser::GetNativeErrorString(fNativeCode, &temp);
    str->append(temp);
}
Esempio n. 20
0
/**
 *  Helper function to write a bitmap subset to a file. Only called if subsets were created
 *  and a writePath was provided. Behaves differently depending on
 *  FLAGS_writeChecksumBasedFilenames. If true:
 *      Writes the image to a PNG file named according to the digest hash, as described in
 *      write_bitmap.
 *  If false:
 *      Creates a subdirectory called 'subsets' and writes a PNG to that directory. Also
 *      creates a subdirectory called 'extracted' and writes a bitmap created using
 *      extractSubset to a PNG in that directory. Both files will represent the same
 *      subrectangle and have the same name for convenient comparison. In this case, the
 *      digest is ignored.
 *
 *  @param writePath Parent directory to hold the folders for the PNG files to write. Must
 *      not be NULL.
 *  @param subsetName Basename of the original file, with the dimensions of the subset tacked
 *      on. Used to name the new file/folder.
 *  @param bitmapAndDigestFromDecodeSubset SkBitmap (with digest) created by
 *      SkImageDecoder::DecodeSubset, using rect as the area to decode.
 *  @param rect Rectangle of the area decoded into bitmapFromDecodeSubset. Used to call
 *      extractSubset on originalBitmap to create a bitmap with the same dimensions/pixels as
 *      bitmapFromDecodeSubset (assuming decodeSubset worked properly).
 *  @param originalBitmap SkBitmap decoded from the same stream as bitmapFromDecodeSubset,
 *      using SkImageDecoder::decode to get the entire image. Used to create a PNG file for
 *      comparison to the PNG created by bitmapAndDigestFromDecodeSubset's bitmap.
 *  @return bool Whether the function succeeded at drawing the decoded subset and the extracted
 *      subset to files.
 */
static bool write_subset(const char* writePath, const SkString& subsetName,
                         const skiagm::BitmapAndDigest bitmapAndDigestFromDecodeSubset,
                         SkIRect rect, const SkBitmap& originalBitmap) {
    // All parameters must be valid.
    SkASSERT(writePath != NULL);

    SkString subsetPath;
    if (FLAGS_writeChecksumBasedFilenames) {
        subsetPath.set(writePath);
    } else {
        // Create a subdirectory to hold the results of decodeSubset.
        subsetPath = SkOSPath::SkPathJoin(writePath, "subsets");
        if (!sk_mkdir(subsetPath.c_str())) {
            gFailedSubsetDecodes.push_back().printf("Successfully decoded subset %s, but "
                                                    "failed to create a directory to write to.",
                                                    subsetName.c_str());
            return false;
        }
    }
    SkAssertResult(write_bitmap(subsetPath.c_str(), subsetName.c_str(),
                                bitmapAndDigestFromDecodeSubset));
    gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", subsetName.c_str());

    if (!FLAGS_writeChecksumBasedFilenames) {
        // FIXME: The goal of extracting the subset is for visual comparison/using skdiff/skpdiff.
        // Currently disabling for writeChecksumBasedFilenames since it will be trickier to
        // determine which files to compare.

        // Also use extractSubset from the original for visual comparison.
        // Write the result to a file in a separate subdirectory.
        SkBitmap extractedSubset;
        if (!originalBitmap.extractSubset(&extractedSubset, rect)) {
            gFailedSubsetDecodes.push_back().printf("Successfully decoded subset %s, but failed "
                                                    "to extract a similar subset for comparison.",
                                                    subsetName.c_str());
            return false;
        }

        SkString dirExtracted = SkOSPath::SkPathJoin(writePath, "extracted");
        if (!sk_mkdir(dirExtracted.c_str())) {
            gFailedSubsetDecodes.push_back().printf("Successfully decoded subset%s, but failed "
                                                    "to create a directory for extractSubset "
                                                    "comparison.",
                                                    subsetName.c_str());
            return false;
        }

        skiagm::BitmapAndDigest bitmapAndDigestFromExtractSubset(extractedSubset);
        SkAssertResult(write_bitmap(dirExtracted.c_str(), subsetName.c_str(),
                                    bitmapAndDigestFromExtractSubset));
    }
    return true;
}
Esempio n. 21
0
    const char* onGetName() override {
        fFullName.set(INHERITED::onGetName());

        if (fSourceAlpha == kOpaque_SourceAlpha) {
                fFullName.append("_source_opaque");
        } else if (fSourceAlpha == kTransparent_SourceAlpha) {
                fFullName.append("_source_transparent");
        } else if (fSourceAlpha == kTwoStripes_SourceAlpha) {
                fFullName.append("_source_stripes_two");
        } else if (fSourceAlpha == kThreeStripes_SourceAlpha) {
                fFullName.append("_source_stripes_three");
        }

        return fFullName.c_str();
    }
Esempio n. 22
0
 const char* onGetName() override {
     SkString vertexMode;
     switch (fVertexMode) {
         case kNone_VertexMode:
             vertexMode.set("meshlines");
             break;
         case kColors_VertexMode:
             vertexMode.set("colors");
             break;
         case kTexCoords_VertexMode:
             vertexMode.set("texs");
             break;
         case kBoth_VertexMode:
             vertexMode.set("colors_texs");
             break;
         default:
             break;
     }
     SkString type;
     this->appendName(&type);
     fName.printf("patch_%s_%s_%fx%f", type.c_str(), vertexMode.c_str(),
                 fScale.x(), fScale.y());
     return fName.c_str();
 }
void SkSVGPaint::addAttribute(SkSVGParser& parser, int attrIndex,
        const char* attrValue, size_t attrLength) {
    SkString* attr = (*this)[attrIndex];
    switch(attrIndex) {
        case kClipPath:
        case kClipRule:
        case kEnableBackground:
        case kFill:
        case kFillRule:
        case kFilter:
        case kFontFamily:
        case kFontSize:
        case kLetterSpacing:
        case kMask:
        case kOpacity:
        case kStopColor:
        case kStopOpacity:
        case kStroke:
        case kStroke_Dasharray:
        case kStroke_Linecap:
        case kStroke_Linejoin:
        case kStroke_Miterlimit:
        case kStroke_Width:
        case kTransform:
            attr->set(attrValue, attrLength);
            return;
        case kStyle: {
            // iterate through colon / semi-colon delimited pairs
            int pairs = SkParse::Count(attrValue, ';');
            const char* attrEnd = attrValue + attrLength;
            do {
                const char* end = strchr(attrValue, ';');
                if (end == NULL)
                    end = attrEnd;
                const char* delimiter = strchr(attrValue, ':');
                SkASSERT(delimiter != 0 && delimiter < end);
                int index = parser.findAttribute(this, attrValue, (int) (delimiter - attrValue), true);
                SkASSERT(index >= 0);
                delimiter++;
                addAttribute(parser, index, delimiter, (int) (end - delimiter));
                attrValue = end + 1;
            } while (--pairs);
            return;
            }
        default:
            SkASSERT(0);
    }
}
Esempio n. 24
0
    const char* onGetName() override {
        fFullName.set(INHERITED::onGetName());
        if (fFlags & kScale_Flag) {
            fFullName.append("_scale");
        }
        if (fFlags & kRotate_Flag) {
            fFullName.append("_rotate");
        }
        if (isBilerp(fFlags)) {
            fFullName.append("_bilerp");
        } else if (isBicubic(fFlags)) {
            fFullName.append("_bicubic");
        }

        return fFullName.c_str();
    }
Esempio n. 25
0
static SkString get_common_prefix(const SkString& a, const SkString& b) {
    const size_t maxPrefixLength = SkTMin(a.size(), b.size());
    SkASSERT(maxPrefixLength > 0);
    for (size_t x = 0; x < maxPrefixLength; ++x) {
        if (a[x] != b[x]) {
            SkString result;
            result.set(a.c_str(), x);
            return result;
        }
    }
    if (a.size() > b.size()) {
        return b;
    } else {
        return a;
    }
}
Esempio n. 26
0
    virtual const char* onGetName() {
        fName.set("bitmap");
        fName.appendf("_%s%s", sk_tool_utils::colortype_name(fColorType),
                      kOpaque_SkAlphaType == fAlphaType ? "" : "_A");
        if (fDoScale) {
            fName.append("_scale");
        }
        if (fForceUpdate) {
            fName.append("_update");
        }
        if (fIsVolatile) {
            fName.append("_volatile");
        }

        return fName.c_str();
    }
int main (int argc, char * const argv[]) {
    SkAutoGraphics ag;
    int i, outDirIndex = 0;
    SkString outDir;

    for (i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-help")) {
            show_help();
            return 0;
        }
        if (!strcmp(argv[i], "-o")) {
            if (i == argc-1) {
                SkDebugf("ERROR: -o needs a following filename\n");
                return -1;
            }
            outDirIndex = i;
            outDir.set(argv[i+1]);
            if (outDir.c_str()[outDir.size() - 1] != '/') {
                outDir.append("/");
            }
            i += 1; // skip the out dir name
        }
    }

    for (i = 1; i < argc; i++) {
        if (i == outDirIndex) {
            i += 1; // skip this and the next entry
            continue;
        }
        
        SkBitmap bitmap;
        if (decodeFile(&bitmap, argv[i])) {
            if (outDirIndex) {
                SkString outPath;
                make_outname(&outPath, outDir.c_str(), argv[i]);
                SkDebugf("  writing %s\n", outPath.c_str());
                SkImageEncoder::EncodeFile(outPath.c_str(), bitmap,
                                           SkImageEncoder::kPNG_Type, 100);
            } else {
                SkDebugf("  decoded %s [%d %d]\n", argv[i], bitmap.width(),
                         bitmap.height());
            }
        }
    }

    return 0;
}
Esempio n. 28
0
 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath,
                           const char *subdirOrNull, const SkString& baseName) {
     SkString partialPath;
     if (subdirOrNull) {
         partialPath = SkOSPath::Join(dirPath.c_str(), subdirOrNull);
         sk_mkdir(partialPath.c_str());
     } else {
         partialPath.set(dirPath);
     }
     SkString fullPath = SkOSPath::Join(partialPath.c_str(), baseName.c_str());
     if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPNG_Type, 100)) {
         return true;
     } else {
         SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str());
         return false;
     }
 }
    virtual const char* onGetName() {
        fName.set("bitmap");
        if (fTileX >= 0) {
            fName.appendf("_%s", gTileName[fTileX]);
            if (fTileY != fTileX) {
                fName.appendf("_%s", gTileName[fTileY]);
            }
        }
        fName.appendf("_%s%s", gConfigName[fBitmap.config()],
                      fIsOpaque ? "" : "_A");
        if (fForceUpdate) 
            fName.append("_update");
        if (fBitmap.isVolatile())
            fName.append("_volatile");

        return fName.c_str();
    }
Esempio n. 30
0
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;
}