DEF_TEST(GrGLSLPrettyPrint, r) { SkTArray<const char*> testStr; SkTArray<int> lengths; testStr.push_back(input1.c_str()); lengths.push_back((int)input1.size()); testStr.push_back(input2.c_str()); lengths.push_back((int)input2.size()); testStr.push_back(input3.c_str()); lengths.push_back((int)input3.size()); testStr.push_back(input4.c_str()); lengths.push_back((int)input4.size()); testStr.push_back(input5.c_str()); lengths.push_back((int)input5.size()); testStr.push_back(input6.c_str()); lengths.push_back((int)input6.size()); SkString test = GrGLSLPrettyPrint::PrettyPrintGLSL(testStr.begin(), lengths.begin(), testStr.count(), true); ASSERT(output1 == test); testStr.reset(); lengths.reset(); testStr.push_back(neg1.c_str()); lengths.push_back((int)neg1.size()); testStr.push_back(neg2.c_str()); lengths.push_back((int)neg2.size()); testStr.push_back(neg3.c_str()); lengths.push_back((int)neg3.size()); // Just test we don't crash with garbage input ASSERT(GrGLSLPrettyPrint::PrettyPrintGLSL(testStr.begin(), lengths.begin(), 1, true).c_str() != NULL); }
void SkInternalAtlasTextTarget::deleteOps() { for (int i = 0; i < fOps.count(); ++i) { if (fOps[i]) { fOpMemoryPool->release(std::move(fOps[i])); } } fOps.reset(); }
void GLCpuPosInstancedArraysBench::teardown(const GrGLInterface* gl) { GR_GL_CALL(gl, BindBuffer(GR_GL_ARRAY_BUFFER, 0)); GR_GL_CALL(gl, BindVertexArray(0)); GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0)); GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); GR_GL_CALL(gl, DeleteTextures(1, &fTexture)); GR_GL_CALL(gl, DeleteProgram(fProgram)); GR_GL_CALL(gl, DeleteBuffers(fBuffers.count(), fBuffers.begin())); GR_GL_CALL(gl, DeleteVertexArrays(1, &fVAO)); fBuffers.reset(); }
GrPathRange* GrGLPathRendering::createGlyphs(const SkTypeface* typeface, const SkDescriptor* desc, const SkStrokeRec& stroke) { if (NULL != desc || !caps().glyphLoadingSupport) { return GrPathRendering::createGlyphs(typeface, desc, stroke); } if (NULL == typeface) { typeface = SkTypeface::GetDefaultTypeface(); SkASSERT(NULL != typeface); } int faceIndex; SkAutoTDelete<SkStream> fontStream(typeface->openStream(&faceIndex)); const size_t fontDataLength = fontStream->getLength(); if (0 == fontDataLength) { return GrPathRendering::createGlyphs(typeface, NULL, stroke); } SkTArray<uint8_t> fontTempBuffer; const void* fontData = fontStream->getMemoryBase(); if (NULL == fontData) { // TODO: Find a more efficient way to pass the font data (e.g. open file descriptor). fontTempBuffer.reset(SkToInt(fontDataLength)); fontStream->read(&fontTempBuffer.front(), fontDataLength); fontData = &fontTempBuffer.front(); } const int numPaths = typeface->countGlyphs(); const GrGLuint basePathID = this->genPaths(numPaths); SkAutoTUnref<GrGLPath> templatePath(SkNEW_ARGS(GrGLPath, (fGpu, SkPath(), stroke))); GrGLenum status; GL_CALL_RET(status, PathMemoryGlyphIndexArray(basePathID, GR_GL_STANDARD_FONT_FORMAT, fontDataLength, fontData, faceIndex, 0, numPaths, templatePath->pathID(), SkPaint::kCanonicalTextSizeForPaths)); if (GR_GL_FONT_GLYPHS_AVAILABLE != status) { this->deletePaths(basePathID, numPaths); return GrPathRendering::createGlyphs(typeface, NULL, stroke); } // This is a crude approximation. We may want to consider giving this class // a pseudo PathGenerator whose sole purpose is to track the approximate gpu // memory size. const size_t gpuMemorySize = fontDataLength / 4; return SkNEW_ARGS(GrGLPathRange, (fGpu, basePathID, numPaths, gpuMemorySize, stroke)); }
void SkConvolutionFilter1D::AddFilter(int filterOffset, const float* filterValues, int filterLength) { SkASSERT(filterLength > 0); SkTArray<ConvolutionFixed> fixedValues; fixedValues.reset(filterLength); for (int i = 0; i < filterLength; ++i) { fixedValues.push_back(FloatToFixed(filterValues[i])); } AddFilter(filterOffset, &fixedValues[0], filterLength); }
static void TestTSet_basic(skiatest::Reporter* reporter) { SkTArray<int, MEM_MOVE> a; // Starts empty. REPORTER_ASSERT(reporter, a.empty()); REPORTER_ASSERT(reporter, a.count() == 0); // { }, add a default constructed element a.push_back() = 0; REPORTER_ASSERT(reporter, !a.empty()); REPORTER_ASSERT(reporter, a.count() == 1); // { 0 }, removeShuffle the only element. a.removeShuffle(0); REPORTER_ASSERT(reporter, a.empty()); REPORTER_ASSERT(reporter, a.count() == 0); // { }, add a default, add a 1, remove first a.push_back() = 0; REPORTER_ASSERT(reporter, a.push_back() = 1); a.removeShuffle(0); REPORTER_ASSERT(reporter, !a.empty()); REPORTER_ASSERT(reporter, a.count() == 1); REPORTER_ASSERT(reporter, a[0] == 1); // { 1 }, replace with new array int b[5] = { 0, 1, 2, 3, 4 }; a.reset(b, SK_ARRAY_COUNT(b)); REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b)); REPORTER_ASSERT(reporter, a[2] == 2); REPORTER_ASSERT(reporter, a[4] == 4); // { 0, 1, 2, 3, 4 }, removeShuffle the last a.removeShuffle(4); REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 1); REPORTER_ASSERT(reporter, a[3] == 3); // { 0, 1, 2, 3 }, remove a middle, note shuffle a.removeShuffle(1); REPORTER_ASSERT(reporter, a.count() == SK_ARRAY_COUNT(b) - 2); REPORTER_ASSERT(reporter, a[0] == 0); REPORTER_ASSERT(reporter, a[1] == 3); REPORTER_ASSERT(reporter, a[2] == 2); // {0, 3, 2 } }
void CubicPathToQuads(const SkPath& cubicPath, SkPath* quadPath) { quadPath->reset(); SkDCubic cubic; SkTArray<SkDQuad, true> quads; SkPath::RawIter iter(cubicPath); uint8_t verb; SkPoint pts[4]; while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { switch (verb) { case SkPath::kMove_Verb: quadPath->moveTo(pts[0].fX, pts[0].fY); continue; case SkPath::kLine_Verb: quadPath->lineTo(pts[1].fX, pts[1].fY); break; case SkPath::kQuad_Verb: quadPath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY); break; case SkPath::kCubic_Verb: quads.reset(); cubic.set(pts); CubicToQuads(cubic, cubic.calcPrecision(), quads); for (int index = 0; index < quads.count(); ++index) { SkPoint qPts[2] = { quads[index][1].asSkPoint(), quads[index][2].asSkPoint() }; quadPath->quadTo(qPts[0].fX, qPts[0].fY, qPts[1].fX, qPts[1].fY); } break; case SkPath::kClose_Verb: quadPath->close(); break; default: SkDEBUGFAIL("bad verb"); return; } } }