Pass in GrContext instead of SkGpuDevice for dashing and Sk2GrPaint conversion


BUG=skia:
R=bsalomon@google.com

Author: egdaniel@google.com

Review URL: https://codereview.chromium.org/292773002

git-svn-id: http://skia.googlecode.com/svn/trunk@14790 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index 0413299..7016b1e 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -77,21 +77,19 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-class SkGpuDevice;
-
 // Converts a SkPaint to a GrPaint, ignoring the SkPaint's shader.
 // justAlpha indicates that the SkPaint's alpha should be used rather than the color.
 // Callers may subsequently modify the GrPaint. Setting constantColor indicates
 // that the final paint will draw the same color at every pixel. This allows
 // an optimization where the the color filter can be applied to the SkPaint's
 // color once while converting to GrPaint and then ignored.
-void SkPaint2GrPaintNoShader(SkGpuDevice* dev, const SkPaint& skPaint, bool justAlpha,
+void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, bool justAlpha,
                              bool constantColor, GrPaint* grPaint);
 
 // This function is similar to skPaint2GrPaintNoShader but also converts
 // skPaint's shader to a GrTexture/GrEffectStage if possible.
 // constantColor has the same meaning as in skPaint2GrPaintNoShader.
-void SkPaint2GrPaintShader(SkGpuDevice* dev, const SkPaint& skPaint,
+void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
                            bool constantColor, GrPaint* grPaint);
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 30cae78..854839d 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -398,7 +398,7 @@
     CHECK_SHOULD_DRAW(draw, false);
 
     GrPaint grPaint;
-    SkPaint2GrPaintShader(this, paint, true, &grPaint);
+    SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
     fContext->drawPaint(grPaint);
 }
@@ -421,7 +421,7 @@
     }
 
     if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
-        if (GrDashingEffect::DrawDashLine(pts, paint, this)) {
+        if (GrDashingEffect::DrawDashLine(pts, paint, this->context())) {
             return;
         }
     }
@@ -434,7 +434,7 @@
     }
 
     GrPaint grPaint;
-    SkPaint2GrPaintShader(this, paint, true, &grPaint);
+    SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
     fContext->drawVertices(grPaint,
                            gPointMode2PrimtiveType[mode],
@@ -491,7 +491,7 @@
     }
 
     GrPaint grPaint;
-    SkPaint2GrPaintShader(this, paint, true, &grPaint);
+    SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
     if (!doStroke) {
         fContext->drawRect(grPaint, rect);
@@ -509,7 +509,7 @@
     CHECK_SHOULD_DRAW(draw, false);
 
     GrPaint grPaint;
-    SkPaint2GrPaintShader(this, paint, true, &grPaint);
+    SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
     SkStrokeRec stroke(paint);
     if (paint.getMaskFilter()) {
@@ -563,7 +563,7 @@
         CHECK_SHOULD_DRAW(draw, false);
 
         GrPaint grPaint;
-        SkPaint2GrPaintShader(this, paint, true, &grPaint);
+        SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
         if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) {
             fContext->drawDRRect(grPaint, outer, inner);
@@ -601,7 +601,7 @@
     }
 
     GrPaint grPaint;
-    SkPaint2GrPaintShader(this, paint, true, &grPaint);
+    SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
     SkStrokeRec stroke(paint);
 
     fContext->drawOval(grPaint, oval, stroke);
@@ -752,7 +752,7 @@
     CHECK_SHOULD_DRAW(draw, false);
 
     GrPaint grPaint;
-    SkPaint2GrPaintShader(this, paint, true, &grPaint);
+    SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
     // If we have a prematrix, apply it to the path, optimizing for the case
     // where the original path can in fact be modified in place (even though
@@ -1400,7 +1400,7 @@
     GrPaint grPaint;
     grPaint.addColorEffect(effect);
     bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config());
-    SkPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint);
+    SkPaint2GrPaintNoShader(this->context(), paint, alphaOnly, false, &grPaint);
 
     fContext->drawRectToRect(grPaint, dstRect, paintRect, NULL);
 }
@@ -1466,7 +1466,7 @@
     GrPaint grPaint;
     grPaint.addColorTextureEffect(texture, SkMatrix::I());
 
-    SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint);
+    SkPaint2GrPaintNoShader(this->context(), paint, true, false, &grPaint);
 
     fContext->drawRectToRect(grPaint,
                              SkRect::MakeXYWH(SkIntToScalar(left),
@@ -1574,7 +1574,7 @@
     GrPaint grPaint;
     grPaint.addColorTextureEffect(devTex, SkMatrix::I());
 
-    SkPaint2GrPaintNoShader(this, paint, true, false, &grPaint);
+    SkPaint2GrPaintNoShader(this->context(), paint, true, false, &grPaint);
 
     SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(x),
                                       SkIntToScalar(y),
@@ -1635,9 +1635,9 @@
     GrPaint grPaint;
     // we ignore the shader if texs is null.
     if (NULL == texs) {
-        SkPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPaint);
+        SkPaint2GrPaintNoShader(this->context(), paint, false, NULL == colors, &grPaint);
     } else {
-        SkPaint2GrPaintShader(this, paint, NULL == colors, &grPaint);
+        SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint);
     }
 
     if (NULL != xmode && NULL != texs && NULL != colors) {
@@ -1677,14 +1677,14 @@
 
     if (fMainTextContext->canDraw(paint)) {
         GrPaint grPaint;
-        SkPaint2GrPaintShader(this, paint, true, &grPaint);
+        SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
         SkDEBUGCODE(this->validate();)
 
         fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLength, x, y);
     } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
         GrPaint grPaint;
