本文整理汇总了C++中SkMatrix::setAll方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::setAll方法的具体用法?C++ SkMatrix::setAll怎么用?C++ SkMatrix::setAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::setAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetTransform
extern void SetTransform(RenderingContext*ctx, float*m)
{
SkMatrix matrix;
matrix.setAll(m[0], m[1], m[2], m[3], m[4], m[5], 0, 0, 1);
ctx->Canvas->setMatrix(ConvertPerspexMatrix(m));
}
示例2: SkScalar
// Test drawing text with some unusual matricies.
// We measure success by not crashing or asserting.
DEF_TEST(DrawText_weirdMatricies, r) {
auto surface = SkSurface::MakeRasterN32Premul(100,100);
auto canvas = surface->getCanvas();
SkPaint paint;
paint.setAntiAlias(true);
paint.setLCDRenderText(true);
struct {
SkScalar textSize;
SkScalar matrix[9];
} testCases[] = {
// 2x2 singular
{10, { 0, 0, 0, 0, 0, 0, 0, 0, 1}},
{10, { 0, 0, 0, 0, 1, 0, 0, 0, 1}},
{10, { 0, 0, 0, 1, 0, 0, 0, 0, 1}},
{10, { 0, 0, 0, 1, 1, 0, 0, 0, 1}},
{10, { 0, 1, 0, 0, 1, 0, 0, 0, 1}},
{10, { 1, 0, 0, 0, 0, 0, 0, 0, 1}},
{10, { 1, 0, 0, 1, 0, 0, 0, 0, 1}},
{10, { 1, 1, 0, 0, 0, 0, 0, 0, 1}},
{10, { 1, 1, 0, 1, 1, 0, 0, 0, 1}},
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1305085 .
{ 1, {10, 20, 0, 20, 40, 0, 0, 0, 1}},
};
for (const auto& testCase : testCases) {
paint.setTextSize(testCase.textSize);
const SkScalar(&m)[9] = testCase.matrix;
SkMatrix mat;
mat.setAll(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
canvas->setMatrix(mat);
canvas->drawString("Hamburgefons", 10, 10, paint);
}
}
示例3: draw
void draw(SkCanvas* canvas) {
SkMatrix matrix;
matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 0);
if (matrix.invert(&matrix)) {
SkScalar factor[2] = {2, 2};
bool result = matrix.getMinMaxScales(factor);
SkDebugf("matrix.getMinMaxScales() %s %g %g\n",
result ? "true" : "false", factor[0], factor[1]);
}
}
示例4: test_wacky_bitmapshader
static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
int width, int height, bool shouldBeDrawn) {
SkBitmap dev;
dev.allocN32Pixels(0x56F, 0x4f6);
dev.eraseColor(SK_ColorTRANSPARENT); // necessary, so we know if we draw to it
SkMatrix matrix;
SkCanvas c(dev);
matrix.setAll(-119.34097f,
-43.436558f,
93489.945f,
43.436558f,
-119.34097f,
123.98426f,
0, 0, SK_Scalar1);
c.concat(matrix);
SkBitmap bm;
if (bm.tryAllocN32Pixels(width, height)) {
// allow this to fail silently, to test the code downstream
}
bm.eraseColor(SK_ColorRED);
matrix.setAll(0.0078740157f,
0,
SkIntToScalar(249),
0,
0.0078740157f,
SkIntToScalar(239),
0, 0, SK_Scalar1);
SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode, &matrix);
SkPaint paint;
paint.setShader(s)->unref();
SkRect r = SkRect::MakeXYWH(681, 239, 695, 253);
c.drawRect(r, paint);
assert_ifDrawnTo(reporter, dev, shouldBeDrawn);
}
示例5: SkDoubleToScalar
void WRasterImage::Impl::applyTransform(const WTransform& t)
{
SkMatrix sm;
sm.setAll(SkDoubleToScalar(t.m11()),
SkDoubleToScalar(t.m12()),
SkDoubleToScalar(t.dx()),
SkDoubleToScalar(t.m21()),
SkDoubleToScalar(t.m22()),
SkDoubleToScalar(t.dy()),
0,
0,
SkDoubleToScalar(1.0));
canvas_->concat(sm);
}
示例6: calc_cubic_klm
// Solves linear system to extract klm
// P.K = k (similarly for l, m)
// Where P is matrix of control points
// K is coefficients for the line K
// k is vector of values of K evaluated at the control points
// Solving for K, thus K = P^(-1) . k
static void calc_cubic_klm(const SkPoint p[4], const SkScalar controlK[4],
const SkScalar controlL[4], const SkScalar controlM[4],
SkScalar k[3], SkScalar l[3], SkScalar m[3]) {
SkMatrix matrix;
matrix.setAll(p[0].fX, p[0].fY, 1.f,
p[1].fX, p[1].fY, 1.f,
p[2].fX, p[2].fY, 1.f);
SkMatrix inverse;
if (matrix.invert(&inverse)) {
inverse.mapHomogeneousPoints(k, controlK, 1);
inverse.mapHomogeneousPoints(l, controlL, 1);
inverse.mapHomogeneousPoints(m, controlM, 1);
}
}
示例7:
static SkMatrix
Matrix3DToSkia(const gfx3DMatrix& aMatrix)
{
SkMatrix transform;
transform.setAll(aMatrix._11,
aMatrix._21,
aMatrix._41,
aMatrix._12,
aMatrix._22,
aMatrix._42,
aMatrix._14,
aMatrix._24,
aMatrix._44);
return transform;
}
示例8: draw
void draw(SkCanvas* canvas) {
SkPaint p;
p.setAntiAlias(true);
SkMatrix m;
int pos = 0;
for (SkScalar sx : { 1, 2 } ) {
for (SkScalar kx : { 0, 1 } ) {
m.setAll(sx, kx, 16, 0, 1, 32, 0, 0, 1);
bool isSimilarity = m.isSimilarity();
bool preservesRightAngles = m.preservesRightAngles();
SkString str;
str.printf("sx: %g kx: %g %s %s", sx, kx, isSimilarity ? "sim" : "",
preservesRightAngles ? "right" : "");
SkAutoCanvasRestore autoRestore(canvas, true);
canvas->concat(m);
canvas->drawString(str, 0, pos, p);
pos += 20;
}
}
}
示例9: onOnceBeforeDraw
void onOnceBeforeDraw() override {
SkBitmap emptyBmp;
SkBitmap blueBmp;
blueBmp.allocN32Pixels(10, 10);
blueBmp.eraseColor(SK_ColorBLUE);
SkMatrix badMatrix;
badMatrix.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
#if 0 // This crashes pipe!
// Empty bitmap.
fPaints.push_back().setColor(SK_ColorGREEN);
fPaints.back().setShader(SkShader::CreateBitmapShader(emptyBmp, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode))->unref();
#endif
// Non-invertible local matrix.
fPaints.push_back().setColor(SK_ColorGREEN);
fPaints.back().setShader(SkShader::CreateBitmapShader(blueBmp, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode,
&badMatrix))->unref();
}
示例10: SkScalarHalf
// Test out the case where an oval already off in space is translated/scaled
// further off into space - yielding numerical issues when the rect & radii
// are transformed separatly
// BUG=skia:2696
static void test_issue_2696(skiatest::Reporter* reporter) {
SkRRect rrect;
SkRect r = { 28443.8594f, 53.1428604f, 28446.7148f, 56.0000038f };
rrect.setOval(r);
SkMatrix xform;
xform.setAll(2.44f, 0.0f, 485411.7f,
0.0f, 2.44f, -438.7f,
0.0f, 0.0f, 1.0f);
SkRRect dst;
bool success = rrect.transform(xform, &dst);
REPORTER_ASSERT(reporter, success);
SkScalar halfWidth = SkScalarHalf(dst.width());
SkScalar halfHeight = SkScalarHalf(dst.height());
for (int i = 0; i < 4; ++i) {
REPORTER_ASSERT(reporter,
SkScalarNearlyEqual(dst.radii((SkRRect::Corner)i).fX, halfWidth));
REPORTER_ASSERT(reporter,
SkScalarNearlyEqual(dst.radii((SkRRect::Corner)i).fY, halfHeight));
}
}
示例11: 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;
const int kTripleCount = 1000;
const int kMatrixCount = 1000;
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(NULL, NULL, 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]);
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));
}
//.........这里部分代码省略.........
示例12: test_matrix_is_similarity
//.........这里部分代码省略.........
// scale with one negative
mat.reset();
mat.setScale(SkIntToScalar(-15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// scale with same size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective x
mat.reset();
mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective y
mat.reset();
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// rotate
for (int angle = 0; angle < 360; ++angle) {
mat.reset();
mat.setRotate(SkIntToScalar(angle));
REPORTER_ASSERT(reporter, mat.isSimilarity());
}
// see if there are any accumulated precision issues
mat.reset();
for (int i = 1; i < 360; i++) {
mat.postRotate(SkIntToScalar(1));
}
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + translate
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postScale(SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + non-uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postScale(SkIntToScalar(3), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// all zero
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// all zero except perspective
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, SK_Scalar1);
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// scales zero, only skews
mat.setAll(0, SK_Scalar1, 0,
SK_Scalar1, 0, 0,
0, 0, SkMatrix::I()[8]);
REPORTER_ASSERT(reporter, mat.isSimilarity());
}
示例13: onDraw
//.........这里部分代码省略.........
}
// check gamma-corrected blending
const SkColor fg[] = {
0xFFFFFFFF,
0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF,
0xFFFF0000, 0xFF00FF00, 0xFF0000FF,
0xFF000000,
};
paint.setColor(0xFFF7F3F7);
SkRect r = SkRect::MakeLTRB(670, 215, 820, 397);
canvas->drawRect(r, paint);
x = SkIntToScalar(680);
y = SkIntToScalar(235);
font.setSize(SkIntToScalar(19));
for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
paint.setColor(fg[i]);
canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, paint);
y += font.getMetrics(nullptr);
}
paint.setColor(0xFF181C18);
r = SkRect::MakeLTRB(820, 215, 970, 397);
canvas->drawRect(r, paint);
x = SkIntToScalar(830);
y = SkIntToScalar(235);
font.setSize(SkIntToScalar(19));
for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
paint.setColor(fg[i]);
canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, paint);
y += font.getMetrics(nullptr);
}
// check skew
{
font.setEdging(SkFont::Edging::kAntiAlias);
SkAutoCanvasRestore acr(canvas, true);
canvas->skew(0.0f, 0.151515f);
font.setSize(SkIntToScalar(32));
canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 745, 70, font, paint);
}
{
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
SkAutoCanvasRestore acr(canvas, true);
canvas->skew(0.5f, 0.0f);
font.setSize(SkIntToScalar(32));
canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 580, 125, font, paint);
}
// check perspective
{
font.setEdging(SkFont::Edging::kAntiAlias);
SkAutoCanvasRestore acr(canvas, true);
SkMatrix persp;
persp.setAll(0.9839f, 0, 0,
0.2246f, 0.6829f, 0,
0.0002352f, -0.0003844f, 1);
canvas->concat(persp);
canvas->translate(1100, -295);
font.setSize(37.5f);
canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint);
}
{
font.setSubpixel(false);
font.setEdging(SkFont::Edging::kAlias);
SkAutoCanvasRestore acr(canvas, true);
SkMatrix persp;
persp.setAll(0.9839f, 0, 0,
0.2246f, 0.6829f, 0,
0.0002352f, -0.0003844f, 1);
canvas->concat(persp);
canvas->translate(1075, -245);
canvas->scale(375, 375);
font.setSize(0.1f);
canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint);
}
// check color emoji
if (fEmojiTypeface) {
SkFont emoiFont;
emoiFont.setSubpixel(true);
emoiFont.setTypeface(fEmojiTypeface);
emoiFont.setSize(SkIntToScalar(19));
canvas->drawSimpleText(fEmojiText, strlen(fEmojiText), SkTextEncoding::kUTF8, 670, 90, emoiFont, paint);
}
// render offscreen buffer
if (surface) {
SkAutoCanvasRestore acr(inputCanvas, true);
// since we prepended this matrix already, we blit using identity
inputCanvas->resetMatrix();
inputCanvas->drawImage(surface->makeImageSnapshot().get(), 0, 0, nullptr);
}
}
示例14: test_matrix_is_similarity
//.........这里部分代码省略.........
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective x
mat.reset();
mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective y
mat.reset();
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
#ifdef SK_SCALAR_IS_FLOAT
/* We bypass the following tests for SK_SCALAR_IS_FIXED build.
* The long discussion can be found in this issue:
* http://codereview.appspot.com/5999050/
* In short, we haven't found a perfect way to fix the precision
* issue, i.e. the way we use tolerance in isSimilarityTransformation
* is incorrect. The situation becomes worse in fixed build, so
* we disabled rotation related tests for fixed build.
*/
// rotate
for (int angle = 0; angle < 360; ++angle) {
mat.reset();
mat.setRotate(SkIntToScalar(angle));
REPORTER_ASSERT(reporter, mat.isSimilarity());
}
// see if there are any accumulated precision issues
mat.reset();
for (int i = 1; i < 360; i++) {
mat.postRotate(SkIntToScalar(1));
}
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + translate
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postScale(SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + non-uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postScale(SkIntToScalar(3), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
#endif
// all zero
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// all zero except perspective
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, SK_Scalar1);
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// scales zero, only skews
mat.setAll(0, SK_Scalar1, 0,
SK_Scalar1, 0, 0,
0, 0, SkMatrix::I()[8]);
REPORTER_ASSERT(reporter, mat.isSimilarity());
}
示例15: flushViewMatrix
void GrGpuGL::flushViewMatrix(DrawType type) {
const GrGLRenderTarget* rt = static_cast<const GrGLRenderTarget*>(this->getDrawState().getRenderTarget());
SkISize viewportSize;
const GrGLIRect& viewport = rt->getViewport();
viewportSize.set(viewport.fWidth, viewport.fHeight);
const SkMatrix& vm = this->getDrawState().getViewMatrix();
if (kStencilPath_DrawType == type) {
if (fHWPathMatrixState.fViewMatrix != vm ||
fHWPathMatrixState.fRTSize != viewportSize) {
// rescale the coords from skia's "device" coords to GL's normalized coords,
// and perform a y-flip.
SkMatrix m;
m.setScale(SkIntToScalar(2) / rt->width(), SkIntToScalar(-2) / rt->height());
m.postTranslate(-SK_Scalar1, SK_Scalar1);
m.preConcat(vm);
// GL wants a column-major 4x4.
GrGLfloat mv[] = {
// col 0
SkScalarToFloat(m[SkMatrix::kMScaleX]),
SkScalarToFloat(m[SkMatrix::kMSkewY]),
0,
SkScalarToFloat(m[SkMatrix::kMPersp0]),
// col 1
SkScalarToFloat(m[SkMatrix::kMSkewX]),
SkScalarToFloat(m[SkMatrix::kMScaleY]),
0,
SkScalarToFloat(m[SkMatrix::kMPersp1]),
// col 2
0, 0, 0, 0,
// col3
SkScalarToFloat(m[SkMatrix::kMTransX]),
SkScalarToFloat(m[SkMatrix::kMTransY]),
0.0f,
SkScalarToFloat(m[SkMatrix::kMPersp2])
};
GL_CALL(MatrixMode(GR_GL_PROJECTION));
GL_CALL(LoadMatrixf(mv));
fHWPathMatrixState.fViewMatrix = vm;
fHWPathMatrixState.fRTSize = viewportSize;
}
} else if (!fCurrentProgram->fViewMatrix.cheapEqualTo(vm) ||
fCurrentProgram->fViewportSize != viewportSize) {
SkMatrix m;
m.setAll(
SkIntToScalar(2) / viewportSize.fWidth, 0, -SK_Scalar1,
0,-SkIntToScalar(2) / viewportSize.fHeight, SK_Scalar1,
0, 0, SkMatrix::I()[8]);
m.setConcat(m, vm);
// ES doesn't allow you to pass true to the transpose param,
// so do our own transpose
GrGLfloat mt[] = {
SkScalarToFloat(m[SkMatrix::kMScaleX]),
SkScalarToFloat(m[SkMatrix::kMSkewY]),
SkScalarToFloat(m[SkMatrix::kMPersp0]),
SkScalarToFloat(m[SkMatrix::kMSkewX]),
SkScalarToFloat(m[SkMatrix::kMScaleY]),
SkScalarToFloat(m[SkMatrix::kMPersp1]),
SkScalarToFloat(m[SkMatrix::kMTransX]),
SkScalarToFloat(m[SkMatrix::kMTransY]),
SkScalarToFloat(m[SkMatrix::kMPersp2])
};
fCurrentProgram->fUniformManager.setMatrix3f(
fCurrentProgram->fUniformHandles.fViewMatrixUni,
mt);
fCurrentProgram->fViewMatrix = vm;
fCurrentProgram->fViewportSize = viewportSize;
}
}