Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Unified Diff: src/gpu/GrAtlasTextContext.cpp

Issue 1175553002: Make GrTextContext be owned by the GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix nvpr config Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAtlasTextContext.cpp
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index 75aaf047b5d274ba0711e4f84daf18f230b0eec6..d1076bbcd080d6c880dfada8edf041387d94edf0 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -13,6 +13,7 @@
#include "GrBlurUtils.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrDrawContext.h"
+#include "GrDrawTarget.h"
#include "GrFontScaler.h"
#include "GrIndexBuffer.h"
#include "GrResourceProvider.h"
@@ -97,9 +98,10 @@ static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
// Distance field text in textblobs
GrAtlasTextContext::GrAtlasTextContext(GrContext* context,
+ GrDrawContext* drawContext,
const SkDeviceProperties& properties,
- bool enableDistanceFields)
- : INHERITED(context, properties)
+ bool useDFT)
+ : INHERITED(context, drawContext, properties)
, fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma()))) {
// We overallocate vertices in our textblobs based on the assumption that A8 has the greatest
// vertexStride
@@ -111,7 +113,7 @@ GrAtlasTextContext::GrAtlasTextContext(GrContext* context,
#if SK_FORCE_DISTANCE_FIELD_TEXT
fEnableDFRendering = true;
#else
- fEnableDFRendering = enableDistanceFields;
+ fEnableDFRendering = useDFT;
#endif
}
@@ -198,9 +200,10 @@ void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable(float gam
}
GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context,
+ GrDrawContext* drawContext,
const SkDeviceProperties& props,
- bool enableDistanceFields) {
- return SkNEW_ARGS(GrAtlasTextContext, (context, props, enableDistanceFields));
+ bool useDFT) {
+ return SkNEW_ARGS(GrAtlasTextContext, (context, drawContext, props, useDFT));
}
bool GrAtlasTextContext::canDraw(const GrRenderTarget*,
@@ -356,11 +359,6 @@ void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt,
return;
}
- GrDrawContext* drawContext = fContext->drawContext();
- if (!drawContext) {
- return;
- }
-
SkAutoTUnref<BitmapTextBlob> cacheBlob;
SkMaskFilter::BlurRec blurRec;
BitmapTextBlob::Key key;
@@ -435,7 +433,7 @@ void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt,
}
cacheBlob->fPaintColor = skPaint.getColor();
- this->flush(drawContext, blob, cacheBlob, rt, skPaint, grPaint, drawFilter,
+ this->flush(blob, cacheBlob, rt, skPaint, grPaint, drawFilter,
clip, viewMatrix, clipBounds, x, y, transX, transY);
}
@@ -777,36 +775,32 @@ GrAtlasTextContext::createDrawPosTextBlob(GrRenderTarget* rt, const GrClip& clip
return blob;
}
-void GrAtlasTextContext::onDrawText(GrDrawContext* drawContext, GrRenderTarget* rt,
+void GrAtlasTextContext::onDrawText(GrRenderTarget* rt,
const GrClip& clip,
const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& regionClipBounds) {
- if (drawContext) {
- SkAutoTUnref<BitmapTextBlob> blob(
- this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix,
- text, byteLength, x, y, regionClipBounds));
- this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBounds);
- }
+ SkAutoTUnref<BitmapTextBlob> blob(
+ this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix,
+ text, byteLength, x, y, regionClipBounds));
+ this->flush(blob, rt, skPaint, paint, clip, regionClipBounds);
}
-void GrAtlasTextContext::onDrawPosText(GrDrawContext* drawContext, GrRenderTarget* rt,
+void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt,
const GrClip& clip,
const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& regionClipBounds) {
- if (drawContext) {
- SkAutoTUnref<BitmapTextBlob> blob(
- this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix,
- text, byteLength,
- pos, scalarsPerPosition,
- offset, regionClipBounds));
+ SkAutoTUnref<BitmapTextBlob> blob(
+ this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix,
+ text, byteLength,
+ pos, scalarsPerPosition,
+ offset, regionClipBounds));
- this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBounds);
- }
+ this->flush(blob, rt, skPaint, paint, clip, regionClipBounds);
}
void GrAtlasTextContext::internalDrawBMPText(BitmapTextBlob* blob, int runIndex,
@@ -2045,8 +2039,7 @@ private:
float fGamma;
};
-void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* drawContext,
- GrRenderTarget* rt, const SkTextBlob::RunIterator& it,
+void GrAtlasTextContext::flushRunAsPaths(GrRenderTarget* rt, const SkTextBlob::RunIterator& it,
const GrClip& clip, const SkPaint& skPaint,
SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
const SkIRect& clipBounds, SkScalar x, SkScalar y) {
@@ -2065,18 +2058,18 @@ void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* drawContext,
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
- this->drawTextAsPath(drawContext, rt, clip, runPaint, viewMatrix,
+ this->drawTextAsPath(rt, clip, runPaint, viewMatrix,
(const char *)it.glyphs(),
textLen, x + offset.x(), y + offset.y(), clipBounds);
break;
case SkTextBlob::kHorizontal_Positioning:
- this->drawPosTextAsPath(drawContext, rt, clip, runPaint, viewMatrix,
+ this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix,
(const char*)it.glyphs(),
textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
clipBounds);
break;
case SkTextBlob::kFull_Positioning:
- this->drawPosTextAsPath(drawContext, rt, clip, runPaint, viewMatrix,
+ this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix,
(const char*)it.glyphs(),
textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
break;
@@ -2128,8 +2121,7 @@ GrAtlasTextContext::createBatch(BitmapTextBlob* cacheBlob, const PerSubRunInfo&
return batch;
}
-inline void GrAtlasTextContext::flushRun(GrDrawContext* drawContext,
- GrPipelineBuilder* pipelineBuilder,
+inline void GrAtlasTextContext::flushRun(GrPipelineBuilder* pipelineBuilder,
BitmapTextBlob* cacheBlob, int run, GrColor color,
SkScalar transX, SkScalar transY,
const SkPaint& skPaint) {
@@ -2143,12 +2135,11 @@ inline void GrAtlasTextContext::flushRun(GrDrawContext* drawContext,
SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, glyphCount, run,
subRun, color, transX, transY,
skPaint));
- drawContext->drawText(pipelineBuilder, batch);
+ fDrawContext->drawBatch(pipelineBuilder, batch);
}
}
-inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob,
- GrDrawContext* drawContext, GrRenderTarget* rt,
+inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt,
const GrClip& clip, const SkPaint& skPaint,
SkScalar transX, SkScalar transY,
const SkIRect& clipBounds) {
@@ -2169,13 +2160,12 @@ inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob,
SkMatrix translate = cacheBlob->fViewMatrix;
translate.postTranslate(bigGlyph.fVx, bigGlyph.fVy);
- GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, clip, bigGlyph.fPath,
+ GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt, clip, bigGlyph.fPath,
skPaint, translate, &pathMatrix, clipBounds, false);
}
}
-void GrAtlasTextContext::flush(GrDrawContext* drawContext,
- const SkTextBlob* blob,
+void GrAtlasTextContext::flush(const SkTextBlob* blob,
BitmapTextBlob* cacheBlob,
GrRenderTarget* rt,
const SkPaint& skPaint,
@@ -2196,21 +2186,20 @@ void GrAtlasTextContext::flush(GrDrawContext* drawContext,
SkTextBlob::RunIterator it(blob);
for (int run = 0; !it.done(); it.next(), run++) {
if (cacheBlob->fRuns[run].fDrawAsPaths) {
- this->flushRunAsPaths(drawContext, rt, it, clip, skPaint,
+ this->flushRunAsPaths(rt, it, clip, skPaint,
drawFilter, viewMatrix, clipBounds, x, y);
continue;
}
cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY);
- this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color,
+ this->flushRun(&pipelineBuilder, cacheBlob, run, color,
transX, transY, skPaint);
}
// Now flush big glyphs
- this->flushBigGlyphs(cacheBlob, drawContext, rt, clip, skPaint, transX, transY, clipBounds);
+ this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, transX, transY, clipBounds);
}
-void GrAtlasTextContext::flush(GrDrawContext* drawContext,
- BitmapTextBlob* cacheBlob,
+void GrAtlasTextContext::flush(BitmapTextBlob* cacheBlob,
GrRenderTarget* rt,
const SkPaint& skPaint,
const GrPaint& grPaint,
@@ -2221,11 +2210,11 @@ void GrAtlasTextContext::flush(GrDrawContext* drawContext,
GrColor color = grPaint.getColor();
for (int run = 0; run < cacheBlob->fRunCount; run++) {
- this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint);
+ this->flushRun(&pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint);
}
// Now flush big glyphs
- this->flushBigGlyphs(cacheBlob, drawContext, rt, clip, skPaint, 0, 0, clipBounds);
+ this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, 0, 0, clipBounds);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -2235,15 +2224,19 @@ void GrAtlasTextContext::flush(GrDrawContext* drawContext,
BATCH_TEST_DEFINE(TextBlobBatch) {
static uint32_t gContextID = SK_InvalidGenID;
static GrAtlasTextContext* gTextContext = NULL;
- static SkDeviceProperties gDeviceProperties(SkDeviceProperties::kLegacyLCD_InitType);
+ static SkDeviceProperties gDevProperties;
if (context->uniqueID() != gContextID) {
gContextID = context->uniqueID();
SkDELETE(gTextContext);
+
+ static const bool kUseDFT = false;
// We don't yet test the fall back to paths in the GrTextContext base class. This is mostly
// because we don't really want to have a gpu device here.
// We enable distance fields by twiddling a knob on the paint
- gTextContext = GrAtlasTextContext::Create(context, gDeviceProperties, false);
+ GrDrawContext* drawContext = context->drawContext(&gDevProperties, kUseDFT);
+
+ gTextContext = GrAtlasTextContext::Create(context, drawContext, gDevProperties, kUseDFT);
}
// create dummy render target
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698