本文整理汇总了C++中SkPoint::set方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPoint::set方法的具体用法?C++ SkPoint::set怎么用?C++ SkPoint::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPoint
的用法示例。
在下文中一共展示了SkPoint::set方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeSweep
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
}
示例2: drawBitmapMesh
static void drawBitmapMesh(JNIEnv* env, jobject, SkCanvas* canvas,
const SkBitmap* bitmap, int meshWidth, int meshHeight,
jfloatArray jverts, int vertIndex, jintArray jcolors,
int colorIndex, const SkPaint* paint) {
const int ptCount = (meshWidth + 1) * (meshHeight + 1);
const int indexCount = meshWidth * meshHeight * 6;
AutoJavaFloatArray vertA(env, jverts, vertIndex + (ptCount << 1));
AutoJavaIntArray colorA(env, jcolors, colorIndex + ptCount);
/* Our temp storage holds 2 or 3 arrays.
texture points [ptCount * sizeof(SkPoint)]
optionally vertex points [ptCount * sizeof(SkPoint)] if we need a
copy to convert from float to fixed
indices [ptCount * sizeof(uint16_t)]
*/
ssize_t storageSize = ptCount * sizeof(SkPoint); // texs[]
#ifdef SK_SCALAR_IS_FIXED
storageSize += ptCount * sizeof(SkPoint); // storage for verts
#endif
storageSize += indexCount * sizeof(uint16_t); // indices[]
SkAutoMalloc storage(storageSize);
SkPoint* texs = (SkPoint*)storage.get();
SkPoint* verts;
uint16_t* indices;
#ifdef SK_SCALAR_IS_FLOAT
verts = (SkPoint*)(vertA.ptr() + vertIndex);
indices = (uint16_t*)(texs + ptCount);
#else
verts = texs + ptCount;
indices = (uint16_t*)(verts + ptCount);
// convert floats to fixed
{
const float* src = vertA.ptr() + vertIndex;
for (int i = 0; i < ptCount; i++) {
verts[i].set(SkFloatToFixed(src[0]), SkFloatToFixed(src[1]));
src += 2;
}
}
#endif
// cons up texture coordinates and indices
{
const SkScalar w = SkIntToScalar(bitmap->width());
const SkScalar h = SkIntToScalar(bitmap->height());
const SkScalar dx = w / meshWidth;
const SkScalar dy = h / meshHeight;
SkPoint* texsPtr = texs;
SkScalar y = 0;
for (int i = 0; i <= meshHeight; i++) {
if (i == meshHeight) {
y = h; // to ensure numerically we hit h exactly
}
SkScalar x = 0;
for (int j = 0; j < meshWidth; j++) {
texsPtr->set(x, y);
texsPtr += 1;
x += dx;
}
texsPtr->set(w, y);
texsPtr += 1;
y += dy;
}
SkASSERT(texsPtr - texs == ptCount);
}
// cons up indices
{
uint16_t* indexPtr = indices;
int index = 0;
for (int i = 0; i < meshHeight; i++) {
for (int j = 0; j < meshWidth; j++) {
// lower-left triangle
*indexPtr++ = index;
*indexPtr++ = index + meshWidth + 1;
*indexPtr++ = index + meshWidth + 2;
// upper-right triangle
*indexPtr++ = index;
*indexPtr++ = index + meshWidth + 2;
*indexPtr++ = index + 1;
// bump to the next cell
index += 1;
}
// bump to the next row
index += 1;
}
SkASSERT(indexPtr - indices == indexCount);
SkASSERT((char*)indexPtr - (char*)storage.get() == storageSize);
}
// double-check that we have legal indices
#ifdef SK_DEBUG
{
for (int i = 0; i < indexCount; i++) {
SkASSERT((unsigned)indices[i] < (unsigned)ptCount);
}
}
//.........这里部分代码省略.........
示例3: ClipLine
int SkLineClipper::ClipLine(const SkPoint pts[], const SkRect& clip, SkPoint lines[],
bool canCullToTheRight) {
int index0, index1;
if (pts[0].fY < pts[1].fY) {
index0 = 0;
index1 = 1;
} else {
index0 = 1;
index1 = 0;
}
// Check if we're completely clipped out in Y (above or below
if (pts[index1].fY <= clip.fTop) { // we're above the clip
return 0;
}
if (pts[index0].fY >= clip.fBottom) { // we're below the clip
return 0;
}
// Chop in Y to produce a single segment, stored in tmp[0..1]
SkPoint tmp[2];
memcpy(tmp, pts, sizeof(tmp));
// now compute intersections
if (pts[index0].fY < clip.fTop) {
tmp[index0].set(sect_with_horizontal(pts, clip.fTop), clip.fTop);
SkASSERT(is_between_unsorted(tmp[index0].fX, pts[0].fX, pts[1].fX));
}
if (tmp[index1].fY > clip.fBottom) {
tmp[index1].set(sect_with_horizontal(pts, clip.fBottom), clip.fBottom);
SkASSERT(is_between_unsorted(tmp[index1].fX, pts[0].fX, pts[1].fX));
}
// Chop it into 1..3 segments that are wholly within the clip in X.
// temp storage for up to 3 segments
SkPoint resultStorage[kMaxPoints];
SkPoint* result; // points to our results, either tmp or resultStorage
int lineCount = 1;
bool reverse;
if (pts[0].fX < pts[1].fX) {
index0 = 0;
index1 = 1;
reverse = false;
} else {
index0 = 1;
index1 = 0;
reverse = true;
}
if (tmp[index1].fX <= clip.fLeft) { // wholly to the left
tmp[0].fX = tmp[1].fX = clip.fLeft;
result = tmp;
reverse = false;
} else if (tmp[index0].fX >= clip.fRight) { // wholly to the right
if (canCullToTheRight) {
return 0;
}
tmp[0].fX = tmp[1].fX = clip.fRight;
result = tmp;
reverse = false;
} else {
result = resultStorage;
SkPoint* r = result;
if (tmp[index0].fX < clip.fLeft) {
r->set(clip.fLeft, tmp[index0].fY);
r += 1;
r->set(clip.fLeft, sect_clamp_with_vertical(tmp, clip.fLeft));
SkASSERT(is_between_unsorted(r->fY, tmp[0].fY, tmp[1].fY));
} else {
*r = tmp[index0];
}
r += 1;
if (tmp[index1].fX > clip.fRight) {
r->set(clip.fRight, sect_clamp_with_vertical(tmp, clip.fRight));
SkASSERT(is_between_unsorted(r->fY, tmp[0].fY, tmp[1].fY));
r += 1;
r->set(clip.fRight, tmp[index1].fY);
} else {
*r = tmp[index1];
}
lineCount = SkToInt(r - result);
}
// Now copy the results into the caller's lines[] parameter
if (reverse) {
// copy the pts in reverse order to maintain winding order
for (int i = 0; i <= lineCount; i++) {
lines[lineCount - i] = result[i];
}
} else {
memcpy(lines, result, (lineCount + 1) * sizeof(SkPoint));
}
//.........这里部分代码省略.........
示例4: PathClipView
PathClipView() {
fOval.set(0, 0, SkIntToScalar(200), SkIntToScalar(50));
fCenter.set(SkIntToScalar(250), SkIntToScalar(250));
// test_ats();
}
示例5: onClick
virtual bool onClick(Click* click) {
fCenter.set(click->fCurr.fX, click->fCurr.fY);
this->inval(NULL);
return NULL;
}
示例6: init
bool SkMeshIndices::init(SkPoint tex[], uint16_t indices[],
int texW, int texH, int rows, int cols) {
if (rows < 2 || cols < 2) {
sk_free(fStorage);
fStorage = nullptr;
fTex = nullptr;
fIndices = nullptr;
fTexCount = fIndexCount = 0;
return false;
}
sk_free(fStorage);
fStorage = nullptr;
fTexCount = rows * cols;
rows -= 1;
cols -= 1;
fIndexCount = rows * cols * 6;
if (tex) {
fTex = tex;
fIndices = indices;
} else {
fStorage = sk_malloc_throw(fTexCount * sizeof(SkPoint) +
fIndexCount * sizeof(uint16_t));
fTex = (SkPoint*)fStorage;
fIndices = (uint16_t*)(fTex + fTexCount);
}
// compute the indices
{
uint16_t* idx = fIndices;
int index = 0;
for (int y = 0; y < cols; y++) {
for (int x = 0; x < rows; x++) {
*idx++ = index;
*idx++ = index + rows + 1;
*idx++ = index + 1;
*idx++ = index + 1;
*idx++ = index + rows + 1;
*idx++ = index + rows + 2;
index += 1;
}
index += 1;
}
}
// compute texture coordinates
{
SkPoint* tex = fTex;
const SkScalar dx = SkIntToScalar(texW) / rows;
const SkScalar dy = SkIntToScalar(texH) / cols;
for (int y = 0; y <= cols; y++) {
for (int x = 0; x <= rows; x++) {
tex->set(x*dx, y*dy);
tex += 1;
}
}
}
return true;
}
示例7: test_matrix_homogeneous
static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
SkMatrix mat;
const float kRotation0 = 15.5f;
const float kRotation1 = -50.f;
const float kScale0 = 5000.f;
#if defined(GOOGLE3)
// Stack frame size is limited in GOOGLE3.
const int kTripleCount = 100;
const int kMatrixCount = 100;
#else
const int kTripleCount = 1000;
const int kMatrixCount = 1000;
#endif
SkRandom rand;
SkScalar randTriples[3*kTripleCount];
for (int i = 0; i < 3*kTripleCount; ++i) {
randTriples[i] = rand.nextRangeF(-3000.f, 3000.f);
}
SkMatrix mats[kMatrixCount];
for (int i = 0; i < kMatrixCount; ++i) {
for (int j = 0; j < 9; ++j) {
mats[i].set(j, rand.nextRangeF(-3000.f, 3000.f));
}
}
// identity
{
mat.reset();
SkScalar dst[3*kTripleCount];
mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(randTriples, dst, kTripleCount*3));
}
// zero matrix
{
mat.setAll(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
SkScalar dst[3*kTripleCount];
mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
SkScalar zeros[3] = {0.f, 0.f, 0.f};
for (int i = 0; i < kTripleCount; ++i) {
REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(&dst[i*3], zeros, 3));
}
}
// zero point
{
SkScalar zeros[3] = {0.f, 0.f, 0.f};
for (int i = 0; i < kMatrixCount; ++i) {
SkScalar dst[3];
mats[i].mapHomogeneousPoints(dst, zeros, 1);
REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(dst, zeros, 3));
}
}
// doesn't crash with null dst, src, count == 0
{
mats[0].mapHomogeneousPoints(nullptr, nullptr, 0);
}
// uniform scale of point
{
mat.setScale(kScale0, kScale0);
SkScalar dst[3];
SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
SkPoint pnt;
pnt.set(src[0], src[1]);
mat.mapHomogeneousPoints(dst, src, 1);
mat.mapPoints(&pnt, &pnt, 1);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1));
}
// rotation of point
{
mat.setRotate(kRotation0);
SkScalar dst[3];
SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
SkPoint pnt;
pnt.set(src[0], src[1]);
mat.mapHomogeneousPoints(dst, src, 1);
mat.mapPoints(&pnt, &pnt, 1);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1));
}
// rotation, scale, rotation of point
{
mat.setRotate(kRotation1);
mat.postScale(kScale0, kScale0);
mat.postRotate(kRotation0);
SkScalar dst[3];
SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
SkPoint pnt;
pnt.set(src[0], src[1]);
//.........这里部分代码省略.........
示例8: appendGlyph
void GrAtlasTextBlob::appendGlyph(int runIndex,
const SkRect& positions,
GrColor color,
GrBatchTextStrike* strike,
GrGlyph* glyph,
GrFontScaler* scaler, const SkGlyph& skGlyph,
SkScalar x, SkScalar y, SkScalar scale, bool applyVM) {
// If the glyph is too large we fall back to paths
if (glyph->fTooLargeForAtlas) {
this->appendLargeGlyph(glyph, scaler, skGlyph, x, y, scale, applyVM);
return;
}
Run& run = fRuns[runIndex];
GrMaskFormat format = glyph->fMaskFormat;
Run::SubRunInfo* subRun = &run.fSubRunInfo.back();
if (run.fInitialized && subRun->maskFormat() != format) {
subRun = &run.push_back();
subRun->setStrike(strike);
} else if (!run.fInitialized) {
subRun->setStrike(strike);
}
run.fInitialized = true;
size_t vertexStride = GetVertexStride(format);
subRun->setMaskFormat(format);
subRun->joinGlyphBounds(positions);
subRun->setColor(color);
intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex());
if (kARGB_GrMaskFormat != glyph->fMaskFormat) {
// V0
SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
position->set(positions.fLeft, positions.fTop);
SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
*colorPtr = color;
vertex += vertexStride;
// V1
position = reinterpret_cast<SkPoint*>(vertex);
position->set(positions.fLeft, positions.fBottom);
colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
*colorPtr = color;
vertex += vertexStride;
// V2
position = reinterpret_cast<SkPoint*>(vertex);
position->set(positions.fRight, positions.fBottom);
colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
*colorPtr = color;
vertex += vertexStride;
// V3
position = reinterpret_cast<SkPoint*>(vertex);
position->set(positions.fRight, positions.fTop);
colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
*colorPtr = color;
} else {
// V0
SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
position->set(positions.fLeft, positions.fTop);
vertex += vertexStride;
// V1
position = reinterpret_cast<SkPoint*>(vertex);
position->set(positions.fLeft, positions.fBottom);
vertex += vertexStride;
// V2
position = reinterpret_cast<SkPoint*>(vertex);
position->set(positions.fRight, positions.fBottom);
vertex += vertexStride;
// V3
position = reinterpret_cast<SkPoint*>(vertex);
position->set(positions.fRight, positions.fTop);
}
subRun->appendVertices(vertexStride);
fGlyphs[subRun->glyphEndIndex()] = glyph;
subRun->glyphAppended();
}
示例9: onClick
bool onClick(Click* click) override {
fCenter.set(click->fCurr.fX, click->fCurr.fY);
this->inval(NULL);
return false;
}
示例10: drawGlyphs
void Font::drawGlyphs(GraphicsContext* graphicsContext,
const SimpleFontData* font,
const GlyphBuffer& glyphBuffer,
int from,
int numGlyphs,
const FloatPoint& point,
const FloatRect& textRect) const
{
SkColor color = graphicsContext->effectiveFillColor();
unsigned char alpha = SkColorGetA(color);
// Skip 100% transparent text; no need to draw anything.
if (!alpha && graphicsContext->strokeStyle() == NoStroke && !graphicsContext->hasShadow())
return;
// We draw the glyphs in chunks to avoid having to do a heap allocation for
// the arrays of characters and advances.
const int kMaxBufferLength = 256;
Vector<int, kMaxBufferLength> advances;
int glyphIndex = 0; // The starting glyph of the current chunk.
float horizontalOffset = point.x(); // The floating point offset of the left side of the current glyph.
#if ENABLE(OPENTYPE_VERTICAL)
const OpenTypeVerticalData* verticalData = font->verticalData();
if (verticalData) {
Vector<FloatPoint, kMaxBufferLength> translations;
Vector<GOFFSET, kMaxBufferLength> offsets;
// Skia doesn't have matrix for glyph coordinate space, so we rotate back the CTM.
AffineTransform savedMatrix = graphicsContext->getCTM();
graphicsContext->concatCTM(AffineTransform(0, -1, 1, 0, point.x(), point.y()));
graphicsContext->concatCTM(AffineTransform(1, 0, 0, 1, -point.x(), -point.y()));
const FontMetrics& metrics = font->fontMetrics();
SkScalar verticalOriginX = SkFloatToScalar(point.x() + metrics.floatAscent() - metrics.floatAscent(IdeographicBaseline));
while (glyphIndex < numGlyphs) {
// How many chars will be in this chunk?
int curLen = std::min(kMaxBufferLength, numGlyphs - glyphIndex);
const Glyph* glyphs = glyphBuffer.glyphs(from + glyphIndex);
translations.resize(curLen);
verticalData->getVerticalTranslationsForGlyphs(font, &glyphs[0], curLen, reinterpret_cast<float*>(&translations[0]));
// To position glyphs vertically, we use offsets instead of advances.
advances.resize(curLen);
advances.fill(0);
offsets.resize(curLen);
float currentWidth = 0;
for (int i = 0; i < curLen; ++i, ++glyphIndex) {
offsets[i].du = lroundf(translations[i].x());
offsets[i].dv = -lroundf(currentWidth - translations[i].y());
currentWidth += glyphBuffer.advanceAt(from + glyphIndex);
}
SkPoint origin;
origin.set(verticalOriginX, SkFloatToScalar(point.y() + horizontalOffset - point.x()));
horizontalOffset += currentWidth;
paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs[0], &advances[0], &offsets[0], origin, SkRect(textRect));
}
graphicsContext->setCTM(savedMatrix);
return;
}
#endif
// In order to round all offsets to the correct pixel boundary, this code keeps track of the absolute position
// of each glyph in floating point units and rounds to integer advances at the last possible moment.
int lastHorizontalOffsetRounded = lroundf(horizontalOffset); // The rounded offset of the left side of the last glyph rendered.
Vector<WORD, kMaxBufferLength> glyphs;
while (glyphIndex < numGlyphs) {
// How many chars will be in this chunk?
int curLen = std::min(kMaxBufferLength, numGlyphs - glyphIndex);
glyphs.resize(curLen);
advances.resize(curLen);
float currentWidth = 0;
for (int i = 0; i < curLen; ++i, ++glyphIndex) {
glyphs[i] = glyphBuffer.glyphAt(from + glyphIndex);
horizontalOffset += glyphBuffer.advanceAt(from + glyphIndex);
advances[i] = lroundf(horizontalOffset) - lastHorizontalOffsetRounded;
lastHorizontalOffsetRounded += advances[i];
currentWidth += glyphBuffer.advanceAt(from + glyphIndex);
// Bug 26088 - very large positive or negative runs can fail to
// render so we clamp the size here. In the specs, negative
// letter-spacing is implementation-defined, so this should be
// fine, and it matches Safari's implementation. The call actually
// seems to crash if kMaxNegativeRun is set to somewhere around
// -32830, so we give ourselves a little breathing room.
const int maxNegativeRun = -32768;
const int maxPositiveRun = 32768;
if ((currentWidth + advances[i] < maxNegativeRun) || (currentWidth + advances[i] > maxPositiveRun))
advances[i] = 0;
}
SkPoint origin = point;
origin.fX += SkFloatToScalar(horizontalOffset - point.x() - currentWidth);
paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs[0], &advances[0], 0, origin, SkRect(textRect));
}
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:99,代码来源:FontChromiumWin.cpp
示例11: midPt
// midPt sets the first argument to be the midpoint of the other two
// it is used by quadApprox
static inline void midPt(SkPoint& dest,const SkPoint& a,const SkPoint& b)
{
dest.set(SkScalarAve(a.fX, b.fX),SkScalarAve(a.fY, b.fY));
}
示例12: appendGlyph
// Returns true if this method handled the glyph, false if needs to be passed to fallback
//
bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
SkScalar sx, SkScalar sy,
GrFontScaler* scaler) {
if (NULL == fDrawTarget) {
return true;
}
if (NULL == fStrike) {
fStrike = fContext->getFontCache()->getStrike(scaler, true);
}
GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
if (NULL == glyph || glyph->fBounds.isEmpty()) {
return true;
}
// fallback to color glyph support
if (kA8_GrMaskFormat != glyph->fMaskFormat) {
return false;
}
SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset);
SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset);
SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldInset);
SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceFieldInset);
SkScalar scale = fTextRatio;
dx *= scale;
dy *= scale;
sx += dx;
sy += dy;
width *= scale;
height *= scale;
SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height);
// check if we clipped out
SkRect dstRect;
const SkMatrix& ctm = fViewMatrix;
(void) ctm.mapRect(&dstRect, glyphRect);
if (fClipRect.quickReject(SkScalarTruncToInt(dstRect.left()),
SkScalarTruncToInt(dstRect.top()),
SkScalarTruncToInt(dstRect.right()),
SkScalarTruncToInt(dstRect.bottom()))) {
return true;
}
if (NULL == glyph->fPlot) {
// needs to be a separate conditional to avoid over-optimization
// on Nexus 7 and Nexus 10
// If the glyph is too large we fall back to paths
if (!uploadGlyph(glyph, scaler)) {
if (NULL == glyph->fPath) {
SkPath* path = SkNEW(SkPath);
if (!scaler->getGlyphPath(glyph->glyphID(), path)) {
// flag the glyph as being dead?
delete path;
return true;
}
glyph->fPath = path;
}
// flush any accumulated draws before drawing this glyph as a path.
this->flush();
SkMatrix ctm;
ctm.setScale(fTextRatio, fTextRatio);
ctm.postTranslate(sx - dx, sy - dy);
SkPath tmpPath(*glyph->fPath);
tmpPath.transform(ctm);
GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
fContext->drawPath(fRenderTarget, fClip, fPaint, fViewMatrix, tmpPath, strokeInfo);
// remove this glyph from the vertices we need to allocate
fTotalVertexCount -= kVerticesPerGlyph;
return true;
}
}
SkASSERT(glyph->fPlot);
GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken();
glyph->fPlot->setDrawToken(drawToken);
GrTexture* texture = glyph->fPlot->texture();
SkASSERT(texture);
if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fTotalVertexCount) {
this->flush();
fCurrTexture = texture;
fCurrTexture->ref();
}
bool useColorVerts = !fUseLCDText;
if (NULL == fVertices) {
int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer()->maxQuads();
//.........这里部分代码省略.........
示例13: GaussianBlur
GrTexture* GaussianBlur(GrContext* context,
GrTexture* srcTexture,
bool canClobberSrc,
const SkRect& dstBounds,
const SkRect* srcBounds,
float sigmaX,
float sigmaY,
GrTextureProvider::SizeConstraint constraint) {
SkASSERT(context);
SkIRect clearRect;
int scaleFactorX, radiusX;
int scaleFactorY, radiusY;
int maxTextureSize = context->caps()->maxTextureSize();
sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX);
sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY);
SkPoint srcOffset = SkPoint::Make(-dstBounds.x(), -dstBounds.y());
SkRect localDstBounds = SkRect::MakeWH(dstBounds.width(), dstBounds.height());
SkRect localSrcBounds;
SkRect srcRect;
if (srcBounds) {
srcRect = localSrcBounds = *srcBounds;
srcRect.offset(srcOffset);
srcBounds = &localSrcBounds;
} else {
srcRect = localDstBounds;
}
scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY);
srcRect.roundOut(&srcRect);
scale_rect(&srcRect, static_cast<float>(scaleFactorX),
static_cast<float>(scaleFactorY));
// setup new clip
GrClip clip(localDstBounds);
SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
kRGBA_8888_GrPixelConfig == srcTexture->config() ||
kAlpha_8_GrPixelConfig == srcTexture->config());
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = SkScalarFloorToInt(dstBounds.width());
desc.fHeight = SkScalarFloorToInt(dstBounds.height());
desc.fConfig = srcTexture->config();
GrTexture* dstTexture;
GrTexture* tempTexture;
SkAutoTUnref<GrTexture> temp1, temp2;
temp1.reset(context->textureProvider()->createTexture(desc, constraint));
dstTexture = temp1.get();
if (canClobberSrc) {
tempTexture = srcTexture;
} else {
temp2.reset(context->textureProvider()->createTexture(desc, constraint));
tempTexture = temp2.get();
}
if (nullptr == dstTexture || nullptr == tempTexture) {
return nullptr;
}
SkAutoTUnref<GrDrawContext> srcDrawContext;
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
GrPaint paint;
SkMatrix matrix;
matrix.setIDiv(srcTexture->width(), srcTexture->height());
SkRect dstRect(srcRect);
if (srcBounds && i == 1) {
SkRect domain;
matrix.mapRect(&domain, *srcBounds);
domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width() : 0.0f,
(i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height() : 0.0f);
SkAutoTUnref<const GrFragmentProcessor> fp(GrTextureDomainEffect::Create(
srcTexture,
matrix,
domain,
GrTextureDomain::kDecal_Mode,
GrTextureParams::kBilerp_FilterMode));
paint.addColorFragmentProcessor(fp);
srcRect.offset(-srcOffset);
srcOffset.set(0, 0);
} else {
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode);
paint.addColorTextureProcessor(srcTexture, matrix, params);
}
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
SkAutoTUnref<GrDrawContext> dstDrawContext(
context->drawContext(dstTexture->asRenderTarget()));
if (!dstDrawContext) {
return nullptr;
}
dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
srcDrawContext.swap(dstDrawContext);
//.........这里部分代码省略.........