예제 #1
0
void
WebGLShader::ShaderSource(const nsAString& source)
{
    const char funcName[] = "shaderSource";
    nsString sourceWithoutComments;
    if (!TruncateComments(source, &sourceWithoutComments)) {
        mContext->ErrorOutOfMemory("%s: Failed to alloc for empting comment contents.",
                                   funcName);
        return;
    }

    if (!ValidateGLSLPreprocString(mContext, funcName, sourceWithoutComments))
        return;

    // We checked that the source stripped of comments is in the
    // 7-bit ASCII range, so we can skip the NS_IsAscii() check.
    const NS_LossyConvertUTF16toASCII cleanSource(sourceWithoutComments);

    if (PR_GetEnv("MOZ_WEBGL_DUMP_SHADERS")) {
        printf_stderr("////////////////////////////////////////\n");
        printf_stderr("// MOZ_WEBGL_DUMP_SHADERS:\n");

        // Wow - Roll Your Own Foreach-Lines because printf_stderr has a hard-coded
        // internal size, so long strings are truncated.

        const size_t maxChunkSize = 1024-1; // -1 for null-term.
        const UniqueBuffer buf(moz_xmalloc(maxChunkSize+1)); // +1 for null-term
        const auto bufBegin = (char*)buf.get();

        size_t chunkStart = 0;
        while (chunkStart != cleanSource.Length()) {
            const auto chunkEnd = std::min(chunkStart + maxChunkSize,
                                           size_t(cleanSource.Length()));
            const auto chunkSize = chunkEnd - chunkStart;

            memcpy(bufBegin, cleanSource.BeginReading() + chunkStart, chunkSize);
            bufBegin[chunkSize + 1] = '\0';

            printf_stderr("%s", bufBegin);
            chunkStart += chunkSize;
        }

        printf_stderr("////////////////////////////////////////\n");
    }

    mSource = source;
    mCleanSource = cleanSource;
}
예제 #2
0
void
WebGLShader::ShaderSource(const nsAString& source)
{
    nsString sourceWithoutComments;
    if (!TruncateComments(source, &sourceWithoutComments)) {
        mContext->ErrorOutOfMemory("Failed to alloc for empting comment contents.");
        return;
    }

    if (!ValidateGLSLPreprocString(mContext, sourceWithoutComments))
        return;

    // We checked that the source stripped of comments is in the
    // 7-bit ASCII range, so we can skip the NS_IsAscii() check.
    const NS_LossyConvertUTF16toASCII cleanSource(sourceWithoutComments);

    mSource = source;
    mCleanSource = cleanSource;
}