Move texture drawing utility method to SkGpuDevice
BUG=skia:4542 Review URL: https://codereview.chromium.org/1506203002
This commit is contained in:
parent
55462e5f50
commit
0671b967eb
@ -354,9 +354,8 @@ public:
|
|||||||
/** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */
|
/** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */
|
||||||
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
|
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
|
||||||
|
|
||||||
/** Draw font cache texture to render target */
|
/** Get pointer to atlas texture for given mask format */
|
||||||
void drawFontCache(const SkRect& rect, GrMaskFormat format, const SkPaint& paint,
|
GrTexture* getFontAtlasTexture(GrMaskFormat format);
|
||||||
GrRenderTarget* target);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GrGpu* fGpu;
|
GrGpu* fGpu;
|
||||||
|
@ -106,8 +106,9 @@ protected:
|
|||||||
SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_testing();
|
SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_testing();
|
||||||
GrContext* grContext = canvas->getGrContext();
|
GrContext* grContext = canvas->getGrContext();
|
||||||
if (grContext) {
|
if (grContext) {
|
||||||
grContext->drawFontCache(SkRect::MakeXYWH(512, 10, 512, 512), kA8_GrMaskFormat, paint,
|
GrTexture* tex = grContext->getFontAtlasTexture(GrMaskFormat::kA8_GrMaskFormat);
|
||||||
reinterpret_cast<SkGpuDevice*>(device)->accessRenderTarget());
|
reinterpret_cast<SkGpuDevice*>(device)->drawTexture(tex,
|
||||||
|
SkRect::MakeXYWH(512, 10, 512, 512), paint);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
canvas->translate(180, 180);
|
canvas->translate(180, 180);
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include "GrGpuResourceCacheAccess.h"
|
#include "GrGpuResourceCacheAccess.h"
|
||||||
#include "GrResourceCache.h"
|
#include "GrResourceCache.h"
|
||||||
#include "GrTextBlobCache.h"
|
#include "GrTextBlobCache.h"
|
||||||
|
|
||||||
|
#include "SkGpuDevice.h"
|
||||||
#include "SkGrPriv.h"
|
#include "SkGrPriv.h"
|
||||||
#include "SkString.h"
|
#include "SkString.h"
|
||||||
|
|
||||||
@ -137,35 +139,33 @@ void GrContext::printGpuStats() const {
|
|||||||
SkDebugf("%s", out.c_str());
|
SkDebugf("%s", out.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrContext::drawFontCache(const SkRect& rect, GrMaskFormat format, const SkPaint& paint,
|
GrTexture* GrContext::getFontAtlasTexture(GrMaskFormat format) {
|
||||||
GrRenderTarget* target) {
|
|
||||||
GrBatchFontCache* cache = this->getBatchFontCache();
|
GrBatchFontCache* cache = this->getBatchFontCache();
|
||||||
|
|
||||||
GrTexture* atlas = cache->getTexture(format);
|
return cache->getTexture(format);
|
||||||
|
}
|
||||||
SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(target));
|
|
||||||
// TODO: add drawContext method to encapsulate this.
|
|
||||||
|
|
||||||
|
void SkGpuDevice::drawTexture(GrTexture* tex, const SkRect& dst, const SkPaint& paint) {
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkMatrix mat;
|
SkMatrix mat;
|
||||||
mat.reset();
|
mat.reset();
|
||||||
if (!SkPaintToGrPaint(this, paint, mat, &grPaint)) {
|
if (!SkPaintToGrPaint(this->context(), paint, mat, &grPaint)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SkMatrix textureMat;
|
SkMatrix textureMat;
|
||||||
textureMat.reset();
|
textureMat.reset();
|
||||||
// TODO: use setScaleTranslate()
|
textureMat[SkMatrix::kMScaleX] = 1.0f/dst.width();
|
||||||
textureMat[SkMatrix::kMScaleX] = 1.0f/rect.width();
|
textureMat[SkMatrix::kMScaleY] = 1.0f/dst.height();
|
||||||
textureMat[SkMatrix::kMScaleY] = 1.0f/rect.height();
|
textureMat[SkMatrix::kMTransX] = -dst.fLeft/dst.width();
|
||||||
textureMat[SkMatrix::kMTransX] = -rect.fLeft/rect.width();
|
textureMat[SkMatrix::kMTransY] = -dst.fTop/dst.height();
|
||||||
textureMat[SkMatrix::kMTransY] = -rect.fTop/rect.height();
|
|
||||||
|
|
||||||
grPaint.addColorTextureProcessor(atlas, textureMat);
|
grPaint.addColorTextureProcessor(tex, textureMat);
|
||||||
|
|
||||||
GrClip clip;
|
GrClip clip;
|
||||||
drawContext->drawRect(clip, grPaint, mat, rect);
|
fDrawContext->drawRect(clip, grPaint, mat, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if GR_GPU_STATS
|
#if GR_GPU_STATS
|
||||||
void GrGpu::Stats::dump(SkString* out) {
|
void GrGpu::Stats::dump(SkString* out) {
|
||||||
out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
|
out->appendf("Render Target Binds: %d\n", fRenderTargetBinds);
|
||||||
|
@ -140,6 +140,9 @@ public:
|
|||||||
|
|
||||||
static SkImageFilter::Cache* NewImageFilterCache();
|
static SkImageFilter::Cache* NewImageFilterCache();
|
||||||
|
|
||||||
|
// for debugging purposes only
|
||||||
|
void drawTexture(GrTexture*, const SkRect& dst, const SkPaint&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool onReadPixels(const SkImageInfo&, void*, size_t, int, int) override;
|
bool onReadPixels(const SkImageInfo&, void*, size_t, int, int) override;
|
||||||
bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
|
bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user