-        SkPaint2GrPaintShader(this, paint, true, &grPaint);
+        SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
         SkDEBUGCODE(this->validate();)
 
@@ -1703,7 +1703,7 @@
 
     if (fMainTextContext->canDraw(paint)) {
         GrPaint grPaint;
-        SkPaint2GrPaintShader(this, paint, true, &grPaint);
+        SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
         SkDEBUGCODE(this->validate();)
 
@@ -1711,7 +1711,7 @@
                                       constY, scalarsPerPos);
     } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) {
         GrPaint grPaint;
-        SkPaint2GrPaintShader(this, paint, true, &grPaint);
+        SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
 
         SkDEBUGCODE(this->validate();)
 
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 016556c..78df53e 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -8,7 +8,6 @@
 #include "SkGr.h"
 #include "SkColorFilter.h"
 #include "SkConfig8888.h"
-#include "SkGpuDevice.h"
 #include "SkMessageBus.h"
 #include "SkPixelRef.h"
 #include "GrResourceCache.h"
@@ -328,7 +327,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void SkPaint2GrPaintNoShader(SkGpuDevice* dev, const SkPaint& skPaint, bool justAlpha,
+void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, bool justAlpha,
                              bool constantColor, GrPaint* grPaint) {
 
     grPaint->setDither(skPaint.isDither());
@@ -371,7 +370,7 @@
             SkColor filtered = colorFilter->filterColor(skPaint.getColor());
             grPaint->setColor(SkColor2GrColor(filtered));
         } else {
-            SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(dev->context()));
+            SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context));
             if (NULL != effect.get()) {
                 grPaint->addColorEffect(effect);
             }
@@ -379,24 +378,24 @@
     }
 }
 
-void SkPaint2GrPaintShader(SkGpuDevice* dev, const SkPaint& skPaint,
+void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
                            bool constantColor, GrPaint* grPaint) {
     SkShader* shader = skPaint.getShader();
     if (NULL == shader) {
-        SkPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPaint);
+        SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint);
         return;
     }
 
     // SkShader::asNewEffect() may do offscreen rendering. Setup default drawing state and require
     // the shader to set a render target.
-    GrContext::AutoWideOpenIdentityDraw awo(dev->context(), NULL);
+    GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
 
     // setup the shader as the first color effect on the paint
-    SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint, NULL));
+    SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL));
     if (NULL != effect.get()) {
         grPaint->addColorEffect(effect);
         // Now setup the rest of the paint.
-        SkPaint2GrPaintNoShader(dev, skPaint, true, false, grPaint);
+        SkPaint2GrPaintNoShader(context, skPaint, true, false, grPaint);
     } else {
         // We still don't have SkColorShader::asNewEffect() implemented.
         SkShader::GradientInfo info;
@@ -411,9 +410,9 @@
             // modulate the paint alpha by the shader's solid color alpha
             U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha());
             copy.setColor(SkColorSetA(color, newA));
-            SkPaint2GrPaintNoShader(dev, copy, false, constantColor, grPaint);
+            SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint);
         } else {
-            SkPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPaint);
+            SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint);
         }
     }
 }
diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp
index 44974e8..584d509 100644
--- a/src/gpu/effects/GrDashingEffect.cpp
+++ b/src/gpu/effects/GrDashingEffect.cpp
@@ -14,7 +14,6 @@
 #include "GrDrawTargetCaps.h"
 #include "GrEffect.h"
 #include "GrTBackendEffectFactory.h"
-#include "SkGpuDevice.h"
 #include "SkGr.h"
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -87,8 +86,7 @@
 }
 
 
-bool GrDashingEffect::DrawDashLine(const SkPoint pts[2], const SkPaint& paint, SkGpuDevice* dev) {
-    GrContext* context = dev->context();
+bool GrDashingEffect::DrawDashLine(const SkPoint pts[2], const SkPaint& paint, GrContext* context) {
     if (context->getRenderTarget()->isMultisampled()) {
         return false;
     }
@@ -139,7 +137,7 @@
     }
 
     GrPaint grPaint;
-    SkPaint2GrPaintShader(dev, paint, true, &grPaint);
+    SkPaint2GrPaintShader(context, paint, true, &grPaint);
 
     bool useAA = paint.isAntiAlias();
     
diff --git a/src/gpu/effects/GrDashingEffect.h b/src/gpu/effects/GrDashingEffect.h
index a1c2829..0ed1cf0 100644
--- a/src/gpu/effects/GrDashingEffect.h
+++ b/src/gpu/effects/GrDashingEffect.h
@@ -12,13 +12,13 @@
 #include "GrTypesPriv.h"
 #include "SkPathEffect.h"
 
-class SkGpuDevice;
+class GrContext;
 
 class GrGLDashingEffect;
 class SkPath;
 
 namespace GrDashingEffect {
-    bool DrawDashLine(const SkPoint pnts[2], const SkPaint& paint, SkGpuDevice* dev);
+    bool DrawDashLine(const SkPoint pnts[2], const SkPaint& paint, GrContext* context);
 
     /**
      * An effect that renders a dashed line. It is intended to be used as a coverage effect.