Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / GrDistanceFieldTextContext.cpp
index 4c9631e..bd3927c 100755 (executable)
@@ -13,6 +13,8 @@
 #include "GrIndexBuffer.h"
 #include "GrTextStrike.h"
 #include "GrTextStrike_impl.h"
+#include "SkDraw.h"
+#include "SkGpuDevice.h"
 #include "SkPath.h"
 #include "SkRTConf.h"
 #include "SkStrokeRec.h"
@@ -26,9 +28,8 @@ SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
                 "Dump the contents of the font cache before every purge.");
 
 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
-                                                       const GrPaint& grPaint,
-                                                       const SkPaint& skPaint)
-                                                     : GrTextContext(context, grPaint, skPaint) {
+                                                       const SkDeviceProperties& properties)
+                                                    : GrTextContext(context, properties) {
     fStrike = NULL;
 
     fCurrTexture = NULL;
@@ -36,19 +37,18 @@ GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
 
     fVertices = NULL;
     fMaxVertices = 0;
-
-    fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize;
-
-    fSkPaint.setTextSize(SkIntToScalar(kBaseDFFontSize));
-    fSkPaint.setLCDRenderText(false);
-    fSkPaint.setAutohinted(false);
-    fSkPaint.setSubpixelText(false);
 }
 
 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
     this->flushGlyphs();
 }
 
+bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
+    return !paint.getRasterizer() && !paint.getMaskFilter() &&
+           paint.getStyle() == SkPaint::kFill_Style &&
+           !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix());
+}
+
 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
     unsigned r = SkColorGetR(c);
     unsigned g = SkColorGetG(c);
@@ -282,20 +282,52 @@ HAS_ATLAS:
     fCurrVertex += 4;
 }
 
-void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength,
-                                          SkScalar x, SkScalar y, SkGlyphCache* cache,
-                                          GrFontScaler* fontScaler) {
+inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
+    GrTextContext::init(paint, skPaint);
+
+    fStrike = NULL;
+
+    fCurrTexture = NULL;
+    fCurrVertex = 0;
+
+    fVertices = NULL;
+    fMaxVertices = 0;
+
+    fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize;
+
+    fSkPaint.setTextSize(SkIntToScalar(kBaseDFFontSize));
+    fSkPaint.setLCDRenderText(false);
+    fSkPaint.setAutohinted(false);
+    fSkPaint.setSubpixelText(false);
+}
+
+inline void GrDistanceFieldTextContext::finish() {
+    flushGlyphs();
+
+    GrTextContext::finish();
+}
+
+void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
+                                          const char text[], size_t byteLength,
+                                          SkScalar x, SkScalar y) {
     SkASSERT(byteLength == 0 || text != NULL);
 
-    // nothing to draw
-    if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
+    // nothing to draw or can't draw
+    if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/
+        || fSkPaint.getRasterizer()) {
         return;
     }
 
+    this->init(paint, skPaint);
+
     SkScalar sizeRatio = fTextRatio;
 
     SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
 
+    SkAutoGlyphCache    autoCache(fSkPaint, &fDeviceProperties, NULL);
+    SkGlyphCache*       cache = autoCache.getCache();
+    GrFontScaler*       fontScaler = GetGrFontScaler(cache);
+
     // need to measure first
     // TODO - generate positions and pre-load cache as well?
     const char* stop = text + byteLength;
@@ -344,12 +376,14 @@ void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength,
         fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale);
         fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale);
     }
+
+    this->finish();
 }
 
-void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLength,
+void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
+                                             const char text[], size_t byteLength,
                                              const SkScalar pos[], SkScalar constY,
-                                             int scalarsPerPosition,
-                                             SkGlyphCache* cache, GrFontScaler* fontScaler) {
+                                             int scalarsPerPosition) {
 
     SkASSERT(byteLength == 0 || text != NULL);
     SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@@ -359,8 +393,14 @@ void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLengt
         return;
     }
 
+    this->init(paint, skPaint);
+
     SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
 
+    SkAutoGlyphCache    autoCache(fSkPaint, &fDeviceProperties, NULL);
+    SkGlyphCache*       cache = autoCache.getCache();
+    GrFontScaler*       fontScaler = GetGrFontScaler(cache);
+
     const char*        stop = text + byteLength;
 
     if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) {
@@ -403,4 +443,6 @@ void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLengt
             pos += scalarsPerPosition;
         }
     }
+
+    this->finish();
 }