implement drawAtlas natively on gpu-device
BUG=skia: Review URL: https://codereview.chromium.org/1216433002
This commit is contained in:
parent
b6d93ea428
commit
ca10953d9c
@ -68,11 +68,13 @@ class DrawAtlasDrawable : public SkDrawable {
|
||||
fVelocity.fX = -fVelocity.fX;
|
||||
}
|
||||
if (fCenter.fY > bounds.bottom()) {
|
||||
SkASSERT(fVelocity.fY > 0);
|
||||
fVelocity.fY = -fVelocity.fY;
|
||||
if (fVelocity.fY > 0) {
|
||||
fVelocity.fY = -fVelocity.fY;
|
||||
}
|
||||
} else if (fCenter.fY < bounds.top()) {
|
||||
SkASSERT(fVelocity.fY < 0);
|
||||
fVelocity.fY = -fVelocity.fY;
|
||||
if (fVelocity.fY < 0) {
|
||||
fVelocity.fY = -fVelocity.fY;
|
||||
}
|
||||
}
|
||||
|
||||
fScale += fDScale;
|
||||
|
@ -1844,11 +1844,26 @@ bool SkDecomposeUpper2x2(const SkMatrix& matrix,
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkRSXform::toQuad(SkScalar width, SkScalar height, SkPoint quad[4]) const {
|
||||
#if 0
|
||||
// This is the slow way, but it documents what we're doing
|
||||
quad[0].set(0, 0);
|
||||
quad[1].set(width, 0);
|
||||
quad[2].set(width, height);
|
||||
quad[3].set(0, height);
|
||||
SkMatrix m;
|
||||
m.setRSXform(*this).mapPoints(quad, quad, 4);
|
||||
#else
|
||||
const SkScalar m00 = fSCos;
|
||||
const SkScalar m01 = -fSSin;
|
||||
const SkScalar m02 = fTx;
|
||||
const SkScalar m10 = -m01;
|
||||
const SkScalar m11 = m00;
|
||||
const SkScalar m12 = fTy;
|
||||
|
||||
quad[0].set(m02, m12);
|
||||
quad[1].set(m00 * width + m02, m10 * width + m12);
|
||||
quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m12);
|
||||
quad[3].set(m01 * height + m02, m11 * height + m12);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1639,6 +1639,50 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void append_quad_indices(uint16_t indices[], int quadIndex) {
|
||||
int i = quadIndex * 4;
|
||||
indices[0] = i + 0; indices[1] = i + 1; indices[2] = i + 2;
|
||||
indices[3] = i + 2; indices[4] = i + 3; indices[5] = i + 0;
|
||||
}
|
||||
|
||||
void SkGpuDevice::drawAtlas(const SkDraw& d, const SkImage* atlas, const SkRSXform xform[],
|
||||
const SkRect texRect[], const SkColor colors[], int count,
|
||||
SkXfermode::Mode mode, const SkPaint& paint) {
|
||||
if (paint.isAntiAlias()) {
|
||||
this->INHERITED::drawAtlas(d, atlas, xform, texRect, colors, count, mode, paint);
|
||||
return;
|
||||
}
|
||||
|
||||
SkPaint p(paint);
|
||||
p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode))->unref();
|
||||
|
||||
const int vertCount = count * 4;
|
||||
const int indexCount = count * 6;
|
||||
SkAutoTMalloc<SkPoint> vertStorage(vertCount * 2);
|
||||
SkPoint* verts = vertStorage.get();
|
||||
SkPoint* texs = verts + vertCount;
|
||||
SkAutoTMalloc<uint16_t> indexStorage(indexCount);
|
||||
uint16_t* indices = indexStorage.get();
|
||||
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode));
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
xform[i].toQuad(texRect[i].width(), texRect[i].height(), verts);
|
||||
texRect[i].toQuad(texs);
|
||||
append_quad_indices(indices, i);
|
||||
verts += 4;
|
||||
texs += 4;
|
||||
indices += 6;
|
||||
}
|
||||
|
||||
verts = vertStorage.get();
|
||||
texs = verts + vertCount;
|
||||
indices = indexStorage.get();
|
||||
this->drawVertices(d, SkCanvas::kTriangles_VertexMode, vertCount, verts, texs, colors, xfer,
|
||||
indices, indexCount, p);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
|
||||
size_t byteLength, SkScalar x, SkScalar y,
|
||||
const SkPaint& paint) {
|
||||
|
@ -111,6 +111,8 @@ public:
|
||||
const SkColor colors[], SkXfermode* xmode,
|
||||
const uint16_t indices[], int indexCount,
|
||||
const SkPaint&) override;
|
||||
void drawAtlas(const SkDraw&, const SkImage* atlas, const SkRSXform[], const SkRect[],
|
||||
const SkColor[], int count, SkXfermode::Mode, const SkPaint&) override;
|
||||
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
|
||||
const SkPaint&) override;
|
||||
void drawImage(const SkDraw&, const SkImage*, SkScalar x, SkScalar y, const SkPaint&) override;
|
||||
|
Loading…
Reference in New Issue
Block a user