From 3b484a40b3be7f0262afadeaf6b741ba5cedcfe1 Mon Sep 17 00:00:00 2001 From: jvanverth Date: Fri, 6 Nov 2015 14:20:03 -0800 Subject: Add text animation sample; tweak DrawShip sample Review URL: https://codereview.chromium.org/1410663005 --- src/gpu/GrTest.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/gpu') diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp index 4adc3f7b7b..7a44942a16 100644 --- a/src/gpu/GrTest.cpp +++ b/src/gpu/GrTest.cpp @@ -11,10 +11,12 @@ #include "GrBatchAtlas.h" #include "GrBatchFontCache.h" #include "GrContextOptions.h" +#include "GrDrawContext.h" #include "GrDrawingManager.h" #include "GrGpuResourceCacheAccess.h" #include "GrResourceCache.h" #include "GrTextBlobCache.h" +#include "SkGrPriv.h" #include "SkString.h" namespace GrTest { @@ -97,6 +99,35 @@ void GrContext::printGpuStats() const { SkDebugf("%s", out.c_str()); } +void GrContext::drawFontCache(const SkRect& rect, GrMaskFormat format, const SkPaint& paint, + GrRenderTarget* target) { + GrBatchFontCache* cache = this->getBatchFontCache(); + + GrTexture* atlas = cache->getTexture(format); + + SkAutoTUnref drawContext(this->drawContext(target)); + // TODO: add drawContext method to encapsulate this. + + GrPaint grPaint; + SkMatrix mat; + mat.reset(); + if (!SkPaintToGrPaint(this, paint, mat, &grPaint)) { + return; + } + SkMatrix textureMat; + textureMat.reset(); + // TODO: use setScaleTranslate() + textureMat[SkMatrix::kMScaleX] = 1.0f/rect.width(); + textureMat[SkMatrix::kMScaleY] = 1.0f/rect.height(); + textureMat[SkMatrix::kMTransX] = -rect.fLeft/rect.width(); + textureMat[SkMatrix::kMTransY] = -rect.fTop/rect.height(); + + grPaint.addColorTextureProcessor(atlas, textureMat); + + GrClip clip; + drawContext->drawRect(clip, grPaint, mat, rect); +} + #if GR_GPU_STATS void GrGpu::Stats::dump(SkString* out) { out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); -- cgit v1.2.3