Rename GrDrawContext to GrRenderTargetContext

This is in preparation for GrTextureContext and GrSurfaceContext

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4030

Change-Id: Ie58c93052e68f3f1f5fe8d15d63760de274a6fbd
Reviewed-on: https://skia-review.googlesource.com/4030
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Osman 2016-10-27 14:47:55 -04:00 committed by Skia Commit-Bot
parent 6e74412a9c
commit 1105224f97
107 changed files with 1693 additions and 1579 deletions

View File

@ -11,7 +11,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrPathUtils.h" #include "GrPathUtils.h"
#include "GrTest.h" #include "GrTest.h"
@ -99,8 +99,9 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -121,8 +122,8 @@ protected:
// Mult by 3 for each edge effect type // Mult by 3 for each edge effect type
int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3))); int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3)));
int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols); int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols);
SkScalar w = SkIntToScalar(drawContext->width()) / numCols; SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols;
SkScalar h = SkIntToScalar(drawContext->height()) / numRows; SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows;
int row = 0; int row = 0;
int col = 0; int col = 0;
constexpr GrColor color = 0xff000000; constexpr GrColor color = 0xff000000;
@ -194,7 +195,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
new BezierCubicOrConicTestBatch(gp, bounds, color, klmEqs, klmSigns[c])); new BezierCubicOrConicTestBatch(gp, bounds, color, klmEqs, klmSigns[c]));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
} }
++col; ++col;
if (numCols == col) { if (numCols == col) {
@ -231,8 +233,9 @@ protected:
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -253,8 +256,8 @@ protected:
// Mult by 3 for each edge effect type // Mult by 3 for each edge effect type
int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3))); int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3)));
int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols); int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols);
SkScalar w = SkIntToScalar(drawContext->width()) / numCols; SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols;
SkScalar h = SkIntToScalar(drawContext->height()) / numRows; SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows;
int row = 0; int row = 0;
int col = 0; int col = 0;
constexpr GrColor color = 0xff000000; constexpr GrColor color = 0xff000000;
@ -325,7 +328,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
new BezierCubicOrConicTestBatch(gp, bounds, color, klmEqs, 1.f)); new BezierCubicOrConicTestBatch(gp, bounds, color, klmEqs, 1.f));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
} }
++col; ++col;
if (numCols == col) { if (numCols == col) {
@ -445,8 +449,9 @@ protected:
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -466,8 +471,8 @@ protected:
int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3))); int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3)));
int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols); int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols);
SkScalar w = SkIntToScalar(drawContext->width()) / numCols; SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols;
SkScalar h = SkIntToScalar(drawContext->height()) / numRows; SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows;
int row = 0; int row = 0;
int col = 0; int col = 0;
constexpr GrColor color = 0xff000000; constexpr GrColor color = 0xff000000;
@ -536,7 +541,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
new BezierQuadTestBatch(gp, bounds, color, DevToUV)); new BezierQuadTestBatch(gp, bounds, color, DevToUV));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
} }
++col; ++col;
if (numCols == col) { if (numCols == col) {

View File

@ -8,7 +8,7 @@
#include "gm.h" #include "gm.h"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "SkRRect.h" #include "SkRRect.h"
#include "batches/GrDrawBatch.h" #include "batches/GrDrawBatch.h"
#include "batches/GrRectBatchFactory.h" #include "batches/GrRectBatchFactory.h"
@ -48,8 +48,9 @@ protected:
SkISize onISize() override { return SkISize::Make(fWidth, fHeight); } SkISize onISize() override { return SkISize::Make(fWidth, fHeight); }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -89,7 +90,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
GrRectBatchFactory::CreateNonAAFill(0xff000000, SkMatrix::I(), bounds, GrRectBatchFactory::CreateNonAAFill(0xff000000, SkMatrix::I(), bounds,
nullptr, nullptr)); nullptr, nullptr));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
} }
canvas->restore(); canvas->restore();
x = x + fTestOffsetX; x = x + fTestOffsetX;

View File

@ -12,7 +12,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "SkGrPriv.h" #include "SkGrPriv.h"
#include "SkGradientShader.h" #include "SkGradientShader.h"
#include "batches/GrDrawBatch.h" #include "batches/GrDrawBatch.h"
@ -46,8 +46,9 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -99,8 +100,8 @@ protected:
} else { } else {
skPaint.setColor(kPaintColors[paintType]); skPaint.setColor(kPaintColors[paintType]);
} }
SkAssertResult(SkPaintToGrPaint(context, drawContext, skPaint, viewMatrix, SkAssertResult(SkPaintToGrPaint(context, renderTargetContext, skPaint,
&grPaint)); viewMatrix, &grPaint));
GrConstColorProcessor::InputMode mode = (GrConstColorProcessor::InputMode) m; GrConstColorProcessor::InputMode mode = (GrConstColorProcessor::InputMode) m;
GrColor4f color = GrColor4f::FromGrColor(kColors[procColor]); GrColor4f color = GrColor4f::FromGrColor(kColors[procColor]);
@ -111,7 +112,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
GrRectBatchFactory::CreateNonAAFill(grPaint.getColor(), viewMatrix, GrRectBatchFactory::CreateNonAAFill(grPaint.getColor(), viewMatrix,
renderRect, nullptr, nullptr)); renderRect, nullptr, nullptr));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
// Draw labels for the input to the processor and the processor to the right of // Draw labels for the input to the processor and the processor to the right of
// the test rect. The input label appears above the processor label. // the test rect. The input label appears above the processor label.

View File

@ -13,7 +13,7 @@
#include "GrContext.h" #include "GrContext.h"
#include "GrDefaultGeoProcFactory.h" #include "GrDefaultGeoProcFactory.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrPathUtils.h" #include "GrPathUtils.h"
#include "GrTest.h" #include "GrTest.h"
#include "SkColorPriv.h" #include "SkColorPriv.h"
@ -153,8 +153,9 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -184,7 +185,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch(new PolyBoundsBatch(p.getBounds(), 0xff000000)); SkAutoTUnref<GrDrawBatch> batch(new PolyBoundsBatch(p.getBounds(), 0xff000000));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
x += SkScalarCeilToScalar(path->getBounds().width() + kDX); x += SkScalarCeilToScalar(path->getBounds().width() + kDX);
} }
@ -223,7 +225,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch(new PolyBoundsBatch(rect, 0xff000000)); SkAutoTUnref<GrDrawBatch> batch(new PolyBoundsBatch(rect, 0xff000000));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
x += SkScalarCeilToScalar(rect.width() + kDX); x += SkScalarCeilToScalar(rect.width() + kDX);
} }

View File

@ -16,8 +16,9 @@ namespace skiagm {
constexpr SkRect kSrcImageClip{75, 75, 275, 275}; constexpr SkRect kSrcImageClip{75, 75, 275, 275};
/* /*
* The purpose of this test is to exercise all three codepaths in GrDrawContext (drawFilledRect, * The purpose of this test is to exercise all three codepaths in GrRenderTargetContext
* fillRectToRect, fillRectWithLocalMatrix) that pre-crop filled rects based on the clip. * (drawFilledRect, fillRectToRect, fillRectWithLocalMatrix) that pre-crop filled rects based on the
* clip.
* *
* The test creates an image of a green square surrounded by red background, then draws this image * The test creates an image of a green square surrounded by red background, then draws this image
* in various ways with the red clipped out. The test is successful if there is no visible red * in various ways with the red clipped out. The test is successful if there is no visible red
@ -54,7 +55,7 @@ private:
canvas->clear(SK_ColorWHITE); canvas->clear(SK_ColorWHITE);
{ {
// GrDrawContext::drawFilledRect. // GrRenderTargetContext::drawFilledRect.
SkAutoCanvasRestore acr(canvas, true); SkAutoCanvasRestore acr(canvas, true);
SkPaint paint; SkPaint paint;
paint.setShader(fSrcImageShader); paint.setShader(fSrcImageShader);
@ -64,7 +65,7 @@ private:
} }
{ {
// GrDrawContext::fillRectToRect. // GrRenderTargetContext::fillRectToRect.
SkAutoCanvasRestore acr(canvas, true); SkAutoCanvasRestore acr(canvas, true);
SkPaint paint; SkPaint paint;
paint.setFilterQuality(kNone_SkFilterQuality); paint.setFilterQuality(kNone_SkFilterQuality);
@ -78,7 +79,7 @@ private:
} }
{ {
// GrDrawContext::fillRectWithLocalMatrix. // GrRenderTargetContext::fillRectWithLocalMatrix.
SkAutoCanvasRestore acr(canvas, true); SkAutoCanvasRestore acr(canvas, true);
SkPath path; SkPath path;
path.moveTo(kSrcImageClip.fLeft - kSrcImageClip.width(), kSrcImageClip.centerY()); path.moveTo(kSrcImageClip.fLeft - kSrcImageClip.width(), kSrcImageClip.centerY());

View File

@ -64,8 +64,9 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }

View File

@ -186,8 +186,9 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }

View File

@ -9,7 +9,8 @@
#include "SkPath.h" #include "SkPath.h"
#include "SkGradientShader.h" #include "SkGradientShader.h"
// Exercises code in GrDrawContext that attempts to replace a rrect clip/draw paint with draw rrect. // Exercises code in GrRenderTargetContext that attempts to replace a rrect clip/draw paint with
// draw rrect.
DEF_SIMPLE_GM(rrect_clip_draw_paint, canvas, 256, 256) { DEF_SIMPLE_GM(rrect_clip_draw_paint, canvas, 256, 256) {
SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(10.f, 10.f, 236.f, 236.f), 30.f, 40.f); SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(10.f, 10.f, 236.f, 236.f), 30.f, 40.f);

View File

@ -8,7 +8,7 @@
#include "gm.h" #include "gm.h"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "batches/GrDrawBatch.h" #include "batches/GrDrawBatch.h"
#include "batches/GrRectBatchFactory.h" #include "batches/GrRectBatchFactory.h"
#include "effects/GrRRectEffect.h" #include "effects/GrRRectEffect.h"
@ -62,8 +62,9 @@ protected:
SkISize onISize() override { return SkISize::Make(kImageWidth, kImageHeight); } SkISize onISize() override { return SkISize::Make(kImageWidth, kImageHeight); }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (kEffect_Type == fType && !drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (kEffect_Type == fType && !renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -117,7 +118,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
GrRectBatchFactory::CreateNonAAFill(0xff000000, SkMatrix::I(), GrRectBatchFactory::CreateNonAAFill(0xff000000, SkMatrix::I(),
bounds, nullptr, nullptr)); bounds, nullptr, nullptr));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(
grPaint, batch);
} else { } else {
drew = false; drew = false;
} }

View File

@ -11,7 +11,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "SkColorPriv.h" #include "SkColorPriv.h"
#include "effects/GrPorterDuffXferProcessor.h" #include "effects/GrPorterDuffXferProcessor.h"
@ -20,8 +20,9 @@
constexpr int S = 200; constexpr int S = 200;
DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) { DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -101,7 +102,7 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
tm.postIDiv(2*S, 2*S); tm.postIDiv(2*S, 2*S);
paint.addColorTextureProcessor(texture, nullptr, tm); paint.addColorTextureProcessor(texture, nullptr, tm);
drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S)); renderTargetContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
// now update the lower right of the texture in first pass // now update the lower right of the texture in first pass
// or upper right in second pass // or upper right in second pass
@ -115,7 +116,7 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
texture->writePixels(S, (i ? 0 : S), S, S, texture->writePixels(S, (i ? 0 : S), S, S,
texture->config(), gTextureData.get(), texture->config(), gTextureData.get(),
4 * stride); 4 * stride);
drawContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S)); renderTargetContext->drawRect(clip, paint, vm, SkRect::MakeWH(2*S, 2*S));
} }
} }
#endif #endif

View File

@ -11,7 +11,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrContext.h" #include "GrContext.h"
#include "SkBitmap.h" #include "SkBitmap.h"
#include "SkGr.h" #include "SkGr.h"
@ -70,8 +70,9 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -129,7 +130,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
GrRectBatchFactory::CreateNonAAFill(GrColor_WHITE, viewMatrix, GrRectBatchFactory::CreateNonAAFill(GrColor_WHITE, viewMatrix,
renderRect, nullptr, nullptr)); renderRect, nullptr, nullptr));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
x += renderRect.width() + kTestPad; x += renderRect.width() + kTestPad;
} }
y += renderRect.height() + kTestPad; y += renderRect.height() + kTestPad;

View File

@ -11,8 +11,8 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
# include "GrAppliedClip.h" # include "GrAppliedClip.h"
# include "GrDrawContext.h" # include "GrRenderTargetContext.h"
# include "GrDrawContextPriv.h" # include "GrRenderTargetContextPriv.h"
# include "GrFixedClip.h" # include "GrFixedClip.h"
# include "GrReducedClip.h" # include "GrReducedClip.h"
# include "GrRenderTargetPriv.h" # include "GrRenderTargetPriv.h"
@ -127,9 +127,11 @@ private:
constexpr static int kMaskCheckerSize = 5; constexpr static int kMaskCheckerSize = 5;
SkString onShortName() final { return SkString("windowrectangles_mask"); } SkString onShortName() final { return SkString("windowrectangles_mask"); }
void onCoverClipStack(const SkClipStack&, SkCanvas*) final; void onCoverClipStack(const SkClipStack&, SkCanvas*) final;
void visualizeAlphaMask(GrContext*, GrDrawContext*, const GrReducedClip&, const GrPaint&); void visualizeAlphaMask(GrContext*, GrRenderTargetContext*, const GrReducedClip&,
void visualizeStencilMask(GrContext*, GrDrawContext*, const GrReducedClip&, const GrPaint&); const GrPaint&);
void stencilCheckerboard(GrDrawContext*, bool flip); void visualizeStencilMask(GrContext*, GrRenderTargetContext*, const GrReducedClip&,
const GrPaint&);
void stencilCheckerboard(GrRenderTargetContext*, bool flip);
void fail(SkCanvas*); void fail(SkCanvas*);
}; };
@ -158,7 +160,7 @@ public:
fFP = GrDeviceSpaceTextureDecalFragmentProcessor::Make(mask, SkIRect::MakeWH(w, h), {x, y}); fFP = GrDeviceSpaceTextureDecalFragmentProcessor::Make(mask, SkIRect::MakeWH(w, h), {x, y});
} }
private: private:
bool apply(GrContext*, GrDrawContext*, bool, bool, GrAppliedClip* out) const override { bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip* out) const override {
out->addCoverageFP(fFP); out->addCoverageFP(fFP);
return true; return true;
} }
@ -170,7 +172,7 @@ private:
*/ */
class StencilOnlyClip final : public MaskOnlyClipBase { class StencilOnlyClip final : public MaskOnlyClipBase {
private: private:
bool apply(GrContext*, GrDrawContext*, bool, bool, GrAppliedClip* out) const override { bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip* out) const override {
out->addStencilClip(); out->addStencilClip();
return true; return true;
} }
@ -178,10 +180,10 @@ private:
void WindowRectanglesMaskGM::onCoverClipStack(const SkClipStack& stack, SkCanvas* canvas) { void WindowRectanglesMaskGM::onCoverClipStack(const SkClipStack& stack, SkCanvas* canvas) {
GrContext* ctx = canvas->getGrContext(); GrContext* ctx = canvas->getGrContext();
GrDrawContext* dc = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext();
if (!ctx || !dc || if (!ctx || !rtc ||
dc->accessRenderTarget()->renderTargetPriv().maxWindowRectangles() < kNumWindows) { rtc->accessRenderTarget()->renderTargetPriv().maxWindowRectangles() < kNumWindows) {
this->fail(canvas); this->fail(canvas);
return; return;
} }
@ -190,21 +192,22 @@ void WindowRectanglesMaskGM::onCoverClipStack(const SkClipStack& stack, SkCanvas
GrPaint paint; GrPaint paint;
paint.setAntiAlias(true); paint.setAntiAlias(true);
if (!dc->isStencilBufferMultisampled()) { if (!rtc->isStencilBufferMultisampled()) {
paint.setColor4f(GrColor4f(0, 0.25f, 1, 1)); paint.setColor4f(GrColor4f(0, 0.25f, 1, 1));
this->visualizeAlphaMask(ctx, dc, reducedClip, paint); this->visualizeAlphaMask(ctx, rtc, reducedClip, paint);
} else { } else {
paint.setColor4f(GrColor4f(1, 0.25f, 0.25f, 1)); paint.setColor4f(GrColor4f(1, 0.25f, 0.25f, 1));
this->visualizeStencilMask(ctx, dc, reducedClip, paint); this->visualizeStencilMask(ctx, rtc, reducedClip, paint);
} }
} }
void WindowRectanglesMaskGM::visualizeAlphaMask(GrContext* ctx, GrDrawContext* dc, void WindowRectanglesMaskGM::visualizeAlphaMask(GrContext* ctx, GrRenderTargetContext* rtc,
const GrReducedClip& reducedClip, const GrReducedClip& reducedClip,
const GrPaint& paint) { const GrPaint& paint) {
sk_sp<GrDrawContext> maskDC( sk_sp<GrRenderTargetContext> maskDC(
ctx->makeDrawContextWithFallback(SkBackingFit::kExact, kLayerRect.width(), ctx->makeRenderTargetContextWithFallback(SkBackingFit::kExact, kLayerRect.width(),
kLayerRect.height(), kAlpha_8_GrPixelConfig, nullptr)); kLayerRect.height(), kAlpha_8_GrPixelConfig,
nullptr));
if (!maskDC || if (!maskDC ||
!ctx->resourceProvider()->attachStencilAttachment(maskDC->accessRenderTarget())) { !ctx->resourceProvider()->attachStencilAttachment(maskDC->accessRenderTarget())) {
return; return;
@ -214,10 +217,12 @@ void WindowRectanglesMaskGM::visualizeAlphaMask(GrContext* ctx, GrDrawContext* d
// the clip mask generation. // the clip mask generation.
this->stencilCheckerboard(maskDC.get(), true); this->stencilCheckerboard(maskDC.get(), true);
maskDC->clear(nullptr, GrColorPackA4(0xff), true); maskDC->clear(nullptr, GrColorPackA4(0xff), true);
maskDC->drawContextPriv().drawAndStencilRect(StencilOnlyClip(), &GrUserStencilSettings::kUnused, maskDC->renderTargetContextPriv().drawAndStencilRect(StencilOnlyClip(),
SkRegion::kDifference_Op, false, false, &GrUserStencilSettings::kUnused,
SkMatrix::I(), SkRegion::kDifference_Op, false, false,
SkRect::MakeIWH(maskDC->width(), maskDC->height())); SkMatrix::I(),
SkRect::MakeIWH(maskDC->width(),
maskDC->height()));
reducedClip.drawAlphaClipMask(maskDC.get()); reducedClip.drawAlphaClipMask(maskDC.get());
sk_sp<GrTexture> mask(maskDC->asTexture()); sk_sp<GrTexture> mask(maskDC->asTexture());
@ -228,29 +233,29 @@ void WindowRectanglesMaskGM::visualizeAlphaMask(GrContext* ctx, GrDrawContext* d
// inside window rectangles or outside the scissor should still have the initial checkerboard // inside window rectangles or outside the scissor should still have the initial checkerboard
// intact. (This verifies we didn't spend any time modifying those pixels in the mask.) // intact. (This verifies we didn't spend any time modifying those pixels in the mask.)
AlphaOnlyClip clip(mask.get(), x, y); AlphaOnlyClip clip(mask.get(), x, y);
dc->drawRect(clip, paint, SkMatrix::I(), rtc->drawRect(clip, paint, SkMatrix::I(),
SkRect::Make(SkIRect::MakeXYWH(x, y, mask->width(), mask->height()))); SkRect::Make(SkIRect::MakeXYWH(x, y, mask->width(), mask->height())));
} }
void WindowRectanglesMaskGM::visualizeStencilMask(GrContext* ctx, GrDrawContext* dc, void WindowRectanglesMaskGM::visualizeStencilMask(GrContext* ctx, GrRenderTargetContext* rtc,
const GrReducedClip& reducedClip, const GrReducedClip& reducedClip,
const GrPaint& paint) { const GrPaint& paint) {
if (!ctx->resourceProvider()->attachStencilAttachment(dc->accessRenderTarget())) { if (!ctx->resourceProvider()->attachStencilAttachment(rtc->accessRenderTarget())) {
return; return;
} }
// Draw a checker pattern into the stencil buffer so we can visualize the regions left untouched // Draw a checker pattern into the stencil buffer so we can visualize the regions left untouched
// by the clip mask generation. // by the clip mask generation.
this->stencilCheckerboard(dc, false); this->stencilCheckerboard(rtc, false);
reducedClip.drawStencilClipMask(ctx, dc, {kLayerRect.x(), kLayerRect.y()}); reducedClip.drawStencilClipMask(ctx, rtc, {kLayerRect.x(), kLayerRect.y()});
// Now visualize the stencil mask by covering the entire render target. The regions inside // Now visualize the stencil mask by covering the entire render target. The regions inside
// window rectangless or outside the scissor should still have the initial checkerboard intact. // window rectangless or outside the scissor should still have the initial checkerboard intact.
// (This verifies we didn't spend any time modifying those pixels in the mask.) // (This verifies we didn't spend any time modifying those pixels in the mask.)
dc->drawPaint(StencilOnlyClip(), paint, SkMatrix::I()); rtc->drawPaint(StencilOnlyClip(), paint, SkMatrix::I());
} }
void WindowRectanglesMaskGM::stencilCheckerboard(GrDrawContext* dc, bool flip) { void WindowRectanglesMaskGM::stencilCheckerboard(GrRenderTargetContext* rtc, bool flip) {
constexpr static GrUserStencilSettings kSetClip( constexpr static GrUserStencilSettings kSetClip(
GrUserStencilSettings::StaticInit< GrUserStencilSettings::StaticInit<
0, 0,
@ -261,14 +266,14 @@ void WindowRectanglesMaskGM::stencilCheckerboard(GrDrawContext* dc, bool flip) {
0>() 0>()
); );
dc->drawContextPriv().clearStencilClip(GrFixedClip::Disabled(), false); rtc->renderTargetContextPriv().clearStencilClip(GrFixedClip::Disabled(), false);
for (int y = 0; y < kLayerRect.height(); y += kMaskCheckerSize) { for (int y = 0; y < kLayerRect.height(); y += kMaskCheckerSize) {
for (int x = (y & 1) == flip ? 0 : kMaskCheckerSize; for (int x = (y & 1) == flip ? 0 : kMaskCheckerSize;
x < kLayerRect.width(); x += 2 * kMaskCheckerSize) { x < kLayerRect.width(); x += 2 * kMaskCheckerSize) {
SkIRect checker = SkIRect::MakeXYWH(x, y, kMaskCheckerSize, kMaskCheckerSize); SkIRect checker = SkIRect::MakeXYWH(x, y, kMaskCheckerSize, kMaskCheckerSize);
dc->drawContextPriv().stencilRect(GrNoClip(), &kSetClip, false, SkMatrix::I(), rtc->renderTargetContextPriv().stencilRect(GrNoClip(), &kSetClip, false, SkMatrix::I(),
SkRect::Make(checker)); SkRect::Make(checker));
} }
} }
} }

View File

@ -12,7 +12,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "SkBitmap.h" #include "SkBitmap.h"
#include "SkGr.h" #include "SkGr.h"
#include "SkGradientShader.h" #include "SkGradientShader.h"
@ -68,8 +68,9 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -124,7 +125,8 @@ protected:
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
GrRectBatchFactory::CreateNonAAFill(GrColor_WHITE, viewMatrix, GrRectBatchFactory::CreateNonAAFill(GrColor_WHITE, viewMatrix,
renderRect, nullptr, nullptr)); renderRect, nullptr, nullptr));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
} }
x += renderRect.width() + kTestPad; x += renderRect.width() + kTestPad;
} }
@ -188,8 +190,9 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* renderTargetContext =
if (!drawContext) { canvas->internal_private_accessTopLayerRenderTargetContext();
if (!renderTargetContext) {
skiagm::GM::DrawGpuOnlyMessage(canvas); skiagm::GM::DrawGpuOnlyMessage(canvas);
return; return;
} }
@ -235,7 +238,8 @@ protected:
grPaint.addColorFragmentProcessor(fp); grPaint.addColorFragmentProcessor(fp);
SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill( SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(
GrColor_WHITE, viewMatrix, renderRect, nullptr, nullptr)); GrColor_WHITE, viewMatrix, renderRect, nullptr, nullptr));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint,
batch);
} }
} }
} }

View File

@ -19,7 +19,6 @@ skia_gpu_sources = [
"$_include/gpu/GrContextOptions.h", "$_include/gpu/GrContextOptions.h",
"$_include/gpu/GrContext.h", "$_include/gpu/GrContext.h",
"$_include/gpu/GrCoordTransform.h", "$_include/gpu/GrCoordTransform.h",
"$_include/gpu/GrDrawContext.h",
"$_include/gpu/GrFragmentProcessor.h", "$_include/gpu/GrFragmentProcessor.h",
"$_include/gpu/GrGpuResource.h", "$_include/gpu/GrGpuResource.h",
"$_include/gpu/GrInvariantOutput.h", "$_include/gpu/GrInvariantOutput.h",
@ -29,6 +28,7 @@ skia_gpu_sources = [
"$_include/gpu/GrProgramElement.h", "$_include/gpu/GrProgramElement.h",
"$_include/gpu/GrGpuResourceRef.h", "$_include/gpu/GrGpuResourceRef.h",
"$_include/gpu/GrRenderTarget.h", "$_include/gpu/GrRenderTarget.h",
"$_include/gpu/GrRenderTargetContext.h",
"$_include/gpu/GrResourceKey.h", "$_include/gpu/GrResourceKey.h",
"$_include/gpu/GrShaderVar.h", "$_include/gpu/GrShaderVar.h",
"$_include/gpu/GrSurface.h", "$_include/gpu/GrSurface.h",
@ -89,10 +89,6 @@ skia_gpu_sources = [
"$_src/gpu/GrCoordTransform.cpp", "$_src/gpu/GrCoordTransform.cpp",
"$_src/gpu/GrDefaultGeoProcFactory.cpp", "$_src/gpu/GrDefaultGeoProcFactory.cpp",
"$_src/gpu/GrDefaultGeoProcFactory.h", "$_src/gpu/GrDefaultGeoProcFactory.h",
"$_src/gpu/GrDrawContext.cpp",
"$_src/gpu/GrDrawContextPriv.h",
"$_src/gpu/GrPathRenderingDrawContext.cpp",
"$_src/gpu/GrPathRenderingDrawContext.h",
"$_src/gpu/GrDrawingManager.cpp", "$_src/gpu/GrDrawingManager.cpp",
"$_src/gpu/GrDrawingManager.h", "$_src/gpu/GrDrawingManager.h",
"$_src/gpu/GrFixedClip.cpp", "$_src/gpu/GrFixedClip.cpp",
@ -162,6 +158,10 @@ skia_gpu_sources = [
"$_src/gpu/GrRenderTargetProxy.cpp", "$_src/gpu/GrRenderTargetProxy.cpp",
"$_src/gpu/GrReducedClip.cpp", "$_src/gpu/GrReducedClip.cpp",
"$_src/gpu/GrReducedClip.h", "$_src/gpu/GrReducedClip.h",
"$_src/gpu/GrRenderTargetContext.cpp",
"$_src/gpu/GrRenderTargetContextPriv.h",
"$_src/gpu/GrPathRenderingRenderTargetContext.cpp",
"$_src/gpu/GrPathRenderingRenderTargetContext.h",
"$_src/gpu/GrRenderTargetOpList.cpp", "$_src/gpu/GrRenderTargetOpList.cpp",
"$_src/gpu/GrRenderTargetOpList.h", "$_src/gpu/GrRenderTargetOpList.h",
"$_src/gpu/GrResourceCache.cpp", "$_src/gpu/GrResourceCache.cpp",

View File

@ -23,7 +23,7 @@
#include "../private/SkShadowParams.h" #include "../private/SkShadowParams.h"
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
class SkBaseDevice; class SkBaseDevice;
class SkCanvasClipVisitor; class SkCanvasClipVisitor;
class SkClipStack; class SkClipStack;
@ -1371,7 +1371,7 @@ public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// don't call // don't call
GrDrawContext* internal_private_accessTopLayerDrawContext(); GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
// don't call // don't call
static void Internal_Private_SetIgnoreSaveLayerBounds(bool); static void Internal_Private_SetIgnoreSaveLayerBounds(bool);

View File

@ -343,7 +343,7 @@ private:
/** /**
* Don't call this! * Don't call this!
*/ */
virtual GrDrawContext* accessDrawContext() { return nullptr; } virtual GrRenderTargetContext* accessRenderTargetContext() { return nullptr; }
// just called by SkCanvas when built as a layer // just called by SkCanvas when built as a layer
void setOrigin(int x, int y) { fOrigin.set(x, y); } void setOrigin(int x, int y) { fOrigin.set(x, y); }

View File

@ -18,7 +18,7 @@
class GrClip; class GrClip;
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
class GrPaint; class GrPaint;
class GrRenderTarget; class GrRenderTarget;
class GrTextureProvider; class GrTextureProvider;
@ -113,7 +113,7 @@ public:
* true if drawing was successful. * true if drawing was successful.
*/ */
virtual bool directFilterMaskGPU(GrTextureProvider* texProvider, virtual bool directFilterMaskGPU(GrTextureProvider* texProvider,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
GrPaint* grp, GrPaint* grp,
const GrClip&, const GrClip&,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -124,7 +124,7 @@ public:
* true if drawing was successful. * true if drawing was successful.
*/ */
virtual bool directFilterRRectMaskGPU(GrContext*, virtual bool directFilterRRectMaskGPU(GrContext*,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
GrPaint* grp, GrPaint* grp,
const GrClip&, const GrClip&,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,

View File

@ -13,7 +13,7 @@
class GrAppliedClip; class GrAppliedClip;
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
/** /**
* GrClip is an abstract base class for applying a clip. It constructs a clip mask if necessary, and * GrClip is an abstract base class for applying a clip. It constructs a clip mask if necessary, and
@ -27,8 +27,8 @@ public:
} }
virtual void getConservativeBounds(int width, int height, SkIRect* devResult, virtual void getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects = nullptr) const = 0; bool* isIntersectionOfRects = nullptr) const = 0;
virtual bool apply(GrContext*, GrDrawContext*, bool useHWAA, bool hasUserStencilSettings, virtual bool apply(GrContext*, GrRenderTargetContext*, bool useHWAA,
GrAppliedClip* out) const = 0; bool hasUserStencilSettings, GrAppliedClip* out) const = 0;
virtual ~GrClip() {} virtual ~GrClip() {}
@ -137,7 +137,7 @@ private:
*isIntersectionOfRects = true; *isIntersectionOfRects = true;
} }
} }
bool apply(GrContext*, GrDrawContext*, bool, bool, GrAppliedClip*) const final { bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip*) const final {
return true; return true;
} }
bool isRRect(const SkRect&, SkRRect*, bool*) const override { return false; } bool isRRect(const SkRect&, SkRRect*, bool*) const override { return false; }

View File

@ -27,7 +27,7 @@ struct GrContextOptions;
class GrContextPriv; class GrContextPriv;
class GrContextThreadSafeProxy; class GrContextThreadSafeProxy;
class GrDrawingManager; class GrDrawingManager;
class GrDrawContext; class GrRenderTargetContext;
class GrFragmentProcessor; class GrFragmentProcessor;
class GrGpu; class GrGpu;
class GrIndexBuffer; class GrIndexBuffer;
@ -181,26 +181,27 @@ public:
int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
/** /**
* Create both a GrRenderTarget and a matching GrDrawContext to wrap it. * Create both a GrRenderTarget and a matching GrRenderTargetContext to wrap it.
* We guarantee that "asTexture" will succeed for drawContexts created * We guarantee that "asTexture" will succeed for renderTargetContexts created
* via this entry point. * via this entry point.
*/ */
sk_sp<GrDrawContext> makeDrawContext(SkBackingFit fit, sk_sp<GrRenderTargetContext> makeRenderTargetContext(
int width, int height, SkBackingFit fit,
GrPixelConfig config, int width, int height,
sk_sp<SkColorSpace> colorSpace, GrPixelConfig config,
int sampleCnt = 0, sk_sp<SkColorSpace> colorSpace,
GrSurfaceOrigin origin = kDefault_GrSurfaceOrigin, int sampleCnt = 0,
const SkSurfaceProps* surfaceProps = nullptr, GrSurfaceOrigin origin = kDefault_GrSurfaceOrigin,
SkBudgeted = SkBudgeted::kYes); const SkSurfaceProps* surfaceProps = nullptr,
SkBudgeted = SkBudgeted::kYes);
/* /*
* This method will attempt to create a drawContext that has, at least, the number of * This method will attempt to create a renderTargetContext that has, at least, the number of
* channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
* converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA). * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
* SRGB-ness will be preserved. * SRGB-ness will be preserved.
*/ */
sk_sp<GrDrawContext> makeDrawContextWithFallback( sk_sp<GrRenderTargetContext> makeRenderTargetContextWithFallback(
SkBackingFit fit, SkBackingFit fit,
int width, int height, int width, int height,
GrPixelConfig config, GrPixelConfig config,
@ -333,8 +334,8 @@ public:
const GrResourceProvider* resourceProvider() const { return fResourceProvider; } const GrResourceProvider* resourceProvider() const { return fResourceProvider; }
GrResourceCache* getResourceCache() { return fResourceCache; } GrResourceCache* getResourceCache() { return fResourceCache; }
// Called by tests that draw directly to the context via GrDrawContext // Called by tests that draw directly to the context via GrRenderTargetContext
void getTestTarget(GrTestTarget*, sk_sp<GrDrawContext>); void getTestTarget(GrTestTarget*, sk_sp<GrRenderTargetContext>);
/** Reset GPU stats */ /** Reset GPU stats */
void resetGpuStats() const ; void resetGpuStats() const ;
@ -406,7 +407,7 @@ private:
// In debug builds we guard against improper thread handling // In debug builds we guard against improper thread handling
// This guard is passed to the GrDrawingManager and, from there to all the // This guard is passed to the GrDrawingManager and, from there to all the
// GrDrawContexts. It is also passed to the GrTextureProvider and SkGpuDevice. // GrRenderTargetContexts. It is also passed to the GrTextureProvider and SkGpuDevice.
mutable GrSingleOwner fSingleOwner; mutable GrSingleOwner fSingleOwner;
struct CleanUpData { struct CleanUpData {
@ -422,7 +423,7 @@ private:
GrAuditTrail fAuditTrail; GrAuditTrail fAuditTrail;
// TODO: have the GrClipStackClip use drawContexts and rm this friending // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
friend class GrContextPriv; friend class GrContextPriv;
GrContext(); // init must be called after the constructor. GrContext(); // init must be called after the constructor.

View File

@ -15,7 +15,7 @@
class SkMatrix; class SkMatrix;
class GrCaps; class GrCaps;
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
struct GrProcessorTestData; struct GrProcessorTestData;
namespace GrProcessorUnitTest { namespace GrProcessorUnitTest {
@ -43,19 +43,19 @@ struct GrProcessorTestData {
GrProcessorTestData(SkRandom* random, GrProcessorTestData(SkRandom* random,
GrContext* context, GrContext* context,
const GrCaps* caps, const GrCaps* caps,
const GrDrawContext* drawContext, const GrRenderTargetContext* renderTargetContext,
GrTexture* textures[2]) GrTexture* textures[2])
: fRandom(random) : fRandom(random)
, fContext(context) , fContext(context)
, fCaps(caps) , fCaps(caps)
, fDrawContext(drawContext) { , fRenderTargetContext(renderTargetContext) {
fTextures[0] = textures[0]; fTextures[0] = textures[0];
fTextures[1] = textures[1]; fTextures[1] = textures[1];
} }
SkRandom* fRandom; SkRandom* fRandom;
GrContext* fContext; GrContext* fContext;
const GrCaps* fCaps; const GrCaps* fCaps;
const GrDrawContext* fDrawContext; const GrRenderTargetContext* fRenderTargetContext;
GrTexture* fTextures[2]; GrTexture* fTextures[2];
}; };

View File

@ -5,8 +5,8 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#ifndef GrDrawContext_DEFINED #ifndef GrRenderTargetContext_DEFINED
#define GrDrawContext_DEFINED #define GrRenderTargetContext_DEFINED
#include "GrColor.h" #include "GrColor.h"
#include "GrContext.h" #include "GrContext.h"
@ -21,7 +21,7 @@
class GrAuditTrail; class GrAuditTrail;
class GrClip; class GrClip;
class GrDrawBatch; class GrDrawBatch;
class GrDrawContextPriv; class GrRenderTargetContextPriv;
class GrDrawPathBatchBase; class GrDrawPathBatchBase;
class GrDrawingManager; class GrDrawingManager;
class GrFixedClip; class GrFixedClip;
@ -49,9 +49,9 @@ class SkTextBlob;
/* /*
* A helper object to orchestrate draws * A helper object to orchestrate draws
*/ */
class SK_API GrDrawContext : public SkRefCnt { class SK_API GrRenderTargetContext : public SkRefCnt {
public: public:
~GrDrawContext() override; ~GrRenderTargetContext() override;
bool copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint); bool copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint);
@ -286,12 +286,12 @@ public:
void prepareForExternalIO(); void prepareForExternalIO();
/** /**
* Reads a rectangle of pixels from the draw context. * Reads a rectangle of pixels from the render target context.
* @param dstInfo image info for the destination * @param dstInfo image info for the destination
* @param dstBuffer destination pixels for the read * @param dstBuffer destination pixels for the read
* @param dstRowBytes bytes in a row of 'dstBuffer' * @param dstRowBytes bytes in a row of 'dstBuffer'
* @param x x offset w/in the draw context from which to read * @param x x offset w/in the render target context from which to read
* @param y y offset w/in the draw context from which to read * @param y y offset w/in the render target context from which to read
* *
* @return true if the read succeeded, false if not. The read can fail because of an * @return true if the read succeeded, false if not. The read can fail because of an
* unsupported pixel config. * unsupported pixel config.
@ -300,12 +300,12 @@ public:
/** /**
* Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the * Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the
* drawContext at the specified position. * renderTargetContext at the specified position.
* @param srcInfo image info for the source pixels * @param srcInfo image info for the source pixels
* @param srcBuffer source for the write * @param srcBuffer source for the write
* @param srcRowBytes bytes in a row of 'srcBuffer' * @param srcRowBytes bytes in a row of 'srcBuffer'
* @param x x offset w/in the draw context at which to write * @param x x offset w/in the render target context at which to write
* @param y y offset w/in the draw context at which to write * @param y y offset w/in the render target context at which to write
* *
* @return true if the write succeeded, false if not. The write can fail because of an * @return true if the write succeeded, false if not. The write can fail because of an
* unsupported pixel config. * unsupported pixel config.
@ -346,14 +346,14 @@ public:
sk_sp<GrTexture> asTexture() { return sk_ref_sp(fRenderTarget->asTexture()); } sk_sp<GrTexture> asTexture() { return sk_ref_sp(fRenderTarget->asTexture()); }
// Provides access to functions that aren't part of the public API. // Provides access to functions that aren't part of the public API.
GrDrawContextPriv drawContextPriv(); GrRenderTargetContextPriv renderTargetContextPriv();
const GrDrawContextPriv drawContextPriv() const; const GrRenderTargetContextPriv renderTargetContextPriv() const;
GrAuditTrail* auditTrail() { return fAuditTrail; } GrAuditTrail* auditTrail() { return fAuditTrail; }
protected: protected:
GrDrawContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTarget>, sk_sp<SkColorSpace>, GrRenderTargetContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTarget>, sk_sp<SkColorSpace>,
const SkSurfaceProps* surfaceProps, GrAuditTrail*, GrSingleOwner*); const SkSurfaceProps* surfaceProps, GrAuditTrail*, GrSingleOwner*);
GrDrawingManager* drawingManager() { return fDrawingManager; } GrDrawingManager* drawingManager() { return fDrawingManager; }
@ -365,7 +365,7 @@ private:
friend class GrStencilAndCoverTextContext; // for access to drawBatch friend class GrStencilAndCoverTextContext; // for access to drawBatch
friend class GrDrawingManager; // for ctor friend class GrDrawingManager; // for ctor
friend class GrDrawContextPriv; friend class GrRenderTargetContextPriv;
friend class GrTestTarget; // for access to getOpList friend class GrTestTarget; // for access to getOpList
friend class GrSWMaskHelper; // for access to drawBatch friend class GrSWMaskHelper; // for access to drawBatch
@ -420,7 +420,7 @@ private:
GrDrawingManager* fDrawingManager; GrDrawingManager* fDrawingManager;
sk_sp<GrRenderTarget> fRenderTarget; sk_sp<GrRenderTarget> fRenderTarget;
// In MDB-mode the GrOpList can be closed by some other drawContext that has picked // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked
// it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'. // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'.
GrRenderTargetOpList* fOpList; GrRenderTargetOpList* fOpList;
GrContext* fContext; GrContext* fContext;

View File

@ -167,7 +167,7 @@ private:
ReleaseCtx fReleaseCtx; ReleaseCtx fReleaseCtx;
// The last opList that wrote to or is currently going to write to this surface // The last opList that wrote to or is currently going to write to this surface
// The opList can be closed (e.g., no draw or copy context is currently bound // The opList can be closed (e.g., no render target or texture context is currently bound
// to this renderTarget or texture). // to this renderTarget or texture).
// This back-pointer is required so that we can add a dependancy between // This back-pointer is required so that we can add a dependancy between
// the opList used to create the current contents of this surface // the opList used to create the current contents of this surface

View File

@ -91,7 +91,7 @@ private:
bool notifyRefCountIsZero() const { return true; } bool notifyRefCountIsZero() const { return true; }
// The last opList that wrote to or is currently going to write to this surface // The last opList that wrote to or is currently going to write to this surface
// The opList can be closed (e.g., no draw context is currently bound // The opList can be closed (e.g., no render target context is currently bound
// to this renderTarget). // to this renderTarget).
// This back-pointer is required so that we can add a dependancy between // This back-pointer is required so that we can add a dependancy between
// the opList used to create the current contents of this surface // the opList used to create the current contents of this surface

View File

@ -152,7 +152,7 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc
// We intentionally use the source's color space, not the destination's (from ctx). We // We intentionally use the source's color space, not the destination's (from ctx). We
// always blur in the source's config, so we need a compatible color space. We also want to // always blur in the source's config, so we need a compatible color space. We also want to
// avoid doing gamut conversion on every fetch of the texture. // avoid doing gamut conversion on every fetch of the texture.
sk_sp<GrDrawContext> drawContext(SkGpuBlurUtils::GaussianBlur( sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::GaussianBlur(
context, context,
inputTexture.get(), inputTexture.get(),
sk_ref_sp(source->getColorSpace()), sk_ref_sp(source->getColorSpace()),
@ -160,14 +160,14 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc
&inputBounds, &inputBounds,
sigma.x(), sigma.x(),
sigma.y())); sigma.y()));
if (!drawContext) { if (!renderTargetContext) {
return nullptr; return nullptr;
} }
// TODO: Get the colorSpace from the drawContext (once it has one) // TODO: Get the colorSpace from the renderTargetContext (once it has one)
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(dstBounds.width(), dstBounds.height()), return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(dstBounds.width(), dstBounds.height()),
kNeedNewImageUniqueID_SpecialImage, kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(), renderTargetContext->asTexture(),
sk_ref_sp(input->getColorSpace()), &source->props()); sk_ref_sp(input->getColorSpace()), &source->props());
} }
#endif #endif

View File

@ -1813,9 +1813,9 @@ const SkRegion& SkCanvas::internal_private_getTotalClip() const {
return fMCRec->fRasterClip.forceGetBW(); return fMCRec->fRasterClip.forceGetBW();
} }
GrDrawContext* SkCanvas::internal_private_accessTopLayerDrawContext() { GrRenderTargetContext* SkCanvas::internal_private_accessTopLayerRenderTargetContext() {
SkBaseDevice* dev = this->getTopDevice(); SkBaseDevice* dev = this->getTopDevice();
return dev ? dev->accessDrawContext() : nullptr; return dev ? dev->accessRenderTargetContext() : nullptr;
} }
GrContext* SkCanvas::getGrContext() { GrContext* SkCanvas::getGrContext() {

View File

@ -14,7 +14,7 @@
#include "effects/GrMatrixConvolutionEffect.h" #include "effects/GrMatrixConvolutionEffect.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#define MAX_BLUR_SIGMA 4.0f #define MAX_BLUR_SIGMA 4.0f
@ -65,7 +65,7 @@ static float adjust_sigma(float sigma, int maxTextureSize, int *scaleFactor, int
return sigma; return sigma;
} }
static void convolve_gaussian_1d(GrDrawContext* drawContext, static void convolve_gaussian_1d(GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkIRect& dstRect, const SkIRect& dstRect,
const SkIPoint& srcOffset, const SkIPoint& srcOffset,
@ -76,18 +76,18 @@ static void convolve_gaussian_1d(GrDrawContext* drawContext,
bool useBounds, bool useBounds,
float bounds[2]) { float bounds[2]) {
GrPaint paint; GrPaint paint;
paint.setGammaCorrect(drawContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
sk_sp<GrFragmentProcessor> conv(GrConvolutionEffect::MakeGaussian( sk_sp<GrFragmentProcessor> conv(GrConvolutionEffect::MakeGaussian(
texture, direction, radius, sigma, useBounds, bounds)); texture, direction, radius, sigma, useBounds, bounds));
paint.addColorFragmentProcessor(std::move(conv)); paint.addColorFragmentProcessor(std::move(conv));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()),
-SkIntToScalar(srcOffset.y())); -SkIntToScalar(srcOffset.y()));
drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), renderTargetContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(),
SkRect::Make(dstRect), localMatrix); SkRect::Make(dstRect), localMatrix);
} }
static void convolve_gaussian_2d(GrDrawContext* drawContext, static void convolve_gaussian_2d(GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkIRect& dstRect, const SkIRect& dstRect,
const SkIPoint& srcOffset, const SkIPoint& srcOffset,
@ -102,7 +102,7 @@ static void convolve_gaussian_2d(GrDrawContext* drawContext,
SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1);
SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY);
GrPaint paint; GrPaint paint;
paint.setGammaCorrect(drawContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect(); SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect();
sk_sp<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::MakeGaussian( sk_sp<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::MakeGaussian(
@ -111,11 +111,11 @@ static void convolve_gaussian_2d(GrDrawContext* drawContext,
true, sigmaX, sigmaY)); true, sigmaX, sigmaY));
paint.addColorFragmentProcessor(std::move(conv)); paint.addColorFragmentProcessor(std::move(conv));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), renderTargetContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(),
SkRect::Make(dstRect), localMatrix); SkRect::Make(dstRect), localMatrix);
} }
static void convolve_gaussian(GrDrawContext* drawContext, static void convolve_gaussian(GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkIRect& srcRect, const SkIRect& srcRect,
GrTexture* texture, GrTexture* texture,
@ -127,7 +127,7 @@ static void convolve_gaussian(GrDrawContext* drawContext,
float bounds[2] = { 0.0f, 1.0f }; float bounds[2] = { 0.0f, 1.0f };
SkIRect dstRect = SkIRect::MakeWH(srcRect.width(), srcRect.height()); SkIRect dstRect = SkIRect::MakeWH(srcRect.width(), srcRect.height());
if (!srcBounds) { if (!srcBounds) {
convolve_gaussian_1d(drawContext, clip, dstRect, srcOffset, texture, convolve_gaussian_1d(renderTargetContext, clip, dstRect, srcOffset, texture,
direction, radius, sigma, false, bounds); direction, radius, sigma, false, bounds);
return; return;
} }
@ -158,37 +158,37 @@ static void convolve_gaussian(GrDrawContext* drawContext,
dstRect.fRight = midRect.right(); dstRect.fRight = midRect.right();
} }
if (!topRect.isEmpty()) { if (!topRect.isEmpty()) {
drawContext->clear(&topRect, 0, false); renderTargetContext->clear(&topRect, 0, false);
} }
if (!bottomRect.isEmpty()) { if (!bottomRect.isEmpty()) {
drawContext->clear(&bottomRect, 0, false); renderTargetContext->clear(&bottomRect, 0, false);
} }
if (midRect.isEmpty()) { if (midRect.isEmpty()) {
// Blur radius covers srcBounds; use bounds over entire draw // Blur radius covers srcBounds; use bounds over entire draw
convolve_gaussian_1d(drawContext, clip, dstRect, srcOffset, texture, convolve_gaussian_1d(renderTargetContext, clip, dstRect, srcOffset, texture,
direction, radius, sigma, true, bounds); direction, radius, sigma, true, bounds);
} else { } else {
// Draw right and left margins with bounds; middle without. // Draw right and left margins with bounds; middle without.
convolve_gaussian_1d(drawContext, clip, leftRect, srcOffset, texture, convolve_gaussian_1d(renderTargetContext, clip, leftRect, srcOffset, texture,
direction, radius, sigma, true, bounds); direction, radius, sigma, true, bounds);
convolve_gaussian_1d(drawContext, clip, rightRect, srcOffset, texture, convolve_gaussian_1d(renderTargetContext, clip, rightRect, srcOffset, texture,
direction, radius, sigma, true, bounds); direction, radius, sigma, true, bounds);
convolve_gaussian_1d(drawContext, clip, midRect, srcOffset, texture, convolve_gaussian_1d(renderTargetContext, clip, midRect, srcOffset, texture,
direction, radius, sigma, false, bounds); direction, radius, sigma, false, bounds);
} }
} }
namespace SkGpuBlurUtils { namespace SkGpuBlurUtils {
sk_sp<GrDrawContext> GaussianBlur(GrContext* context, sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
GrTexture* origSrc, GrTexture* origSrc,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkIRect& dstBounds, const SkIRect& dstBounds,
const SkIRect* srcBounds, const SkIRect* srcBounds,
float sigmaX, float sigmaX,
float sigmaY, float sigmaY,
SkBackingFit fit) { SkBackingFit fit) {
SkASSERT(context); SkASSERT(context);
SkIRect clearRect; SkIRect clearRect;
int scaleFactorX, radiusX; int scaleFactorX, radiusX;
@ -229,10 +229,9 @@ sk_sp<GrDrawContext> GaussianBlur(GrContext* context,
const int height = dstBounds.height(); const int height = dstBounds.height();
const GrPixelConfig config = srcTexture->config(); const GrPixelConfig config = srcTexture->config();
sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(fit, sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeRenderTargetContext(
width, height, config, colorSpace, fit, width, height, config, colorSpace, 0, kDefault_GrSurfaceOrigin));
0, kDefault_GrSurfaceOrigin)); if (!dstRenderTargetContext) {
if (!dstDrawContext) {
return nullptr; return nullptr;
} }
@ -243,26 +242,25 @@ sk_sp<GrDrawContext> GaussianBlur(GrContext* context,
// We shouldn't be scaling because this is a small size blur // We shouldn't be scaling because this is a small size blur
SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY));
convolve_gaussian_2d(dstDrawContext.get(), clip, localDstBounds, srcOffset, convolve_gaussian_2d(dstRenderTargetContext.get(), clip, localDstBounds, srcOffset,
srcTexture.get(), radiusX, radiusY, sigmaX, sigmaY, srcBounds); srcTexture.get(), radiusX, radiusY, sigmaX, sigmaY, srcBounds);
return dstDrawContext; return dstRenderTargetContext;
} }
sk_sp<GrDrawContext> tmpDrawContext(context->makeDrawContext(fit, sk_sp<GrRenderTargetContext> tmpRenderTargetContext(context->makeRenderTargetContext(
width, height, config, colorSpace, fit, width, height, config, colorSpace, 0, kDefault_GrSurfaceOrigin));
0, kDefault_GrSurfaceOrigin)); if (!tmpRenderTargetContext) {
if (!tmpDrawContext) {
return nullptr; return nullptr;
} }
sk_sp<GrDrawContext> srcDrawContext; sk_sp<GrRenderTargetContext> srcRenderTargetContext;
SkASSERT(SkIsPow2(scaleFactorX) && SkIsPow2(scaleFactorY)); SkASSERT(SkIsPow2(scaleFactorX) && SkIsPow2(scaleFactorY));
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) { for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
GrPaint paint; GrPaint paint;
paint.setGammaCorrect(dstDrawContext->isGammaCorrect()); paint.setGammaCorrect(dstRenderTargetContext->isGammaCorrect());
SkMatrix matrix; SkMatrix matrix;
matrix.setIDiv(srcTexture->width(), srcTexture->height()); matrix.setIDiv(srcTexture->width(), srcTexture->height());
SkIRect dstRect(srcRect); SkIRect dstRect(srcRect);
@ -288,13 +286,13 @@ sk_sp<GrDrawContext> GaussianBlur(GrContext* context,
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY); shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY);
dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRenderTargetContext->fillRectToRect(clip, paint, SkMatrix::I(),
SkRect::Make(dstRect), SkRect::Make(srcRect)); SkRect::Make(dstRect), SkRect::Make(srcRect));
srcDrawContext = dstDrawContext; srcRenderTargetContext = dstRenderTargetContext;
srcRect = dstRect; srcRect = dstRect;
srcTexture = srcDrawContext->asTexture(); srcTexture = srcRenderTargetContext->asTexture();
dstDrawContext.swap(tmpDrawContext); dstRenderTargetContext.swap(tmpRenderTargetContext);
localSrcBounds = srcRect; localSrcBounds = srcRect;
} }
@ -302,79 +300,79 @@ sk_sp<GrDrawContext> GaussianBlur(GrContext* context,
scale_irect_roundout(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); scale_irect_roundout(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY);
if (sigmaX > 0.0f) { if (sigmaX > 0.0f) {
if (scaleFactorX > 1) { if (scaleFactorX > 1) {
SkASSERT(srcDrawContext); SkASSERT(srcRenderTargetContext);
// Clear out a radius to the right of the srcRect to prevent the // Clear out a radius to the right of the srcRect to prevent the
// X convolution from reading garbage. // X convolution from reading garbage.
clearRect = SkIRect::MakeXYWH(srcRect.fRight, srcRect.fTop, clearRect = SkIRect::MakeXYWH(srcRect.fRight, srcRect.fTop,
radiusX, srcRect.height()); radiusX, srcRect.height());
srcDrawContext->clear(&clearRect, 0x0, false); srcRenderTargetContext->clear(&clearRect, 0x0, false);
} }
convolve_gaussian(dstDrawContext.get(), clip, srcRect, convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect,
srcTexture.get(), Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, srcTexture.get(), Gr1DKernelEffect::kX_Direction, radiusX, sigmaX,
srcBounds, srcOffset); srcBounds, srcOffset);
srcDrawContext = dstDrawContext; srcRenderTargetContext = dstRenderTargetContext;
srcTexture = srcDrawContext->asTexture(); srcTexture = srcRenderTargetContext->asTexture();
srcRect.offsetTo(0, 0); srcRect.offsetTo(0, 0);
dstDrawContext.swap(tmpDrawContext); dstRenderTargetContext.swap(tmpRenderTargetContext);
localSrcBounds = srcRect; localSrcBounds = srcRect;
srcOffset.set(0, 0); srcOffset.set(0, 0);
} }
if (sigmaY > 0.0f) { if (sigmaY > 0.0f) {
if (scaleFactorY > 1 || sigmaX > 0.0f) { if (scaleFactorY > 1 || sigmaX > 0.0f) {
SkASSERT(srcDrawContext); SkASSERT(srcRenderTargetContext);
// Clear out a radius below the srcRect to prevent the Y // Clear out a radius below the srcRect to prevent the Y
// convolution from reading garbage. // convolution from reading garbage.
clearRect = SkIRect::MakeXYWH(srcRect.fLeft, srcRect.fBottom, clearRect = SkIRect::MakeXYWH(srcRect.fLeft, srcRect.fBottom,
srcRect.width(), radiusY); srcRect.width(), radiusY);
srcDrawContext->clear(&clearRect, 0x0, false); srcRenderTargetContext->clear(&clearRect, 0x0, false);
} }
convolve_gaussian(dstDrawContext.get(), clip, srcRect, convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect,
srcTexture.get(), Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, srcTexture.get(), Gr1DKernelEffect::kY_Direction, radiusY, sigmaY,
srcBounds, srcOffset); srcBounds, srcOffset);
srcDrawContext = dstDrawContext; srcRenderTargetContext = dstRenderTargetContext;
srcRect.offsetTo(0, 0); srcRect.offsetTo(0, 0);
dstDrawContext.swap(tmpDrawContext); dstRenderTargetContext.swap(tmpRenderTargetContext);
} }
SkASSERT(srcDrawContext); SkASSERT(srcRenderTargetContext);
srcTexture = nullptr; // we don't use this from here on out srcTexture = nullptr; // we don't use this from here on out
if (scaleFactorX > 1 || scaleFactorY > 1) { if (scaleFactorX > 1 || scaleFactorY > 1) {
// Clear one pixel to the right and below, to accommodate bilinear upsampling. // Clear one pixel to the right and below, to accommodate bilinear upsampling.
clearRect = SkIRect::MakeXYWH(srcRect.fLeft, srcRect.fBottom, srcRect.width() + 1, 1); clearRect = SkIRect::MakeXYWH(srcRect.fLeft, srcRect.fBottom, srcRect.width() + 1, 1);
srcDrawContext->clear(&clearRect, 0x0, false); srcRenderTargetContext->clear(&clearRect, 0x0, false);
clearRect = SkIRect::MakeXYWH(srcRect.fRight, srcRect.fTop, 1, srcRect.height()); clearRect = SkIRect::MakeXYWH(srcRect.fRight, srcRect.fTop, 1, srcRect.height());
srcDrawContext->clear(&clearRect, 0x0, false); srcRenderTargetContext->clear(&clearRect, 0x0, false);
SkMatrix matrix; SkMatrix matrix;
matrix.setIDiv(srcDrawContext->width(), srcDrawContext->height()); matrix.setIDiv(srcRenderTargetContext->width(), srcRenderTargetContext->height());
GrPaint paint; GrPaint paint;
paint.setGammaCorrect(dstDrawContext->isGammaCorrect()); paint.setGammaCorrect(dstRenderTargetContext->isGammaCorrect());
// FIXME: this should be mitchell, not bilinear. // FIXME: this should be mitchell, not bilinear.
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode); GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode);
sk_sp<GrTexture> tex(srcDrawContext->asTexture()); sk_sp<GrTexture> tex(srcRenderTargetContext->asTexture());
paint.addColorTextureProcessor(tex.get(), nullptr, matrix, params); paint.addColorTextureProcessor(tex.get(), nullptr, matrix, params);
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkIRect dstRect(srcRect); SkIRect dstRect(srcRect);
scale_irect(&dstRect, scaleFactorX, scaleFactorY); scale_irect(&dstRect, scaleFactorX, scaleFactorY);
dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRenderTargetContext->fillRectToRect(clip, paint, SkMatrix::I(),
SkRect::Make(dstRect), SkRect::Make(srcRect)); SkRect::Make(dstRect), SkRect::Make(srcRect));
srcDrawContext = dstDrawContext; srcRenderTargetContext = dstRenderTargetContext;
srcRect = dstRect; srcRect = dstRect;
dstDrawContext.swap(tmpDrawContext); dstRenderTargetContext.swap(tmpRenderTargetContext);
} }
return srcDrawContext; return srcRenderTargetContext;
} }
} }

View File

@ -9,7 +9,7 @@
#define SkGpuBlurUtils_DEFINED #define SkGpuBlurUtils_DEFINED
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
class GrContext; class GrContext;
class GrTexture; class GrTexture;
@ -19,27 +19,28 @@ struct SkRect;
namespace SkGpuBlurUtils { namespace SkGpuBlurUtils {
/** /**
* Applies a 2D Gaussian blur to a given texture. The blurred result is returned * Applies a 2D Gaussian blur to a given texture. The blurred result is returned
* as a drawContext in case the caller wishes to future draw into the result. * as a renderTargetContext in case the caller wishes to future draw into the result.
* Note: one of sigmaX and sigmaY should be non-zero! * Note: one of sigmaX and sigmaY should be non-zero!
* @param context The GPU context * @param context The GPU context
* @param srcTexture The source texture to be blurred. * @param srcTexture The source texture to be blurred.
* @param colorSpace Color space of the source (used for the drawContext result, too). * @param colorSpace Color space of the source (used for the renderTargetContext result,
* too).
* @param dstBounds The destination bounds, relative to the source texture. * @param dstBounds The destination bounds, relative to the source texture.
* @param srcBounds The source bounds, relative to the source texture. If non-null, * @param srcBounds The source bounds, relative to the source texture. If non-null,
* no pixels will be sampled outside of this rectangle. * no pixels will be sampled outside of this rectangle.
* @param sigmaX The blur's standard deviation in X. * @param sigmaX The blur's standard deviation in X.
* @param sigmaY The blur's standard deviation in Y. * @param sigmaY The blur's standard deviation in Y.
* @param fit backing fit for the returned draw context * @param fit backing fit for the returned render target context
* @return The drawContext containing the blurred result. * @return The renderTargetContext containing the blurred result.
*/ */
sk_sp<GrDrawContext> GaussianBlur(GrContext* context, sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
GrTexture* srcTexture, GrTexture* srcTexture,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkIRect& dstBounds, const SkIRect& dstBounds,
const SkIRect* srcBounds, const SkIRect* srcBounds,
float sigmaX, float sigmaX,
float sigmaY, float sigmaY,
SkBackingFit fit = SkBackingFit::kApprox); SkBackingFit fit = SkBackingFit::kApprox);
}; };
#endif #endif

View File

@ -20,7 +20,7 @@
#include "SkWriteBuffer.h" #include "SkWriteBuffer.h"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "SkGrPriv.h" #include "SkGrPriv.h"
#endif #endif
@ -285,24 +285,22 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context,
sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace()); sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace());
GrPixelConfig config = GrRenderableConfigForColorSpace(colorSpace.get()); GrPixelConfig config = GrRenderableConfigForColorSpace(colorSpace.get());
sk_sp<GrDrawContext> drawContext(context->makeDrawContext(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
bounds.width(), bounds.height(), SkBackingFit::kApprox, bounds.width(), bounds.height(), config, std::move(colorSpace)));
config, if (!renderTargetContext) {
std::move(colorSpace)));
if (!drawContext) {
return nullptr; return nullptr;
} }
paint.setGammaCorrect(drawContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
SkIRect dstIRect = SkIRect::MakeWH(bounds.width(), bounds.height()); SkIRect dstIRect = SkIRect::MakeWH(bounds.width(), bounds.height());
SkRect srcRect = SkRect::Make(bounds); SkRect srcRect = SkRect::Make(bounds);
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
GrFixedClip clip(dstIRect); GrFixedClip clip(dstIRect);
drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); renderTargetContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
return SkSpecialImage::MakeFromGpu(dstIRect, kNeedNewImageUniqueID_SpecialImage, return SkSpecialImage::MakeFromGpu(dstIRect, kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(), renderTargetContext->asTexture(),
sk_ref_sp(drawContext->getColorSpace())); sk_ref_sp(renderTargetContext->getColorSpace()));
} }
#endif #endif

View File

@ -314,7 +314,7 @@ bool SkMaskFilter::canFilterMaskGPU(const SkRRect& devRRect,
} }
bool SkMaskFilter::directFilterMaskGPU(GrTextureProvider* texProvider, bool SkMaskFilter::directFilterMaskGPU(GrTextureProvider* texProvider,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
GrPaint* grp, GrPaint* grp,
const GrClip&, const GrClip&,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -325,7 +325,7 @@ bool SkMaskFilter::canFilterMaskGPU(const SkRRect& devRRect,
bool SkMaskFilter::directFilterRRectMaskGPU(GrContext*, bool SkMaskFilter::directFilterRRectMaskGPU(GrContext*,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
GrPaint* grp, GrPaint* grp,
const GrClip&, const GrClip&,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,

View File

@ -115,13 +115,13 @@ sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRaster(const SkImageInfo& info,
class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
public: public:
SkSpecialSurface_Gpu(sk_sp<GrDrawContext> drawContext, SkSpecialSurface_Gpu(sk_sp<GrRenderTargetContext> renderTargetContext,
int width, int height, int width, int height,
const SkIRect& subset) const SkIRect& subset)
: INHERITED(subset, &drawContext->surfaceProps()) : INHERITED(subset, &renderTargetContext->surfaceProps())
, fDrawContext(std::move(drawContext)) { , fRenderTargetContext(std::move(renderTargetContext)) {
sk_sp<SkBaseDevice> device(SkGpuDevice::Make(fDrawContext, width, height, sk_sp<SkBaseDevice> device(SkGpuDevice::Make(fRenderTargetContext, width, height,
SkGpuDevice::kUninit_InitContents)); SkGpuDevice::kUninit_InitContents));
if (!device) { if (!device) {
return; return;
@ -138,17 +138,17 @@ public:
sk_sp<SkSpecialImage> onMakeImageSnapshot() override { sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
sk_sp<SkSpecialImage> tmp(SkSpecialImage::MakeFromGpu( sk_sp<SkSpecialImage> tmp(SkSpecialImage::MakeFromGpu(
this->subset(), this->subset(),
kNeedNewImageUniqueID_SpecialImage, kNeedNewImageUniqueID_SpecialImage,
fDrawContext->asTexture(), fRenderTargetContext->asTexture(),
sk_ref_sp(fDrawContext->getColorSpace()), sk_ref_sp(fRenderTargetContext->getColorSpace()),
&this->props())); &this->props()));
fDrawContext = nullptr; fRenderTargetContext = nullptr;
return tmp; return tmp;
} }
private: private:
sk_sp<GrDrawContext> fDrawContext; sk_sp<GrRenderTargetContext> fRenderTargetContext;
typedef SkSpecialSurface_Base INHERITED; typedef SkSpecialSurface_Base INHERITED;
}; };
@ -161,16 +161,15 @@ sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
return nullptr; return nullptr;
} }
sk_sp<GrDrawContext> drawContext(context->makeDrawContext(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
width, height, config, SkBackingFit::kApprox, width, height, config, std::move(colorSpace)));
std::move(colorSpace))); if (!renderTargetContext) {
if (!drawContext) {
return nullptr; return nullptr;
} }
const SkIRect subset = SkIRect::MakeWH(width, height); const SkIRect subset = SkIRect::MakeWH(width, height);
return sk_make_sp<SkSpecialSurface_Gpu>(std::move(drawContext), width, height, subset); return sk_make_sp<SkSpecialSurface_Gpu>(std::move(renderTargetContext), width, height, subset);
} }
#endif #endif

View File

@ -16,7 +16,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrAlphaThresholdFragmentProcessor.h" #include "GrAlphaThresholdFragmentProcessor.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#endif #endif
@ -97,28 +97,25 @@ sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* contex
const SkMatrix& inMatrix, const SkMatrix& inMatrix,
const SkIRect& bounds) const { const SkIRect& bounds) const {
sk_sp<GrDrawContext> drawContext(context->makeDrawContextWithFallback(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContextWithFallback(
bounds.width(), SkBackingFit::kApprox, bounds.width(), bounds.height(), kAlpha_8_GrPixelConfig, nullptr));
bounds.height(), if (!renderTargetContext) {
kAlpha_8_GrPixelConfig,
nullptr));
if (!drawContext) {
return nullptr; return nullptr;
} }
GrPaint grPaint; GrPaint grPaint;
grPaint.setPorterDuffXPFactory(SkBlendMode::kSrc); grPaint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkRegion::Iterator iter(fRegion); SkRegion::Iterator iter(fRegion);
drawContext->clear(nullptr, 0x0, true); renderTargetContext->clear(nullptr, 0x0, true);
GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height())); GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height()));
while (!iter.done()) { while (!iter.done()) {
SkRect rect = SkRect::Make(iter.rect()); SkRect rect = SkRect::Make(iter.rect());
drawContext->drawRect(clip, grPaint, inMatrix, rect); renderTargetContext->drawRect(clip, grPaint, inMatrix, rect);
iter.next(); iter.next();
} }
return drawContext->asTexture(); return renderTargetContext->asTexture();
} }
#endif #endif

View File

@ -18,7 +18,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrCircleBlurFragmentProcessor.h" #include "GrCircleBlurFragmentProcessor.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrTexture.h" #include "GrTexture.h"
#include "GrFragmentProcessor.h" #include "GrFragmentProcessor.h"
#include "GrInvariantOutput.h" #include "GrInvariantOutput.h"
@ -50,14 +50,14 @@ public:
const SkMatrix& ctm, const SkMatrix& ctm,
SkRect* maskRect) const override; SkRect* maskRect) const override;
bool directFilterMaskGPU(GrTextureProvider* texProvider, bool directFilterMaskGPU(GrTextureProvider* texProvider,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
GrPaint* grp, GrPaint* grp,
const GrClip&, const GrClip&,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec, const SkStrokeRec& strokeRec,
const SkPath& path) const override; const SkPath& path) const override;
bool directFilterRRectMaskGPU(GrContext*, bool directFilterRRectMaskGPU(GrContext*,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
GrPaint* grp, GrPaint* grp,
const GrClip&, const GrClip&,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -1011,13 +1011,13 @@ sk_sp<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTestData* d)
bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrTextureProvider* texProvider, bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrTextureProvider* texProvider,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
GrPaint* grp, GrPaint* grp,
const GrClip& clip, const GrClip& clip,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec, const SkStrokeRec& strokeRec,
const SkPath& path) const { const SkPath& path) const {
SkASSERT(drawContext); SkASSERT(renderTargetContext);
if (fBlurStyle != kNormal_SkBlurStyle) { if (fBlurStyle != kNormal_SkBlurStyle) {
return false; return false;
@ -1059,7 +1059,7 @@ bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrTextureProvider* texProvider,
return false; return false;
} }
drawContext->fillRectWithLocalMatrix(clip, *grp, SkMatrix::I(), rect, inverse); renderTargetContext->fillRectWithLocalMatrix(clip, *grp, SkMatrix::I(), rect, inverse);
return true; return true;
} }
@ -1121,34 +1121,33 @@ static sk_sp<GrTexture> find_or_create_rrect_blur_mask(GrContext* context,
sk_sp<GrTexture> mask(context->textureProvider()->findAndRefTextureByUniqueKey(key)); sk_sp<GrTexture> mask(context->textureProvider()->findAndRefTextureByUniqueKey(key));
if (!mask) { if (!mask) {
// TODO: this could be approx but the texture coords will need to be updated // TODO: this could be approx but the texture coords will need to be updated
sk_sp<GrDrawContext> dc(context->makeDrawContextWithFallback(SkBackingFit::kExact, sk_sp<GrRenderTargetContext> rtc(context->makeRenderTargetContextWithFallback(
size.fWidth, size.fHeight, SkBackingFit::kExact, size.fWidth, size.fHeight, kAlpha_8_GrPixelConfig, nullptr));
kAlpha_8_GrPixelConfig, if (!rtc) {
nullptr));
if (!dc) {
return nullptr; return nullptr;
} }
GrPaint grPaint; GrPaint grPaint;
grPaint.setAntiAlias(doAA); grPaint.setAntiAlias(doAA);
dc->clear(nullptr, 0x0, true); rtc->clear(nullptr, 0x0, true);
dc->drawRRect(GrNoClip(), grPaint, SkMatrix::I(), rrectToDraw, GrStyle::SimpleFill()); rtc->drawRRect(GrNoClip(), grPaint, SkMatrix::I(), rrectToDraw, GrStyle::SimpleFill());
sk_sp<GrTexture> srcTexture(dc->asTexture()); sk_sp<GrTexture> srcTexture(rtc->asTexture());
sk_sp<GrDrawContext> dc2(SkGpuBlurUtils::GaussianBlur(context, sk_sp<GrRenderTargetContext> rtc2(SkGpuBlurUtils::GaussianBlur(context,
srcTexture.get(), srcTexture.get(),
nullptr, nullptr,
SkIRect::MakeWH(size.fWidth, SkIRect::MakeWH(
size.fHeight), size.fWidth,
nullptr, size.fHeight),
xformedSigma, xformedSigma, nullptr,
SkBackingFit::kExact)); xformedSigma, xformedSigma,
if (!dc2) { SkBackingFit::kExact));
if (!rtc2) {
return nullptr; return nullptr;
} }
mask = dc2->asTexture(); mask = rtc2->asTexture();
SkASSERT(mask); SkASSERT(mask);
context->textureProvider()->assignUniqueKeyToTexture(key, mask.get()); context->textureProvider()->assignUniqueKeyToTexture(key, mask.get());
} }
@ -1333,14 +1332,14 @@ GrGLSLFragmentProcessor* GrRRectBlurEffect::onCreateGLSLInstance() const {
} }
bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context, bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
GrPaint* grp, GrPaint* grp,
const GrClip& clip, const GrClip& clip,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkStrokeRec& strokeRec, const SkStrokeRec& strokeRec,
const SkRRect& srcRRect, const SkRRect& srcRRect,
const SkRRect& devRRect) const { const SkRRect& devRRect) const {
SkASSERT(drawContext); SkASSERT(renderTargetContext);
if (fBlurStyle != kNormal_SkBlurStyle) { if (fBlurStyle != kNormal_SkBlurStyle) {
return false; return false;
@ -1380,7 +1379,7 @@ bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
SkRect srcProxyRect = srcRRect.rect(); SkRect srcProxyRect = srcRRect.rect();
srcProxyRect.outset(3.0f*fSigma, 3.0f*fSigma); srcProxyRect.outset(3.0f*fSigma, 3.0f*fSigma);
drawContext->drawRect(clip, newPaint, viewMatrix, srcProxyRect); renderTargetContext->drawRect(clip, newPaint, viewMatrix, srcProxyRect);
return true; return true;
} }
@ -1425,8 +1424,8 @@ bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
numIndices = 6; numIndices = 6;
} }
drawContext->drawVertices(clip, newPaint, viewMatrix, kTriangles_GrPrimitiveType, renderTargetContext->drawVertices(clip, newPaint, viewMatrix, kTriangles_GrPrimitiveType,
numPoints, points, nullptr, nullptr, indices, numIndices); numPoints, points, nullptr, nullptr, indices, numIndices);
} else { } else {
SkMatrix inverse; SkMatrix inverse;
@ -1439,7 +1438,8 @@ bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
proxyRect.outset(extra, extra); proxyRect.outset(extra, extra);
drawContext->fillRectWithLocalMatrix(clip, newPaint, SkMatrix::I(), proxyRect, inverse); renderTargetContext->fillRectWithLocalMatrix(clip, newPaint, SkMatrix::I(), proxyRect,
inverse);
} }
return true; return true;
@ -1502,10 +1502,12 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
// If we're doing a normal blur, we can clobber the pathTexture in the // If we're doing a normal blur, we can clobber the pathTexture in the
// gaussianBlur. Otherwise, we need to save it for later compositing. // gaussianBlur. Otherwise, we need to save it for later compositing.
bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle);
sk_sp<GrDrawContext> drawContext(SkGpuBlurUtils::GaussianBlur(context, src, nullptr, sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::GaussianBlur(context, src,
clipRect, nullptr, nullptr, clipRect,
xformedSigma, xformedSigma)); nullptr,
if (!drawContext) { xformedSigma,
xformedSigma));
if (!renderTargetContext) {
return false; return false;
} }
@ -1530,10 +1532,10 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
paint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); paint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
} }
drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), SkRect::Make(clipRect)); renderTargetContext->drawRect(GrNoClip(), paint, SkMatrix::I(), SkRect::Make(clipRect));
} }
*result = drawContext->asTexture().release(); *result = renderTargetContext->asTexture().release();
return true; return true;
} }

View File

@ -15,7 +15,7 @@
#include "SkColorPriv.h" #include "SkColorPriv.h"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrCoordTransform.h" #include "GrCoordTransform.h"
#include "GrInvariantOutput.h" #include "GrInvariantOutput.h"
#include "SkGr.h" #include "SkGr.h"
@ -348,23 +348,23 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y())); matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y()));
SkColorSpace* colorSpace = ctx.outputProperties().colorSpace(); SkColorSpace* colorSpace = ctx.outputProperties().colorSpace();
sk_sp<GrDrawContext> drawContext( sk_sp<GrRenderTargetContext> renderTargetContext(
context->makeDrawContext(SkBackingFit::kApprox, bounds.width(), bounds.height(), context->makeRenderTargetContext(SkBackingFit::kApprox, bounds.width(), bounds.height(),
GrRenderableConfigForColorSpace(colorSpace), GrRenderableConfigForColorSpace(colorSpace),
sk_ref_sp(colorSpace))); sk_ref_sp(colorSpace)));
if (!drawContext) { if (!renderTargetContext) {
return nullptr; return nullptr;
} }
paint.setGammaCorrect(drawContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
drawContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(colorBounds)); renderTargetContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(colorBounds));
offset->fX = bounds.left(); offset->fX = bounds.left();
offset->fY = bounds.top(); offset->fY = bounds.top();
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()), return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage, kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(), renderTargetContext->asTexture(),
sk_ref_sp(drawContext->getColorSpace())); sk_ref_sp(renderTargetContext->getColorSpace()));
} }
#endif #endif

View File

@ -16,7 +16,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "GrFragmentProcessor.h" #include "GrFragmentProcessor.h"
#include "GrInvariantOutput.h" #include "GrInvariantOutput.h"
@ -369,7 +369,7 @@ protected:
#endif #endif
private: private:
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
void drawRect(GrDrawContext* drawContext, void drawRect(GrRenderTargetContext* renderTargetContext,
GrTexture* src, GrTexture* src,
const SkMatrix& matrix, const SkMatrix& matrix,
const GrClip& clip, const GrClip& clip,
@ -382,7 +382,7 @@ private:
}; };
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, void SkLightingImageFilterInternal::drawRect(GrRenderTargetContext* renderTargetContext,
GrTexture* src, GrTexture* src,
const SkMatrix& matrix, const SkMatrix& matrix,
const GrClip& clip, const GrClip& clip,
@ -392,12 +392,12 @@ void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext,
const SkIRect& bounds) const { const SkIRect& bounds) const {
SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y())); SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()));
GrPaint paint; GrPaint paint;
paint.setGammaCorrect(drawContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(src, matrix, srcBounds, sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(src, matrix, srcBounds,
boundaryMode)); boundaryMode));
paint.addColorFragmentProcessor(std::move(fp)); paint.addColorFragmentProcessor(std::move(fp));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); renderTargetContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
} }
sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU( sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(
@ -413,11 +413,11 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(
sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
SkASSERT(inputTexture); SkASSERT(inputTexture);
sk_sp<GrDrawContext> drawContext( sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
context->makeDrawContext(SkBackingFit::kApprox,offsetBounds.width(), offsetBounds.height(), SkBackingFit::kApprox,offsetBounds.width(), offsetBounds.height(),
GrRenderableConfigForColorSpace(outputProperties.colorSpace()), GrRenderableConfigForColorSpace(outputProperties.colorSpace()),
sk_ref_sp(outputProperties.colorSpace()))); sk_ref_sp(outputProperties.colorSpace())));
if (!drawContext) { if (!renderTargetContext) {
return nullptr; return nullptr;
} }
@ -439,29 +439,29 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(
SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1); SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1);
const SkIRect* pSrcBounds = inputBounds.contains(offsetBounds) ? nullptr : &inputBounds; const SkIRect* pSrcBounds = inputBounds.contains(offsetBounds) ? nullptr : &inputBounds;
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, topLeft, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, topLeft,
kTopLeft_BoundaryMode, pSrcBounds, offsetBounds); kTopLeft_BoundaryMode, pSrcBounds, offsetBounds);
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, top, kTop_BoundaryMode, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, top,
pSrcBounds, offsetBounds); kTop_BoundaryMode, pSrcBounds, offsetBounds);
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, topRight, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, topRight,
kTopRight_BoundaryMode, pSrcBounds, offsetBounds); kTopRight_BoundaryMode, pSrcBounds, offsetBounds);
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, left, kLeft_BoundaryMode, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, left,
pSrcBounds, offsetBounds); kLeft_BoundaryMode, pSrcBounds, offsetBounds);
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, interior, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, interior,
kInterior_BoundaryMode, pSrcBounds, offsetBounds); kInterior_BoundaryMode, pSrcBounds, offsetBounds);
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, right, kRight_BoundaryMode, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, right,
pSrcBounds, offsetBounds); kRight_BoundaryMode, pSrcBounds, offsetBounds);
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, bottomLeft, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomLeft,
kBottomLeft_BoundaryMode, pSrcBounds, offsetBounds); kBottomLeft_BoundaryMode, pSrcBounds, offsetBounds);
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, bottom, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottom,
kBottom_BoundaryMode, pSrcBounds, offsetBounds); kBottom_BoundaryMode, pSrcBounds, offsetBounds);
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, bottomRight, this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomRight,
kBottomRight_BoundaryMode, pSrcBounds, offsetBounds); kBottomRight_BoundaryMode, pSrcBounds, offsetBounds);
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height()), return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height()),
kNeedNewImageUniqueID_SpecialImage, kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(), renderTargetContext->asTexture(),
sk_ref_sp(drawContext->getColorSpace())); sk_ref_sp(renderTargetContext->getColorSpace()));
} }
#endif #endif

View File

@ -17,7 +17,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h"
#include "GrInvariantOutput.h" #include "GrInvariantOutput.h"
#include "effects/GrSingleTextureEffect.h" #include "effects/GrSingleTextureEffect.h"
#include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentProcessor.h"

View File

@ -17,7 +17,6 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h"
#include "effects/GrMatrixConvolutionEffect.h" #include "effects/GrMatrixConvolutionEffect.h"
#endif #endif

View File

@ -17,7 +17,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "GrInvariantOutput.h" #include "GrInvariantOutput.h"
#include "GrTexture.h" #include "GrTexture.h"
@ -385,7 +385,7 @@ sk_sp<GrFragmentProcessor> GrMorphologyEffect::TestCreate(GrProcessorTestData* d
} }
static void apply_morphology_rect(GrDrawContext* drawContext, static void apply_morphology_rect(GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
GrTexture* texture, GrTexture* texture,
const SkIRect& srcRect, const SkIRect& srcRect,
@ -395,18 +395,18 @@ static void apply_morphology_rect(GrDrawContext* drawContext,
float bounds[2], float bounds[2],
Gr1DKernelEffect::Direction direction) { Gr1DKernelEffect::Direction direction) {
GrPaint paint; GrPaint paint;
paint.setGammaCorrect(drawContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
paint.addColorFragmentProcessor(GrMorphologyEffect::Make(texture, paint.addColorFragmentProcessor(GrMorphologyEffect::Make(texture,
direction, direction,
radius, radius,
morphType, morphType,
bounds)); bounds));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
drawContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect), renderTargetContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect)); SkRect::Make(srcRect));
} }
static void apply_morphology_rect_no_bounds(GrDrawContext* drawContext, static void apply_morphology_rect_no_bounds(GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
GrTexture* texture, GrTexture* texture,
const SkIRect& srcRect, const SkIRect& srcRect,
@ -415,15 +415,15 @@ static void apply_morphology_rect_no_bounds(GrDrawContext* drawContext,
GrMorphologyEffect::MorphologyType morphType, GrMorphologyEffect::MorphologyType morphType,
Gr1DKernelEffect::Direction direction) { Gr1DKernelEffect::Direction direction) {
GrPaint paint; GrPaint paint;
paint.setGammaCorrect(drawContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
paint.addColorFragmentProcessor(GrMorphologyEffect::Make(texture, direction, radius, paint.addColorFragmentProcessor(GrMorphologyEffect::Make(texture, direction, radius,
morphType)); morphType));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
drawContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect), renderTargetContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect)); SkRect::Make(srcRect));
} }
static void apply_morphology_pass(GrDrawContext* drawContext, static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
GrTexture* texture, GrTexture* texture,
const SkIRect& srcRect, const SkIRect& srcRect,
@ -456,16 +456,16 @@ static void apply_morphology_pass(GrDrawContext* drawContext,
} }
if (middleSrcRect.fLeft - middleSrcRect.fRight >= 0) { if (middleSrcRect.fLeft - middleSrcRect.fRight >= 0) {
// radius covers srcRect; use bounds over entire draw // radius covers srcRect; use bounds over entire draw
apply_morphology_rect(drawContext, clip, texture, srcRect, dstRect, radius, apply_morphology_rect(renderTargetContext, clip, texture, srcRect, dstRect, radius,
morphType, bounds, direction); morphType, bounds, direction);
} else { } else {
// Draw upper and lower margins with bounds; middle without. // Draw upper and lower margins with bounds; middle without.
apply_morphology_rect(drawContext, clip, texture, lowerSrcRect, lowerDstRect, radius, apply_morphology_rect(renderTargetContext, clip, texture, lowerSrcRect, lowerDstRect,
morphType, bounds, direction); radius, morphType, bounds, direction);
apply_morphology_rect(drawContext, clip, texture, upperSrcRect, upperDstRect, radius, apply_morphology_rect(renderTargetContext, clip, texture, upperSrcRect, upperDstRect,
morphType, bounds, direction); radius, morphType, bounds, direction);
apply_morphology_rect_no_bounds(drawContext, clip, texture, middleSrcRect, middleDstRect, apply_morphology_rect_no_bounds(renderTargetContext, clip, texture, middleSrcRect,
radius, morphType, direction); middleDstRect, radius, morphType, direction);
} }
} }
@ -490,14 +490,13 @@ static sk_sp<SkSpecialImage> apply_morphology(
SkASSERT(radius.width() > 0 || radius.height() > 0); SkASSERT(radius.width() > 0 || radius.height() > 0);
if (radius.fWidth > 0) { if (radius.fWidth > 0) {
sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeRenderTargetContext(
rect.width(), rect.height(), SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace));
config, colorSpace)); if (!dstRenderTargetContext) {
if (!dstDrawContext) {
return nullptr; return nullptr;
} }
apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), apply_morphology_pass(dstRenderTargetContext.get(), clip, srcTexture.get(),
srcRect, dstRect, radius.fWidth, morphType, srcRect, dstRect, radius.fWidth, morphType,
Gr1DKernelEffect::kX_Direction); Gr1DKernelEffect::kX_Direction);
SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
@ -505,24 +504,23 @@ static sk_sp<SkSpecialImage> apply_morphology(
GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphType GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphType
? SK_ColorWHITE ? SK_ColorWHITE
: SK_ColorTRANSPARENT; : SK_ColorTRANSPARENT;
dstDrawContext->clear(&clearRect, clearColor, false); dstRenderTargetContext->clear(&clearRect, clearColor, false);
srcTexture = dstDrawContext->asTexture(); srcTexture = dstRenderTargetContext->asTexture();
srcRect = dstRect; srcRect = dstRect;
} }
if (radius.fHeight > 0) { if (radius.fHeight > 0) {
sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeRenderTargetContext(
rect.width(), rect.height(), SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace));
config, colorSpace)); if (!dstRenderTargetContext) {
if (!dstDrawContext) {
return nullptr; return nullptr;
} }
apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), apply_morphology_pass(dstRenderTargetContext.get(), clip, srcTexture.get(),
srcRect, dstRect, radius.fHeight, morphType, srcRect, dstRect, radius.fHeight, morphType,
Gr1DKernelEffect::kY_Direction); Gr1DKernelEffect::kY_Direction);
srcTexture = dstDrawContext->asTexture(); srcTexture = dstRenderTargetContext->asTexture();
} }
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height()), return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height()),

View File

@ -17,7 +17,7 @@
#include "SkXfermode.h" #include "SkXfermode.h"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "effects/GrConstColorProcessor.h" #include "effects/GrConstColorProcessor.h"
#include "effects/GrTextureDomain.h" #include "effects/GrTextureDomain.h"
#include "effects/GrSimpleTextureEffect.h" #include "effects/GrSimpleTextureEffect.h"
@ -301,23 +301,23 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU(
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
sk_sp<GrDrawContext> drawContext( sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
context->makeDrawContext(SkBackingFit::kApprox, bounds.width(), bounds.height(), SkBackingFit::kApprox, bounds.width(), bounds.height(),
GrRenderableConfigForColorSpace(outputProperties.colorSpace()), GrRenderableConfigForColorSpace(outputProperties.colorSpace()),
sk_ref_sp(outputProperties.colorSpace()))); sk_ref_sp(outputProperties.colorSpace())));
if (!drawContext) { if (!renderTargetContext) {
return nullptr; return nullptr;
} }
paint.setGammaCorrect(drawContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
SkMatrix matrix; SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())); matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
drawContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(bounds)); renderTargetContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(bounds));
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()), return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage, kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(), renderTargetContext->asTexture(),
sk_ref_sp(drawContext->getColorSpace())); sk_ref_sp(renderTargetContext->getColorSpace()));
} }
sk_sp<GrFragmentProcessor> sk_sp<GrFragmentProcessor>

View File

@ -6,7 +6,7 @@
*/ */
#include "GrBlurUtils.h" #include "GrBlurUtils.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
@ -27,7 +27,7 @@ static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& r
// Draw a mask using the supplied paint. Since the coverage/geometry // Draw a mask using the supplied paint. Since the coverage/geometry
// is already burnt into the mask this boils down to a rect draw. // is already burnt into the mask this boils down to a rect draw.
// Return true if the mask was successfully drawn. // Return true if the mask was successfully drawn.
static bool draw_mask(GrDrawContext* drawContext, static bool draw_mask(GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkIRect& maskRect, const SkIRect& maskRect,
@ -43,12 +43,12 @@ static bool draw_mask(GrDrawContext* drawContext,
if (!viewMatrix.invert(&inverse)) { if (!viewMatrix.invert(&inverse)) {
return false; return false;
} }
drawContext->fillRectWithLocalMatrix(clip, *grp, SkMatrix::I(), SkRect::Make(maskRect), renderTargetContext->fillRectWithLocalMatrix(clip, *grp, SkMatrix::I(), SkRect::Make(maskRect),
inverse); inverse);
return true; return true;
} }
static bool sw_draw_with_mask_filter(GrDrawContext* drawContext, static bool sw_draw_with_mask_filter(GrRenderTargetContext* renderTargetContext,
GrTextureProvider* textureProvider, GrTextureProvider* textureProvider,
const GrClip& clipData, const GrClip& clipData,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -88,7 +88,7 @@ static bool sw_draw_with_mask_filter(GrDrawContext* drawContext,
texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
dstM.fImage, dstM.fRowBytes); dstM.fImage, dstM.fRowBytes);
return draw_mask(drawContext, clipData, viewMatrix, dstM.fBounds, grp, texture); return draw_mask(renderTargetContext, clipData, viewMatrix, dstM.fBounds, grp, texture);
} }
// Create a mask of 'devPath' and place the result in 'mask'. // Create a mask of 'devPath' and place the result in 'mask'.
@ -103,17 +103,14 @@ static sk_sp<GrTexture> create_mask_GPU(GrContext* context,
sampleCnt = 0; sampleCnt = 0;
} }
sk_sp<GrDrawContext> drawContext(context->makeDrawContextWithFallback(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContextWithFallback(
maskRect.width(), SkBackingFit::kApprox, maskRect.width(), maskRect.height(), kAlpha_8_GrPixelConfig, nullptr,
maskRect.height(), sampleCnt));
kAlpha_8_GrPixelConfig, if (!renderTargetContext) {
nullptr,
sampleCnt));
if (!drawContext) {
return nullptr; return nullptr;
} }
drawContext->clear(nullptr, 0x0, true); renderTargetContext->clear(nullptr, 0x0, true);
GrPaint tempPaint; GrPaint tempPaint;
tempPaint.setAntiAlias(doAA); tempPaint.setAntiAlias(doAA);
@ -127,12 +124,12 @@ static sk_sp<GrTexture> create_mask_GPU(GrContext* context,
// the origin using tempPaint. // the origin using tempPaint.
SkMatrix translate; SkMatrix translate;
translate.setTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop)); translate.setTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop));
drawContext->drawPath(clip, tempPaint, translate, devPath, GrStyle(fillOrHairline)); renderTargetContext->drawPath(clip, tempPaint, translate, devPath, GrStyle(fillOrHairline));
return drawContext->asTexture();; return renderTargetContext->asTexture();;
} }
static void draw_path_with_mask_filter(GrContext* context, static void draw_path_with_mask_filter(GrContext* context,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
GrPaint* paint, GrPaint* paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -143,7 +140,8 @@ static void draw_path_with_mask_filter(GrContext* context,
SkASSERT(maskFilter); SkASSERT(maskFilter);
SkIRect clipBounds; SkIRect clipBounds;
clip.getConservativeBounds(drawContext->width(), drawContext->height(), &clipBounds); clip.getConservativeBounds(renderTargetContext->width(), renderTargetContext->height(),
&clipBounds);
SkTLazy<SkPath> tmpPath; SkTLazy<SkPath> tmpPath;
SkStrokeRec::InitStyle fillOrHairline; SkStrokeRec::InitStyle fillOrHairline;
@ -195,7 +193,7 @@ static void draw_path_with_mask_filter(GrContext* context,
} }
if (maskFilter->directFilterMaskGPU(context->textureProvider(), if (maskFilter->directFilterMaskGPU(context->textureProvider(),
drawContext, renderTargetContext,
paint, paint,
clip, clip,
viewMatrix, viewMatrix,
@ -211,14 +209,14 @@ static void draw_path_with_mask_filter(GrContext* context,
*path, *path,
fillOrHairline, fillOrHairline,
paint->isAntiAlias(), paint->isAntiAlias(),
drawContext->numColorSamples())); renderTargetContext->numColorSamples()));
if (mask) { if (mask) {
GrTexture* filtered; GrTexture* filtered;
if (maskFilter->filterMaskGPU(mask.get(), viewMatrix, finalIRect, &filtered)) { if (maskFilter->filterMaskGPU(mask.get(), viewMatrix, finalIRect, &filtered)) {
// filterMaskGPU gives us ownership of a ref to the result // filterMaskGPU gives us ownership of a ref to the result
SkAutoTUnref<GrTexture> atu(filtered); SkAutoTUnref<GrTexture> atu(filtered);
if (draw_mask(drawContext, clip, viewMatrix, finalIRect, paint, filtered)) { if (draw_mask(renderTargetContext, clip, viewMatrix, finalIRect, paint, filtered)) {
// This path is completely drawn // This path is completely drawn
return; return;
} }
@ -226,13 +224,13 @@ static void draw_path_with_mask_filter(GrContext* context,
} }
} }
sw_draw_with_mask_filter(drawContext, context->textureProvider(), sw_draw_with_mask_filter(renderTargetContext, context->textureProvider(),
clip, viewMatrix, *path, clip, viewMatrix, *path,
maskFilter, clipBounds, paint, fillOrHairline); maskFilter, clipBounds, paint, fillOrHairline);
} }
void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkPath& path, const SkPath& path,
GrPaint* paint, GrPaint* paint,
@ -240,12 +238,12 @@ void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,
const SkMaskFilter* mf, const SkMaskFilter* mf,
const GrStyle& style, const GrStyle& style,
bool pathIsMutable) { bool pathIsMutable) {
draw_path_with_mask_filter(context, drawContext, clip, paint, viewMatrix, mf, draw_path_with_mask_filter(context, renderTargetContext, clip, paint, viewMatrix, mf,
style, &path, pathIsMutable); style, &path, pathIsMutable);
} }
void GrBlurUtils::drawPathWithMaskFilter(GrContext* context, void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkPath& origPath, const SkPath& origPath,
const SkPaint& paint, const SkPaint& paint,
@ -281,17 +279,17 @@ void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,
SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;)
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(context, drawContext, paint, viewMatrix, &grPaint)) { if (!SkPaintToGrPaint(context, renderTargetContext, paint, viewMatrix, &grPaint)) {
return; return;
} }
SkMaskFilter* mf = paint.getMaskFilter(); SkMaskFilter* mf = paint.getMaskFilter();
if (mf && !mf->asFragmentProcessor(nullptr, nullptr, viewMatrix)) { if (mf && !mf->asFragmentProcessor(nullptr, nullptr, viewMatrix)) {
// The MaskFilter wasn't already handled in SkPaintToGrPaint // The MaskFilter wasn't already handled in SkPaintToGrPaint
draw_path_with_mask_filter(context, drawContext, clip, &grPaint, viewMatrix, draw_path_with_mask_filter(context, renderTargetContext, clip, &grPaint, viewMatrix,
mf, style, mf, style,
path, pathIsMutable); path, pathIsMutable);
} else { } else {
drawContext->drawPath(clip, grPaint, viewMatrix, *path, style); renderTargetContext->drawPath(clip, grPaint, viewMatrix, *path, style);
} }
} }

View File

@ -10,7 +10,7 @@
class GrClip; class GrClip;
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
class GrPaint; class GrPaint;
class GrRenderTarget; class GrRenderTarget;
class GrStyle; class GrStyle;
@ -30,7 +30,7 @@ namespace GrBlurUtils {
* Draw a path handling the mask filter if present. * Draw a path handling the mask filter if present.
*/ */
void drawPathWithMaskFilter(GrContext* context, void drawPathWithMaskFilter(GrContext* context,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkPath& origSrcPath, const SkPath& origSrcPath,
const SkPaint& paint, const SkPaint& paint,
@ -44,7 +44,7 @@ namespace GrBlurUtils {
* optional. The GrPaint will be modified after return. * optional. The GrPaint will be modified after return.
*/ */
void drawPathWithMaskFilter(GrContext*, void drawPathWithMaskFilter(GrContext*,
GrDrawContext*, GrRenderTargetContext*,
const GrClip&, const GrClip&,
const SkPath& path, const SkPath& path,
GrPaint*, GrPaint*,

View File

@ -10,7 +10,7 @@
#include "GrAppliedClip.h" #include "GrAppliedClip.h"
#include "GrContextPriv.h" #include "GrContextPriv.h"
#include "GrDrawingManager.h" #include "GrDrawingManager.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "GrGpuResourcePriv.h" #include "GrGpuResourcePriv.h"
#include "GrRenderTargetPriv.h" #include "GrRenderTargetPriv.h"
@ -92,7 +92,7 @@ static sk_sp<GrFragmentProcessor> create_fp_for_mask(GrTexture* result,
// 'prOut' to the non-SW path renderer that will do the job). // 'prOut' to the non-SW path renderer that will do the job).
bool GrClipStackClip::PathNeedsSWRenderer(GrContext* context, bool GrClipStackClip::PathNeedsSWRenderer(GrContext* context,
bool hasUserStencilSettings, bool hasUserStencilSettings,
const GrDrawContext* drawContext, const GrRenderTargetContext* renderTargetContext,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const Element* element, const Element* element,
GrPathRenderer** prOut, GrPathRenderer** prOut,
@ -134,7 +134,7 @@ bool GrClipStackClip::PathNeedsSWRenderer(GrContext* context,
canDrawArgs.fShape = &shape; canDrawArgs.fShape = &shape;
canDrawArgs.fAntiAlias = element->isAA(); canDrawArgs.fAntiAlias = element->isAA();
canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings;
canDrawArgs.fIsStencilBufferMSAA = drawContext->isStencilBufferMultisampled(); canDrawArgs.fIsStencilBufferMSAA = renderTargetContext->isStencilBufferMultisampled();
// the 'false' parameter disallows use of the SW path renderer // the 'false' parameter disallows use of the SW path renderer
GrPathRenderer* pr = GrPathRenderer* pr =
@ -153,7 +153,7 @@ bool GrClipStackClip::PathNeedsSWRenderer(GrContext* context,
*/ */
bool GrClipStackClip::UseSWOnlyPath(GrContext* context, bool GrClipStackClip::UseSWOnlyPath(GrContext* context,
bool hasUserStencilSettings, bool hasUserStencilSettings,
const GrDrawContext* drawContext, const GrRenderTargetContext* renderTargetContext,
const GrReducedClip& reducedClip) { const GrReducedClip& reducedClip) {
// TODO: generalize this function so that when // TODO: generalize this function so that when
// a clip gets complex enough it can just be done in SW regardless // a clip gets complex enough it can just be done in SW regardless
@ -173,7 +173,7 @@ bool GrClipStackClip::UseSWOnlyPath(GrContext* context,
SkCanvas::kIntersect_Op == op || SkCanvas::kReverseDifference_Op == op; SkCanvas::kIntersect_Op == op || SkCanvas::kReverseDifference_Op == op;
if (PathNeedsSWRenderer(context, hasUserStencilSettings, if (PathNeedsSWRenderer(context, hasUserStencilSettings,
drawContext, translate, element, nullptr, needsStencil)) { renderTargetContext, translate, element, nullptr, needsStencil)) {
return true; return true;
} }
} }
@ -262,18 +262,18 @@ static bool get_analytic_clip_processor(const ElementList& elements,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// sort out what kind of clip mask needs to be created: alpha, stencil, // sort out what kind of clip mask needs to be created: alpha, stencil,
// scissor, or entirely software // scissor, or entirely software
bool GrClipStackClip::apply(GrContext* context, GrDrawContext* drawContext, bool useHWAA, bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTargetContext,
bool hasUserStencilSettings, GrAppliedClip* out) const { bool useHWAA, bool hasUserStencilSettings, GrAppliedClip* out) const {
if (!fStack || fStack->isWideOpen()) { if (!fStack || fStack->isWideOpen()) {
return true; return true;
} }
SkRect devBounds = SkRect::MakeIWH(drawContext->width(), drawContext->height()); SkRect devBounds = SkRect::MakeIWH(renderTargetContext->width(), renderTargetContext->height());
if (!devBounds.intersect(out->clippedDrawBounds())) { if (!devBounds.intersect(out->clippedDrawBounds())) {
return false; return false;
} }
GrRenderTarget* rt = drawContext->accessRenderTarget(); GrRenderTarget* rt = renderTargetContext->accessRenderTarget();
const SkScalar clipX = SkIntToScalar(fOrigin.x()), const SkScalar clipX = SkIntToScalar(fOrigin.x()),
clipY = SkIntToScalar(fOrigin.y()); clipY = SkIntToScalar(fOrigin.y());
@ -311,8 +311,8 @@ bool GrClipStackClip::apply(GrContext* context, GrDrawContext* drawContext, bool
if (reducedClip.elements().count() <= kMaxAnalyticElements) { if (reducedClip.elements().count() <= kMaxAnalyticElements) {
// When there are multiple samples we want to do per-sample clipping, not compute a // When there are multiple samples we want to do per-sample clipping, not compute a
// fractional pixel coverage. // fractional pixel coverage.
bool disallowAnalyticAA = drawContext->isStencilBufferMultisampled(); bool disallowAnalyticAA = renderTargetContext->isStencilBufferMultisampled();
if (disallowAnalyticAA && !drawContext->numColorSamples()) { if (disallowAnalyticAA && !renderTargetContext->numColorSamples()) {
// With a single color sample, any coverage info is lost from color once it hits the // With a single color sample, any coverage info is lost from color once it hits the
// color buffer anyway, so we may as well use coverage AA if nothing else in the pipe // color buffer anyway, so we may as well use coverage AA if nothing else in the pipe
// is multisampled. // is multisampled.
@ -328,9 +328,9 @@ bool GrClipStackClip::apply(GrContext* context, GrDrawContext* drawContext, bool
} }
// If the stencil buffer is multisampled we can use it to do everything. // If the stencil buffer is multisampled we can use it to do everything.
if (!drawContext->isStencilBufferMultisampled() && reducedClip.requiresAA()) { if (!renderTargetContext->isStencilBufferMultisampled() && reducedClip.requiresAA()) {
sk_sp<GrTexture> result; sk_sp<GrTexture> result;
if (UseSWOnlyPath(context, hasUserStencilSettings, drawContext, reducedClip)) { if (UseSWOnlyPath(context, hasUserStencilSettings, renderTargetContext, reducedClip)) {
// The clip geometry is complex enough that it will be more efficient to create it // The clip geometry is complex enough that it will be more efficient to create it
// entirely in software // entirely in software
result = CreateSoftwareClipMask(context->textureProvider(), reducedClip); result = CreateSoftwareClipMask(context->textureProvider(), reducedClip);
@ -365,7 +365,7 @@ bool GrClipStackClip::apply(GrContext* context, GrDrawContext* drawContext, bool
// after clipping is overhauled. // after clipping is overhauled.
if (stencilAttachment->mustRenderClip(reducedClip.elementsGenID(), reducedClip.ibounds(), if (stencilAttachment->mustRenderClip(reducedClip.elementsGenID(), reducedClip.ibounds(),
fOrigin)) { fOrigin)) {
reducedClip.drawStencilClipMask(context, drawContext, fOrigin); reducedClip.drawStencilClipMask(context, renderTargetContext, fOrigin);
stencilAttachment->setLastClip(reducedClip.elementsGenID(), reducedClip.ibounds(), stencilAttachment->setLastClip(reducedClip.elementsGenID(), reducedClip.ibounds(),
fOrigin); fOrigin);
} }
@ -393,20 +393,21 @@ sk_sp<GrTexture> GrClipStackClip::CreateAlphaClipMask(GrContext* context,
return sk_sp<GrTexture>(texture); return sk_sp<GrTexture>(texture);
} }
sk_sp<GrDrawContext> dc(context->makeDrawContextWithFallback(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> rtc(context->makeRenderTargetContextWithFallback(
reducedClip.width(), SkBackingFit::kApprox,
reducedClip.height(), reducedClip.width(),
kAlpha_8_GrPixelConfig, reducedClip.height(),
nullptr)); kAlpha_8_GrPixelConfig,
if (!dc) { nullptr));
if (!rtc) {
return nullptr; return nullptr;
} }
if (!reducedClip.drawAlphaClipMask(dc.get())) { if (!reducedClip.drawAlphaClipMask(rtc.get())) {
return nullptr; return nullptr;
} }
sk_sp<GrTexture> texture(dc->asTexture()); sk_sp<GrTexture> texture(rtc->asTexture());
SkASSERT(texture); SkASSERT(texture);
texture->resourcePriv().setUniqueKey(key); texture->resourcePriv().setUniqueKey(key);
return texture; return texture;

View File

@ -35,7 +35,7 @@ public:
bool quickContains(const SkRRect&) const final; bool quickContains(const SkRRect&) const final;
void getConservativeBounds(int width, int height, SkIRect* devResult, void getConservativeBounds(int width, int height, SkIRect* devResult,
bool* isIntersectionOfRects) const final; bool* isIntersectionOfRects) const final;
bool apply(GrContext*, GrDrawContext*, bool useHWAA, bool hasUserStencilSettings, bool apply(GrContext*, GrRenderTargetContext*, bool useHWAA, bool hasUserStencilSettings,
GrAppliedClip* out) const final; GrAppliedClip* out) const final;
bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override; bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override;
@ -43,7 +43,7 @@ public:
private: private:
static bool PathNeedsSWRenderer(GrContext* context, static bool PathNeedsSWRenderer(GrContext* context,
bool hasUserStencilSettings, bool hasUserStencilSettings,
const GrDrawContext*, const GrRenderTargetContext*,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkClipStack::Element* element, const SkClipStack::Element* element,
GrPathRenderer** prOut, GrPathRenderer** prOut,
@ -58,7 +58,7 @@ private:
static bool UseSWOnlyPath(GrContext*, static bool UseSWOnlyPath(GrContext*,
bool hasUserStencilSettings, bool hasUserStencilSettings,
const GrDrawContext*, const GrRenderTargetContext*,
const GrReducedClip&); const GrReducedClip&);
static GrTexture* CreateCachedMask(int width, int height, const GrUniqueKey& key, static GrTexture* CreateCachedMask(int width, int height, const GrUniqueKey& key,

View File

@ -9,7 +9,7 @@
#include "GrContextPriv.h" #include "GrContextPriv.h"
#include "GrContextOptions.h" #include "GrContextOptions.h"
#include "GrDrawingManager.h" #include "GrDrawingManager.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrResourceCache.h" #include "GrResourceCache.h"
#include "GrResourceProvider.h" #include "GrResourceProvider.h"
#include "GrSoftwarePathRenderer.h" #include "GrSoftwarePathRenderer.h"
@ -208,9 +208,10 @@ void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
void GrContext::TextBlobCacheOverBudgetCB(void* data) { void GrContext::TextBlobCacheOverBudgetCB(void* data) {
SkASSERT(data); SkASSERT(data);
// TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on GrDrawContext // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on
// to perform a necessary flush. The solution is to move drawText calls to below the GrContext // GrRenderTargetContext to perform a necessary flush. The solution is to move drawText calls
// level, but this is not trivial because they call drawPath on SkGpuDevice. // to below the GrContext level, but this is not trivial because they call drawPath on
// SkGpuDevice.
GrContext* context = reinterpret_cast<GrContext*>(data); GrContext* context = reinterpret_cast<GrContext*>(data);
context->flush(); context->flush();
} }
@ -348,10 +349,10 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
// TODO: Need to decide the semantics of this function for color spaces. Do we support // TODO: Need to decide the semantics of this function for color spaces. Do we support
// conversion from a passed-in color space? For now, specifying nullptr means that this // conversion from a passed-in color space? For now, specifying nullptr means that this
// path will do no conversion, so it will match the behavior of the non-draw path. // path will do no conversion, so it will match the behavior of the non-draw path.
sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext( sk_sp<GrRenderTargetContext> renderTargetContext(
sk_ref_sp(renderTarget), this->contextPriv().makeWrappedRenderTargetContext(sk_ref_sp(renderTarget),
nullptr)); nullptr));
if (!drawContext) { if (!renderTargetContext) {
return false; return false;
} }
GrPaint paint; GrPaint paint;
@ -359,7 +360,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
paint.setAllowSRGBInputs(true); paint.setAllowSRGBInputs(true);
SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); renderTargetContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr);
if (kFlushWrites_PixelOp & pixelOpsFlags) { if (kFlushWrites_PixelOp & pixelOpsFlags) {
this->flushSurfaceWrites(surface); this->flushSurfaceWrites(surface);
@ -440,7 +441,8 @@ bool GrContext::readSurfacePixels(GrSurface* src,
// TODO: Need to decide the semantics of this function for color spaces. Do we support // TODO: Need to decide the semantics of this function for color spaces. Do we support
// conversion to a passed-in color space? For now, specifying nullptr means that this // conversion to a passed-in color space? For now, specifying nullptr means that this
// path will do no conversion, so it will match the behavior of the non-draw path. // path will do no conversion, so it will match the behavior of the non-draw path.
sk_sp<GrDrawContext> tempDC = this->makeDrawContext(tempDrawInfo.fTempSurfaceFit, sk_sp<GrRenderTargetContext> tempDC = this->makeRenderTargetContext(
tempDrawInfo.fTempSurfaceFit,
tempDrawInfo.fTempSurfaceDesc.fWidth, tempDrawInfo.fTempSurfaceDesc.fWidth,
tempDrawInfo.fTempSurfaceDesc.fHeight, tempDrawInfo.fTempSurfaceDesc.fHeight,
tempDrawInfo.fTempSurfaceDesc.fConfig, tempDrawInfo.fTempSurfaceDesc.fConfig,
@ -544,22 +546,22 @@ bool GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
&clippedSrcRect, &clippedDstPoint)) { &clippedSrcRect, &clippedDstPoint)) {
return false; return false;
} }
// If we don't have an RT for the dst then we won't have a GrDrawContext to insert the // If we don't have an RT for the dst then we won't have a GrRenderTargetContext to insert
// the copy surface into. In the future we plan to have a more limited Context type // the copy surface into. In the future we plan to have a more limited Context type
// (GrCopyContext?) that has the subset of GrDrawContext operations that should be // (GrCopyContext?) that has the subset of GrRenderTargetContext operations that should be
// allowed on textures that aren't render targets. // allowed on textures that aren't render targets.
// For now we just flush any writes to the src and issue an immediate copy to the dst. // For now we just flush any writes to the src and issue an immediate copy to the dst.
src->flushWrites(); src->flushWrites();
return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint);
} }
sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext( sk_sp<GrRenderTargetContext> renderTargetContext(
sk_ref_sp(dst->asRenderTarget()), this->contextPriv().makeWrappedRenderTargetContext(sk_ref_sp(dst->asRenderTarget()),
nullptr)); nullptr));
if (!drawContext) { if (!renderTargetContext) {
return false; return false;
} }
if (!drawContext->copySurface(src, srcRect, dstPoint)) { if (!renderTargetContext->copySurface(src, srcRect, dstPoint)) {
return false; return false;
} }
return true; return true;
@ -600,19 +602,20 @@ int GrContext::getRecommendedSampleCount(GrPixelConfig config,
return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCount : 0; return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCount : 0;
} }
sk_sp<GrDrawContext> GrContextPriv::makeWrappedDrawContext(sk_sp<GrRenderTarget> rt, sk_sp<GrRenderTargetContext> GrContextPriv::makeWrappedRenderTargetContext(
sk_sp<SkColorSpace> colorSpace, sk_sp<GrRenderTarget> rt,
const SkSurfaceProps* surfaceProps) { sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
return this->drawingManager()->makeDrawContext(std::move(rt), return this->drawingManager()->makeRenderTargetContext(std::move(rt), std::move(colorSpace),
std::move(colorSpace), surfaceProps);
surfaceProps);
} }
sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureDrawContext(const GrBackendTextureDesc& desc, sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext(
sk_sp<SkColorSpace> colorSpace, const GrBackendTextureDesc& desc,
const SkSurfaceProps* props, sk_sp<SkColorSpace> colorSpace,
GrWrapOwnership ownership) { const SkSurfaceProps* props,
GrWrapOwnership ownership) {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
@ -621,11 +624,11 @@ sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureDrawContext(const GrBacken
return nullptr; return nullptr;
} }
return this->drawingManager()->makeDrawContext(sk_ref_sp(surface->asRenderTarget()), return this->drawingManager()->makeRenderTargetContext(sk_ref_sp(surface->asRenderTarget()),
std::move(colorSpace), props); std::move(colorSpace), props);
} }
sk_sp<GrDrawContext> GrContextPriv::makeBackendRenderTargetDrawContext( sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetContext(
const GrBackendRenderTargetDesc& desc, const GrBackendRenderTargetDesc& desc,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) { const SkSurfaceProps* surfaceProps) {
@ -636,12 +639,11 @@ sk_sp<GrDrawContext> GrContextPriv::makeBackendRenderTargetDrawContext(
return nullptr; return nullptr;
} }
return this->drawingManager()->makeDrawContext(std::move(rt), return this->drawingManager()->makeRenderTargetContext(std::move(rt), std::move(colorSpace),
std::move(colorSpace), surfaceProps);
surfaceProps);
} }
sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureAsRenderTargetDrawContext( sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureAsRenderTargetRenderTargetContext(
const GrBackendTextureDesc& desc, const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) { const SkSurfaceProps* surfaceProps) {
@ -653,9 +655,8 @@ sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureAsRenderTargetDrawContext(
return nullptr; return nullptr;
} }
return this->drawingManager()->makeDrawContext(sk_ref_sp(surface->asRenderTarget()), return this->drawingManager()->makeRenderTargetContext(sk_ref_sp(surface->asRenderTarget()),
std::move(colorSpace), std::move(colorSpace), surfaceProps);
surfaceProps);
} }
static inline GrPixelConfig GrPixelConfigFallback(GrPixelConfig config) { static inline GrPixelConfig GrPixelConfigFallback(GrPixelConfig config) {
@ -698,30 +699,31 @@ static inline GrPixelConfig GrPixelConfigFallback(GrPixelConfig config) {
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFallback) == kGrPixelConfigCnt); GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFallback) == kGrPixelConfigCnt);
} }
sk_sp<GrDrawContext> GrContext::makeDrawContextWithFallback(SkBackingFit fit, sk_sp<GrRenderTargetContext> GrContext::makeRenderTargetContextWithFallback(
int width, int height, SkBackingFit fit,
GrPixelConfig config, int width, int height,
sk_sp<SkColorSpace> colorSpace, GrPixelConfig config,
int sampleCnt, sk_sp<SkColorSpace> colorSpace,
GrSurfaceOrigin origin, int sampleCnt,
const SkSurfaceProps* surfaceProps, GrSurfaceOrigin origin,
SkBudgeted budgeted) { const SkSurfaceProps* surfaceProps,
SkBudgeted budgeted) {
if (!this->caps()->isConfigRenderable(config, sampleCnt > 0)) { if (!this->caps()->isConfigRenderable(config, sampleCnt > 0)) {
config = GrPixelConfigFallback(config); config = GrPixelConfigFallback(config);
} }
return this->makeDrawContext(fit, width, height, config, std::move(colorSpace), return this->makeRenderTargetContext(fit, width, height, config, std::move(colorSpace),
sampleCnt, origin, surfaceProps, budgeted); sampleCnt, origin, surfaceProps, budgeted);
} }
sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit, sk_sp<GrRenderTargetContext> GrContext::makeRenderTargetContext(SkBackingFit fit,
int width, int height, int width, int height,
GrPixelConfig config, GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
int sampleCnt, int sampleCnt,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,
const SkSurfaceProps* surfaceProps, const SkSurfaceProps* surfaceProps,
SkBudgeted budgeted) { SkBudgeted budgeted) {
if (!this->caps()->isConfigRenderable(config, sampleCnt > 0)) { if (!this->caps()->isConfigRenderable(config, sampleCnt > 0)) {
return nullptr; return nullptr;
} }
@ -744,14 +746,14 @@ sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit,
return nullptr; return nullptr;
} }
sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext( sk_sp<GrRenderTargetContext> renderTargetContext(
sk_ref_sp(tex->asRenderTarget()), this->contextPriv().makeWrappedRenderTargetContext(sk_ref_sp(tex->asRenderTarget()),
std::move(colorSpace), surfaceProps)); std::move(colorSpace), surfaceProps));
if (!drawContext) { if (!renderTargetContext) {
return nullptr; return nullptr;
} }
return drawContext; return renderTargetContext;
} }
bool GrContext::abandoned() const { bool GrContext::abandoned() const {

View File

@ -17,21 +17,23 @@ class GrContextPriv {
public: public:
GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); } GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
// Create a drawContext that wraps an existing renderTarget // Create a renderTargetContext that wraps an existing renderTarget
sk_sp<GrDrawContext> makeWrappedDrawContext(sk_sp<GrRenderTarget> rt, sk_sp<GrRenderTargetContext> makeWrappedRenderTargetContext(sk_sp<GrRenderTarget> rt,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr); const SkSurfaceProps* = nullptr);
sk_sp<GrDrawContext> makeBackendTextureDrawContext(const GrBackendTextureDesc& desc, sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
sk_sp<SkColorSpace> colorSpace, const GrBackendTextureDesc& desc,
const SkSurfaceProps* = nullptr, sk_sp<SkColorSpace> colorSpace,
GrWrapOwnership = kBorrow_GrWrapOwnership); const SkSurfaceProps* = nullptr,
GrWrapOwnership = kBorrow_GrWrapOwnership);
sk_sp<GrDrawContext> makeBackendRenderTargetDrawContext(const GrBackendRenderTargetDesc& desc, sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
sk_sp<SkColorSpace> colorSpace, const GrBackendRenderTargetDesc& desc,
const SkSurfaceProps* = nullptr); sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr);
sk_sp<GrDrawContext> makeBackendTextureAsRenderTargetDrawContext( sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
const GrBackendTextureDesc& desc, const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr); const SkSurfaceProps* = nullptr);

View File

@ -8,8 +8,8 @@
#include "GrDrawingManager.h" #include "GrDrawingManager.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrPathRenderingDrawContext.h" #include "GrPathRenderingRenderTargetContext.h"
#include "GrResourceProvider.h" #include "GrResourceProvider.h"
#include "GrSoftwarePathRenderer.h" #include "GrSoftwarePathRenderer.h"
#include "GrSurfacePriv.h" #include "GrSurfacePriv.h"
@ -207,9 +207,10 @@ GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawP
return pr; return pr;
} }
sk_sp<GrDrawContext> GrDrawingManager::makeDrawContext(sk_sp<GrRenderTarget> rt, sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext(
sk_sp<SkColorSpace> colorSpace, sk_sp<GrRenderTarget> rt,
const SkSurfaceProps* surfaceProps) { sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) {
if (this->wasAbandoned()) { if (this->wasAbandoned()) {
return nullptr; return nullptr;
} }
@ -231,15 +232,16 @@ sk_sp<GrDrawContext> GrDrawingManager::makeDrawContext(sk_sp<GrRenderTarget> rt,
rt->isStencilBufferMultisampled()) { rt->isStencilBufferMultisampled()) {
GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt.get()); GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt.get());
if (sb) { if (sb) {
return sk_sp<GrDrawContext>(new GrPathRenderingDrawContext( return sk_sp<GrRenderTargetContext>(new GrPathRenderingRenderTargetContext(
fContext, this, std::move(rt), fContext, this, std::move(rt),
std::move(colorSpace), surfaceProps, std::move(colorSpace), surfaceProps,
fContext->getAuditTrail(), fSingleOwner)); fContext->getAuditTrail(), fSingleOwner));
} }
} }
return sk_sp<GrDrawContext>(new GrDrawContext(fContext, this, std::move(rt), return sk_sp<GrRenderTargetContext>(new GrRenderTargetContext(fContext, this, std::move(rt),
std::move(colorSpace), surfaceProps, std::move(colorSpace),
fContext->getAuditTrail(), surfaceProps,
fSingleOwner)); fContext->getAuditTrail(),
fSingleOwner));
} }

View File

@ -18,14 +18,14 @@
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
class GrSingleOWner; class GrSingleOWner;
class GrSoftwarePathRenderer; class GrSoftwarePathRenderer;
// The GrDrawingManager allocates a new GrDrawContext for each GrRenderTarget // The GrDrawingManager allocates a new GrRenderTargetContext for each GrRenderTarget
// but all of them still land in the same GrOpList! // but all of them still land in the same GrOpList!
// //
// In the future this class will allocate a new GrDrawContext for // In the future this class will allocate a new GrRenderTargetContext for
// each GrRenderTarget/GrOpList and manage the DAG. // each GrRenderTarget/GrOpList and manage the DAG.
class GrDrawingManager { class GrDrawingManager {
public: public:
@ -34,9 +34,9 @@ public:
bool wasAbandoned() const { return fAbandoned; } bool wasAbandoned() const { return fAbandoned; }
void freeGpuResources(); void freeGpuResources();
sk_sp<GrDrawContext> makeDrawContext(sk_sp<GrRenderTarget> rt, sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrRenderTarget> rt,
sk_sp<SkColorSpace>, sk_sp<SkColorSpace>,
const SkSurfaceProps*); const SkSurfaceProps*);
// The caller automatically gets a ref on the returned opList. It must // The caller automatically gets a ref on the returned opList. It must
// be balanced by an unref call. // be balanced by an unref call.

View File

@ -8,7 +8,7 @@
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "GrAppliedClip.h" #include "GrAppliedClip.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
bool GrFixedClip::quickContains(const SkRect& rect) const { bool GrFixedClip::quickContains(const SkRect& rect) const {
if (fWindowRectsState.enabled()) { if (fWindowRectsState.enabled()) {
@ -45,9 +45,10 @@ bool GrFixedClip::isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const {
return false; return false;
}; };
bool GrFixedClip::apply(GrContext*, GrDrawContext* dc, bool, bool, GrAppliedClip* out) const { bool GrFixedClip::apply(GrContext*, GrRenderTargetContext* rtc,
bool, bool, GrAppliedClip* out) const {
if (fScissorState.enabled()) { if (fScissorState.enabled()) {
SkIRect tightScissor = SkIRect::MakeWH(dc->width(), dc->height()); SkIRect tightScissor = SkIRect::MakeWH(rtc->width(), rtc->height());
if (!tightScissor.intersect(fScissorState.rect())) { if (!tightScissor.intersect(fScissorState.rect())) {
return false; return false;
} }

View File

@ -43,7 +43,7 @@ public:
bool quickContains(const SkRect&) const override; bool quickContains(const SkRect&) const override;
void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override; void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override;
bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override; bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override;
bool apply(GrContext*, GrDrawContext*, bool, bool, GrAppliedClip* out) const override; bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip* out) const override;
static const GrFixedClip& Disabled(); static const GrFixedClip& Disabled();

View File

@ -9,7 +9,7 @@
#define GrPathRenderer_DEFINED #define GrPathRenderer_DEFINED
#include "GrCaps.h" #include "GrCaps.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrPaint.h" #include "GrPaint.h"
#include "GrResourceProvider.h" #include "GrResourceProvider.h"
#include "GrShape.h" #include "GrShape.h"
@ -129,7 +129,7 @@ public:
const GrPaint* fPaint; const GrPaint* fPaint;
const GrUserStencilSettings*fUserStencilSettings; const GrUserStencilSettings*fUserStencilSettings;
GrDrawContext* fDrawContext; GrRenderTargetContext* fRenderTargetContext;
const GrClip* fClip; const GrClip* fClip;
const SkMatrix* fViewMatrix; const SkMatrix* fViewMatrix;
const GrShape* fShape; const GrShape* fShape;
@ -140,7 +140,7 @@ public:
SkASSERT(fResourceProvider); SkASSERT(fResourceProvider);
SkASSERT(fPaint); SkASSERT(fPaint);
SkASSERT(fUserStencilSettings); SkASSERT(fUserStencilSettings);
SkASSERT(fDrawContext); SkASSERT(fRenderTargetContext);
SkASSERT(fClip); SkASSERT(fClip);
SkASSERT(fViewMatrix); SkASSERT(fViewMatrix);
SkASSERT(fShape); SkASSERT(fShape);
@ -162,7 +162,7 @@ public:
canArgs.fAntiAlias = args.fAntiAlias; canArgs.fAntiAlias = args.fAntiAlias;
canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused(); canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused();
canArgs.fIsStencilBufferMSAA = args.fDrawContext->isStencilBufferMultisampled(); canArgs.fIsStencilBufferMSAA = args.fRenderTargetContext->isStencilBufferMultisampled();
SkASSERT(this->canDrawPath(canArgs)); SkASSERT(this->canDrawPath(canArgs));
if (!args.fUserStencilSettings->isUnused()) { if (!args.fUserStencilSettings->isUnused()) {
SkPath path; SkPath path;
@ -177,23 +177,23 @@ public:
/* Args to stencilPath(). /* Args to stencilPath().
* *
* fResourceProvider The resource provider for creating gpu resources to render the path * fResourceProvider The resource provider for creating gpu resources to render the path
* fDrawContext The target of the draws * fRenderTargetContext The target of the draws
* fViewMatrix Matrix applied to the path. * fViewMatrix Matrix applied to the path.
* fPath The path to draw. * fPath The path to draw.
* fIsAA Is the path to be drawn AA (only set when MSAA is available) * fIsAA Is the path to be drawn AA (only set when MSAA is available)
*/ */
struct StencilPathArgs { struct StencilPathArgs {
GrResourceProvider* fResourceProvider; GrResourceProvider* fResourceProvider;
GrDrawContext* fDrawContext; GrRenderTargetContext* fRenderTargetContext;
const GrClip* fClip; const GrClip* fClip;
const SkMatrix* fViewMatrix; const SkMatrix* fViewMatrix;
bool fIsAA; bool fIsAA;
const GrShape* fShape; const GrShape* fShape;
#ifdef SK_DEBUG #ifdef SK_DEBUG
void validate() const { void validate() const {
SkASSERT(fResourceProvider); SkASSERT(fResourceProvider);
SkASSERT(fDrawContext); SkASSERT(fRenderTargetContext);
SkASSERT(fViewMatrix); SkASSERT(fViewMatrix);
SkASSERT(fShape); SkASSERT(fShape);
SkASSERT(fShape->style().isSimpleFill()); SkASSERT(fShape->style().isSimpleFill());
@ -280,7 +280,7 @@ private:
drawArgs.fResourceProvider = args.fResourceProvider; drawArgs.fResourceProvider = args.fResourceProvider;
drawArgs.fPaint = &paint; drawArgs.fPaint = &paint;
drawArgs.fUserStencilSettings = &kIncrementStencil; drawArgs.fUserStencilSettings = &kIncrementStencil;
drawArgs.fDrawContext = args.fDrawContext; drawArgs.fRenderTargetContext = args.fRenderTargetContext;
drawArgs.fViewMatrix = args.fViewMatrix; drawArgs.fViewMatrix = args.fViewMatrix;
drawArgs.fShape = args.fShape; drawArgs.fShape = args.fShape;
drawArgs.fAntiAlias = false; // In this case the MSAA handles the AA so we want to draw BW drawArgs.fAntiAlias = false; // In this case the MSAA handles the AA so we want to draw BW

View File

@ -5,7 +5,7 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "GrPathRenderingDrawContext.h" #include "GrPathRenderingRenderTargetContext.h"
#include "GrDrawingManager.h" #include "GrDrawingManager.h"
@ -15,15 +15,15 @@
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
#define RETURN_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return; } #define RETURN_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return; }
void GrPathRenderingDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, void GrPathRenderingRenderTargetContext::drawText(const GrClip& clip, const GrPaint& grPaint,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const char text[], const SkMatrix& viewMatrix, const char text[],
size_t byteLength, SkScalar x, SkScalar y, size_t byteLength, SkScalar x, SkScalar y,
const SkIRect& clipBounds) { const SkIRect& clipBounds) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawText"); GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingRenderTargetContext::drawText");
if (!fStencilAndCoverTextContext) { if (!fStencilAndCoverTextContext) {
GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext(); GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();
@ -35,16 +35,17 @@ void GrPathRenderingDrawContext::drawText(const GrClip& clip, const GrPaint& gr
text, byteLength, x, y, clipBounds); text, byteLength, x, y, clipBounds);
} }
void GrPathRenderingDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint, void GrPathRenderingRenderTargetContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const char text[], const SkMatrix& viewMatrix, const char text[],
size_t byteLength, const SkScalar pos[], size_t byteLength, const SkScalar pos[],
int scalarsPerPosition, const SkPoint& offset, int scalarsPerPosition, const SkPoint& offset,
const SkIRect& clipBounds) { const SkIRect& clipBounds) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawPosText"); GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(),
"GrPathRenderingRenderTargetContext::drawPosText");
if (!fStencilAndCoverTextContext) { if (!fStencilAndCoverTextContext) {
GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext(); GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();
@ -57,14 +58,17 @@ void GrPathRenderingDrawContext::drawPosText(const GrClip& clip, const GrPaint&
clipBounds); clipBounds);
} }
void GrPathRenderingDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint, void GrPathRenderingRenderTargetContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkTextBlob* blob, const SkMatrix& viewMatrix,
SkScalar x, SkScalar y, const SkTextBlob* blob,
SkDrawFilter* filter, const SkIRect& clipBounds) { SkScalar x, SkScalar y,
SkDrawFilter* filter,
const SkIRect& clipBounds) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrPathRenderingDrawContext::drawTextBlob"); GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(),
"GrPathRenderingRenderTargetContext::drawTextBlob");
if (!fStencilAndCoverTextContext) { if (!fStencilAndCoverTextContext) {
GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext(); GrAtlasTextContext* fallbackContext = this->drawingManager()->getAtlasTextContext();

View File

@ -5,14 +5,14 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#ifndef GrPathRenderingDrawContext_DEFINED #ifndef GrPathRenderingRenderTargetContext_DEFINED
#define GrPathRenderingDrawContext_DEFINED #define GrPathRenderingRenderTargetContext_DEFINED
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
class GrStencilAndCoverTextContext; class GrStencilAndCoverTextContext;
class GrPathRenderingDrawContext : public GrDrawContext { class GrPathRenderingRenderTargetContext : public GrRenderTargetContext {
public: public:
void drawText(const GrClip&, const GrPaint&, const SkPaint&, void drawText(const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const char text[], size_t byteLength, const SkMatrix& viewMatrix, const char text[], size_t byteLength,
@ -26,9 +26,10 @@ public:
SkScalar x, SkScalar y, SkScalar x, SkScalar y,
SkDrawFilter*, const SkIRect& clipBounds) override; SkDrawFilter*, const SkIRect& clipBounds) override;
protected: protected:
GrPathRenderingDrawContext(GrContext* ctx, GrDrawingManager* mgr, sk_sp<GrRenderTarget> rt, GrPathRenderingRenderTargetContext(GrContext* ctx, GrDrawingManager* mgr,
sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps, sk_sp<GrRenderTarget> rt, sk_sp<SkColorSpace> colorSpace,
GrAuditTrail* at, GrSingleOwner* so) const SkSurfaceProps* surfaceProps, GrAuditTrail* at,
GrSingleOwner* so)
: INHERITED(ctx, mgr, std::move(rt), std::move(colorSpace), surfaceProps, at, so) {} : INHERITED(ctx, mgr, std::move(rt), std::move(colorSpace), surfaceProps, at, so) {}
private: private:
@ -36,7 +37,7 @@ private:
friend class GrDrawingManager; // for ctor friend class GrDrawingManager; // for ctor
typedef GrDrawContext INHERITED; typedef GrRenderTargetContext INHERITED;
}; };
#endif #endif

View File

@ -8,7 +8,7 @@
#include "GrPipeline.h" #include "GrPipeline.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrGpu.h" #include "GrGpu.h"
#include "GrPipelineBuilder.h" #include "GrPipelineBuilder.h"
#include "GrProcOptInfo.h" #include "GrProcOptInfo.h"
@ -23,7 +23,7 @@ GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args,
const GrPipelineBuilder& builder = *args.fPipelineBuilder; const GrPipelineBuilder& builder = *args.fPipelineBuilder;
GrPipeline* pipeline = new (memory) GrPipeline; GrPipeline* pipeline = new (memory) GrPipeline;
GrRenderTarget* rt = args.fDrawContext->accessRenderTarget(); GrRenderTarget* rt = args.fRenderTargetContext->accessRenderTarget();
pipeline->fRenderTarget.reset(rt); pipeline->fRenderTarget.reset(rt);
SkASSERT(pipeline->fRenderTarget); SkASSERT(pipeline->fRenderTarget);
pipeline->fScissorState = *args.fScissor; pipeline->fScissorState = *args.fScissor;
@ -57,7 +57,7 @@ GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args,
} }
// Create XferProcessor from DS's XPFactory // Create XferProcessor from DS's XPFactory
bool hasMixedSamples = args.fDrawContext->hasMixedSamples() && bool hasMixedSamples = args.fRenderTargetContext->hasMixedSamples() &&
(builder.isHWAntialias() || !pipeline->fStencilSettings.isDisabled()); (builder.isHWAntialias() || !pipeline->fStencilSettings.isDisabled());
const GrXPFactory* xpFactory = builder.getXPFactory(); const GrXPFactory* xpFactory = builder.getXPFactory();
SkAutoTUnref<GrXferProcessor> xferProcessor; SkAutoTUnref<GrXferProcessor> xferProcessor;

View File

@ -27,7 +27,7 @@
#include "effects/GrSimpleTextureEffect.h" #include "effects/GrSimpleTextureEffect.h"
class GrBatch; class GrBatch;
class GrDrawContext; class GrRenderTargetContext;
class GrDeviceCoordTexture; class GrDeviceCoordTexture;
class GrPipelineBuilder; class GrPipelineBuilder;
@ -55,7 +55,7 @@ public:
struct CreateArgs { struct CreateArgs {
const GrPipelineBuilder* fPipelineBuilder; const GrPipelineBuilder* fPipelineBuilder;
GrDrawContext* fDrawContext; GrRenderTargetContext* fRenderTargetContext;
const GrCaps* fCaps; const GrCaps* fCaps;
GrPipelineOptimizations fOpts; GrPipelineOptimizations fOpts;
const GrScissorState* fScissor; const GrScissorState* fScissor;

View File

@ -11,8 +11,8 @@
#include "GrClip.h" #include "GrClip.h"
#include "GrColor.h" #include "GrColor.h"
#include "GrContextPriv.h" #include "GrContextPriv.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrDrawingManager.h" #include "GrDrawingManager.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "GrPathRenderer.h" #include "GrPathRenderer.h"
@ -523,7 +523,7 @@ inline bool GrReducedClip::intersectIBounds(const SkIRect& irect) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Create a 8-bit clip mask in alpha // Create a 8-bit clip mask in alpha
static bool stencil_element(GrDrawContext* dc, static bool stencil_element(GrRenderTargetContext* rtc,
const GrFixedClip& clip, const GrFixedClip& clip,
const GrUserStencilSettings* ss, const GrUserStencilSettings* ss,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -535,11 +535,12 @@ static bool stencil_element(GrDrawContext* dc,
SkDEBUGFAIL("Should never get here with an empty element."); SkDEBUGFAIL("Should never get here with an empty element.");
break; break;
case Element::kRect_Type: case Element::kRect_Type:
return dc->drawContextPriv().drawAndStencilRect(clip, ss, return rtc->renderTargetContextPriv().drawAndStencilRect(clip, ss,
(SkRegion::Op)element->getOp(), (SkRegion::Op)element->getOp(),
element->isInverseFilled(), element->isInverseFilled(),
element->isAA(), element->isAA(),
viewMatrix, element->getRect()); viewMatrix,
element->getRect());
break; break;
default: { default: {
SkPath path; SkPath path;
@ -548,10 +549,11 @@ static bool stencil_element(GrDrawContext* dc,
path.toggleInverseFillType(); path.toggleInverseFillType();
} }
return dc->drawContextPriv().drawAndStencilPath(clip, ss, return rtc->renderTargetContextPriv().drawAndStencilPath(clip, ss,
(SkRegion::Op)element->getOp(), (SkRegion::Op)element->getOp(),
element->isInverseFilled(), element->isInverseFilled(),
element->isAA(), viewMatrix, path); element->isAA(), viewMatrix,
path);
break; break;
} }
} }
@ -559,7 +561,7 @@ static bool stencil_element(GrDrawContext* dc,
return false; return false;
} }
static void draw_element(GrDrawContext* dc, static void draw_element(GrRenderTargetContext* rtc,
const GrClip& clip, // TODO: can this just always be WideOpen? const GrClip& clip, // TODO: can this just always be WideOpen?
const GrPaint &paint, const GrPaint &paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -571,7 +573,7 @@ static void draw_element(GrDrawContext* dc,
SkDEBUGFAIL("Should never get here with an empty element."); SkDEBUGFAIL("Should never get here with an empty element.");
break; break;
case Element::kRect_Type: case Element::kRect_Type:
dc->drawRect(clip, paint, viewMatrix, element->getRect()); rtc->drawRect(clip, paint, viewMatrix, element->getRect());
break; break;
default: { default: {
SkPath path; SkPath path;
@ -580,13 +582,13 @@ static void draw_element(GrDrawContext* dc,
path.toggleInverseFillType(); path.toggleInverseFillType();
} }
dc->drawPath(clip, paint, viewMatrix, path, GrStyle::SimpleFill()); rtc->drawPath(clip, paint, viewMatrix, path, GrStyle::SimpleFill());
break; break;
} }
} }
} }
bool GrReducedClip::drawAlphaClipMask(GrDrawContext* dc) const { bool GrReducedClip::drawAlphaClipMask(GrRenderTargetContext* rtc) const {
// The texture may be larger than necessary, this rect represents the part of the texture // The texture may be larger than necessary, this rect represents the part of the texture
// we populate with a rasterization of the clip. // we populate with a rasterization of the clip.
GrFixedClip clip(SkIRect::MakeWH(fIBounds.width(), fIBounds.height())); GrFixedClip clip(SkIRect::MakeWH(fIBounds.width(), fIBounds.height()));
@ -599,7 +601,7 @@ bool GrReducedClip::drawAlphaClipMask(GrDrawContext* dc) const {
// The scratch texture that we are drawing into can be substantially larger than the mask. Only // The scratch texture that we are drawing into can be substantially larger than the mask. Only
// clear the part that we care about. // clear the part that we care about.
GrColor initialCoverage = InitialState::kAllIn == this->initialState() ? -1 : 0; GrColor initialCoverage = InitialState::kAllIn == this->initialState() ? -1 : 0;
dc->drawContextPriv().clear(clip, initialCoverage, true); rtc->renderTargetContextPriv().clear(clip, initialCoverage, true);
// Set the matrix so that rendered clip elements are transformed to mask space from clip space. // Set the matrix so that rendered clip elements are transformed to mask space from clip space.
SkMatrix translate; SkMatrix translate;
@ -622,7 +624,7 @@ bool GrReducedClip::drawAlphaClipMask(GrDrawContext* dc) const {
GrUserStencilOp::kReplace, GrUserStencilOp::kReplace,
0xffff>() 0xffff>()
); );
if (!stencil_element(dc, clip, &kStencilInElement, translate, element)) { if (!stencil_element(rtc, clip, &kStencilInElement, translate, element)) {
return false; return false;
} }
@ -636,10 +638,10 @@ bool GrReducedClip::drawAlphaClipMask(GrDrawContext* dc) const {
GrUserStencilOp::kZero, GrUserStencilOp::kZero,
0xffff>() 0xffff>()
); );
if (!dc->drawContextPriv().drawAndStencilRect(clip, &kDrawOutsideElement, if (!rtc->renderTargetContextPriv().drawAndStencilRect(clip, &kDrawOutsideElement,
op, !invert, false, op, !invert, false,
translate, translate,
SkRect::Make(fIBounds))) { SkRect::Make(fIBounds))) {
return false; return false;
} }
} else { } else {
@ -648,7 +650,7 @@ bool GrReducedClip::drawAlphaClipMask(GrDrawContext* dc) const {
paint.setAntiAlias(element->isAA()); paint.setAntiAlias(element->isAA());
paint.setCoverageSetOpXPFactory(op, false); paint.setCoverageSetOpXPFactory(op, false);
draw_element(dc, clip, paint, translate, element); draw_element(rtc, clip, paint, translate, element);
} }
} }
@ -678,9 +680,9 @@ private:
bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override { bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override {
return false; return false;
} }
bool apply(GrContext* context, GrDrawContext* drawContext, bool useHWAA, bool apply(GrContext* context, GrRenderTargetContext* renderTargetContext, bool useHWAA,
bool hasUserStencilSettings, GrAppliedClip* out) const override { bool hasUserStencilSettings, GrAppliedClip* out) const override {
if (!fFixedClip.apply(context, drawContext, useHWAA, hasUserStencilSettings, out)) { if (!fFixedClip.apply(context, renderTargetContext, useHWAA, hasUserStencilSettings, out)) {
return false; return false;
} }
out->addStencilClip(); out->addStencilClip();
@ -693,7 +695,7 @@ private:
}; };
bool GrReducedClip::drawStencilClipMask(GrContext* context, bool GrReducedClip::drawStencilClipMask(GrContext* context,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
const SkIPoint& clipOrigin) const { const SkIPoint& clipOrigin) const {
// We set the current clip to the bounds so that our recursive draws are scissored to them. // We set the current clip to the bounds so that our recursive draws are scissored to them.
StencilClip stencilClip(fIBounds.makeOffset(-clipOrigin.x(), -clipOrigin.y())); StencilClip stencilClip(fIBounds.makeOffset(-clipOrigin.x(), -clipOrigin.y()));
@ -704,7 +706,8 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
} }
bool initialState = InitialState::kAllIn == this->initialState(); bool initialState = InitialState::kAllIn == this->initialState();
drawContext->drawContextPriv().clearStencilClip(stencilClip.fixedClip(), initialState); renderTargetContext->renderTargetContextPriv().clearStencilClip(stencilClip.fixedClip(),
initialState);
// Set the matrix so that rendered clip elements are transformed from clip to stencil space. // Set the matrix so that rendered clip elements are transformed from clip to stencil space.
SkMatrix viewMatrix; SkMatrix viewMatrix;
@ -714,7 +717,7 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
// with the existing clip. // with the existing clip.
for (ElementList::Iter iter(fElements); iter.get(); iter.next()) { for (ElementList::Iter iter(fElements); iter.get(); iter.next()) {
const Element* element = iter.get(); const Element* element = iter.get();
bool useHWAA = element->isAA() && drawContext->isStencilBufferMultisampled(); bool useHWAA = element->isAA() && renderTargetContext->isStencilBufferMultisampled();
bool fillInverted = false; bool fillInverted = false;
@ -743,7 +746,7 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
canDrawArgs.fShape = &shape; canDrawArgs.fShape = &shape;
canDrawArgs.fAntiAlias = false; canDrawArgs.fAntiAlias = false;
canDrawArgs.fHasUserStencilSettings = false; canDrawArgs.fHasUserStencilSettings = false;
canDrawArgs.fIsStencilBufferMSAA = drawContext->isStencilBufferMultisampled(); canDrawArgs.fIsStencilBufferMSAA = renderTargetContext->isStencilBufferMultisampled();
GrDrawingManager* dm = context->contextPriv().drawingManager(); GrDrawingManager* dm = context->contextPriv().drawingManager();
pr = dm->getPathRenderer(canDrawArgs, false, pr = dm->getPathRenderer(canDrawArgs, false,
@ -776,9 +779,10 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
0xffff>() 0xffff>()
); );
if (Element::kRect_Type == element->getType()) { if (Element::kRect_Type == element->getType()) {
drawContext->drawContextPriv().stencilRect(stencilClip.fixedClip(), renderTargetContext->renderTargetContextPriv().stencilRect(stencilClip.fixedClip(),
&kDrawToStencil, useHWAA, &kDrawToStencil, useHWAA,
viewMatrix, element->getRect()); viewMatrix,
element->getRect());
} else { } else {
if (!clipPath.isEmpty()) { if (!clipPath.isEmpty()) {
GrShape shape(clipPath, GrStyle::SimpleFill()); GrShape shape(clipPath, GrStyle::SimpleFill());
@ -791,7 +795,7 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
args.fResourceProvider = context->resourceProvider(); args.fResourceProvider = context->resourceProvider();
args.fPaint = &paint; args.fPaint = &paint;
args.fUserStencilSettings = &kDrawToStencil; args.fUserStencilSettings = &kDrawToStencil;
args.fDrawContext = drawContext; args.fRenderTargetContext = renderTargetContext;
args.fClip = &stencilClip.fixedClip(); args.fClip = &stencilClip.fixedClip();
args.fViewMatrix = &viewMatrix; args.fViewMatrix = &viewMatrix;
args.fShape = &shape; args.fShape = &shape;
@ -801,7 +805,7 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
} else { } else {
GrPathRenderer::StencilPathArgs args; GrPathRenderer::StencilPathArgs args;
args.fResourceProvider = context->resourceProvider(); args.fResourceProvider = context->resourceProvider();
args.fDrawContext = drawContext; args.fRenderTargetContext = renderTargetContext;
args.fClip = &stencilClip.fixedClip(); args.fClip = &stencilClip.fixedClip();
args.fViewMatrix = &viewMatrix; args.fViewMatrix = &viewMatrix;
args.fIsAA = element->isAA(); args.fIsAA = element->isAA();
@ -817,8 +821,9 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
for (GrUserStencilSettings const* const* pass = stencilPasses; *pass; ++pass) { for (GrUserStencilSettings const* const* pass = stencilPasses; *pass; ++pass) {
if (drawDirectToClip) { if (drawDirectToClip) {
if (Element::kRect_Type == element->getType()) { if (Element::kRect_Type == element->getType()) {
drawContext->drawContextPriv().stencilRect(stencilClip, *pass, useHWAA, renderTargetContext->renderTargetContextPriv().stencilRect(stencilClip, *pass,
viewMatrix, element->getRect()); useHWAA, viewMatrix,
element->getRect());
} else { } else {
GrShape shape(clipPath, GrStyle::SimpleFill()); GrShape shape(clipPath, GrStyle::SimpleFill());
GrPaint paint; GrPaint paint;
@ -828,7 +833,7 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
args.fResourceProvider = context->resourceProvider(); args.fResourceProvider = context->resourceProvider();
args.fPaint = &paint; args.fPaint = &paint;
args.fUserStencilSettings = *pass; args.fUserStencilSettings = *pass;
args.fDrawContext = drawContext; args.fRenderTargetContext = renderTargetContext;
args.fClip = &stencilClip; args.fClip = &stencilClip;
args.fViewMatrix = &viewMatrix; args.fViewMatrix = &viewMatrix;
args.fShape = &shape; args.fShape = &shape;
@ -839,9 +844,9 @@ bool GrReducedClip::drawStencilClipMask(GrContext* context,
} else { } else {
// The view matrix is setup to do clip space -> stencil space translation, so // The view matrix is setup to do clip space -> stencil space translation, so
// draw rect in clip space. // draw rect in clip space.
drawContext->drawContextPriv().stencilRect(stencilClip, *pass, renderTargetContext->renderTargetContextPriv().stencilRect(stencilClip, *pass,
false, viewMatrix, false, viewMatrix,
SkRect::Make(fIBounds)); SkRect::Make(fIBounds));
} }
} }
} }

View File

@ -13,7 +13,7 @@
#include "SkTLList.h" #include "SkTLList.h"
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
/** /**
* This class takes a clip stack and produces a reduced set of elements that are equivalent to * This class takes a clip stack and produces a reduced set of elements that are equivalent to
@ -70,8 +70,8 @@ public:
InitialState initialState() const { return fInitialState; } InitialState initialState() const { return fInitialState; }
bool drawAlphaClipMask(GrDrawContext*) const; bool drawAlphaClipMask(GrRenderTargetContext*) const;
bool drawStencilClipMask(GrContext*, GrDrawContext*, const SkIPoint& clipOrigin) const; bool drawStencilClipMask(GrContext*, GrRenderTargetContext*, const SkIPoint& clipOrigin) const;
private: private:
void walkStack(const SkClipStack&, const SkRect& queryBounds, int maxWindowRectangles); void walkStack(const SkClipStack&, const SkRect& queryBounds, int maxWindowRectangles);

View File

@ -10,7 +10,7 @@
#include "GrContext.h" #include "GrContext.h"
#include "GrContextPriv.h" #include "GrContextPriv.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrGpu.h" #include "GrGpu.h"
#include "GrRenderTargetOpList.h" #include "GrRenderTargetOpList.h"
#include "GrRenderTargetPriv.h" #include "GrRenderTargetPriv.h"
@ -34,13 +34,13 @@ void GrRenderTarget::discard() {
return; return;
} }
sk_sp<GrDrawContext> drawContext(context->contextPriv().makeWrappedDrawContext(sk_ref_sp(this), sk_sp<GrRenderTargetContext> renderTargetContext(
nullptr)); context->contextPriv().makeWrappedRenderTargetContext(sk_ref_sp(this), nullptr));
if (!drawContext) { if (!renderTargetContext) {
return; return;
} }
drawContext->discard(); renderTargetContext->discard();
} }
void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {

View File

@ -7,8 +7,8 @@
#include "GrBatchTest.h" #include "GrBatchTest.h"
#include "GrColor.h" #include "GrColor.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrDrawingManager.h" #include "GrDrawingManager.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "GrGpuResourcePriv.h" #include "GrGpuResourcePriv.h"
@ -45,11 +45,11 @@
#define ASSERT_SINGLE_OWNER \ #define ASSERT_SINGLE_OWNER \
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
#define ASSERT_SINGLE_OWNER_PRIV \ #define ASSERT_SINGLE_OWNER_PRIV \
SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fDrawContext->fSingleOwner);) SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);)
#define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; } #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; }
#define RETURN_IF_ABANDONED_PRIV if (fDrawContext->fDrawingManager->wasAbandoned()) { return; } #define RETURN_IF_ABANDONED_PRIV if (fRenderTargetContext->fDrawingManager->wasAbandoned()) { return; }
#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; } #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; }
#define RETURN_FALSE_IF_ABANDONED_PRIV if (fDrawContext->fDrawingManager->wasAbandoned()) { return false; } #define RETURN_FALSE_IF_ABANDONED_PRIV if (fRenderTargetContext->fDrawingManager->wasAbandoned()) { return false; }
#define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; } #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; }
using gr_instanced::InstancedRendering; using gr_instanced::InstancedRendering;
@ -65,21 +65,21 @@ private:
GrDrawingManager* fDrawingManager; GrDrawingManager* fDrawingManager;
}; };
bool GrDrawContext::wasAbandoned() const { bool GrRenderTargetContext::wasAbandoned() const {
return fDrawingManager->wasAbandoned(); return fDrawingManager->wasAbandoned();
} }
// In MDB mode the reffing of the 'getLastOpList' call's result allows in-progress // In MDB mode the reffing of the 'getLastOpList' call's result allows in-progress
// GrOpLists to be picked up and added to by drawContexts lower in the call // GrOpLists to be picked up and added to by renderTargetContexts lower in the call
// stack. When this occurs with a closed GrOpList, a new one will be allocated // stack. When this occurs with a closed GrOpList, a new one will be allocated
// when the drawContext attempts to use it (via getOpList). // when the renderTargetContext attempts to use it (via getOpList).
GrDrawContext::GrDrawContext(GrContext* context, GrRenderTargetContext::GrRenderTargetContext(GrContext* context,
GrDrawingManager* drawingMgr, GrDrawingManager* drawingMgr,
sk_sp<GrRenderTarget> rt, sk_sp<GrRenderTarget> rt,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps, const SkSurfaceProps* surfaceProps,
GrAuditTrail* auditTrail, GrAuditTrail* auditTrail,
GrSingleOwner* singleOwner) GrSingleOwner* singleOwner)
: fDrawingManager(drawingMgr) : fDrawingManager(drawingMgr)
, fRenderTarget(std::move(rt)) , fRenderTarget(std::move(rt))
, fOpList(SkSafeRef(fRenderTarget->getLastRenderTargetOpList())) , fOpList(SkSafeRef(fRenderTarget->getLastRenderTargetOpList()))
@ -102,7 +102,7 @@ GrDrawContext::GrDrawContext(GrContext* context,
} }
#ifdef SK_DEBUG #ifdef SK_DEBUG
void GrDrawContext::validate() const { void GrRenderTargetContext::validate() const {
SkASSERT(fRenderTarget); SkASSERT(fRenderTarget);
ASSERT_OWNED_RESOURCE(fRenderTarget); ASSERT_OWNED_RESOURCE(fRenderTarget);
@ -112,12 +112,12 @@ void GrDrawContext::validate() const {
} }
#endif #endif
GrDrawContext::~GrDrawContext() { GrRenderTargetContext::~GrRenderTargetContext() {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
SkSafeUnref(fOpList); SkSafeUnref(fOpList);
} }
GrRenderTargetOpList* GrDrawContext::getOpList() { GrRenderTargetOpList* GrRenderTargetContext::getOpList() {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
@ -128,40 +128,41 @@ GrRenderTargetOpList* GrDrawContext::getOpList() {
return fOpList; return fOpList;
} }
bool GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { bool GrRenderTargetContext::copySurface(GrSurface* src, const SkIRect& srcRect,
const SkIPoint& dstPoint) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::copySurface"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::copySurface");
return this->getOpList()->copySurface(fRenderTarget.get(), src, srcRect, dstPoint); return this->getOpList()->copySurface(fRenderTarget.get(), src, srcRect, dstPoint);
} }
void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, void GrRenderTargetContext::drawText(const GrClip& clip, const GrPaint& grPaint,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& clipBounds) { SkScalar x, SkScalar y, const SkIRect& clipBounds) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawText"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawText");
GrAtlasTextContext* atlasTextContext = fDrawingManager->getAtlasTextContext(); GrAtlasTextContext* atlasTextContext = fDrawingManager->getAtlasTextContext();
atlasTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps, atlasTextContext->drawText(fContext, this, clip, grPaint, skPaint, viewMatrix, fSurfaceProps,
text, byteLength, x, y, clipBounds); text, byteLength, x, y, clipBounds);
} }
void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint, void GrRenderTargetContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& clipBounds) { const SkPoint& offset, const SkIRect& clipBounds) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPosText"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawPosText");
GrAtlasTextContext* atlasTextContext = fDrawingManager->getAtlasTextContext(); GrAtlasTextContext* atlasTextContext = fDrawingManager->getAtlasTextContext();
atlasTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix, atlasTextContext->drawPosText(fContext, this, clip, grPaint, skPaint, viewMatrix,
@ -170,57 +171,58 @@ void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
} }
void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint, void GrRenderTargetContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkTextBlob* blob, const SkMatrix& viewMatrix, const SkTextBlob* blob,
SkScalar x, SkScalar y, SkScalar x, SkScalar y,
SkDrawFilter* filter, const SkIRect& clipBounds) { SkDrawFilter* filter, const SkIRect& clipBounds) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawTextBlob"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawTextBlob");
GrAtlasTextContext* atlasTextContext = fDrawingManager->getAtlasTextContext(); GrAtlasTextContext* atlasTextContext = fDrawingManager->getAtlasTextContext();
atlasTextContext->drawTextBlob(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, blob, atlasTextContext->drawTextBlob(fContext, this, clip, skPaint, viewMatrix, fSurfaceProps, blob,
x, y, filter, clipBounds); x, y, filter, clipBounds);
} }
void GrDrawContext::discard() { void GrRenderTargetContext::discard() {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::discard"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::discard");
AutoCheckFlush acf(fDrawingManager); AutoCheckFlush acf(fDrawingManager);
this->getOpList()->discard(fRenderTarget.get()); this->getOpList()->discard(fRenderTarget.get());
} }
void GrDrawContext::clear(const SkIRect* rect, void GrRenderTargetContext::clear(const SkIRect* rect,
const GrColor color, const GrColor color,
bool canIgnoreRect) { bool canIgnoreRect) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::clear");
AutoCheckFlush acf(fDrawingManager); AutoCheckFlush acf(fDrawingManager);
this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), color, canIgnoreRect); this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), color, canIgnoreRect);
} }
void GrDrawContextPriv::clear(const GrFixedClip& clip, void GrRenderTargetContextPriv::clear(const GrFixedClip& clip,
const GrColor color, const GrColor color,
bool canIgnoreClip) { bool canIgnoreClip) {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
RETURN_IF_ABANDONED_PRIV RETURN_IF_ABANDONED_PRIV
SkDEBUGCODE(fDrawContext->validate();) SkDEBUGCODE(fRenderTargetContext->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContextPriv::clear"); GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
"GrRenderTargetContextPriv::clear");
AutoCheckFlush acf(fDrawContext->fDrawingManager); AutoCheckFlush acf(fRenderTargetContext->fDrawingManager);
fDrawContext->internalClear(clip, color, canIgnoreClip); fRenderTargetContext->internalClear(clip, color, canIgnoreClip);
} }
void GrDrawContext::internalClear(const GrFixedClip& clip, void GrRenderTargetContext::internalClear(const GrFixedClip& clip,
const GrColor color, const GrColor color,
bool canIgnoreClip) { bool canIgnoreClip) {
bool isFull = false; bool isFull = false;
if (!clip.hasWindowRectangles()) { if (!clip.hasWindowRectangles()) {
isFull = !clip.scissorEnabled() || isFull = !clip.scissorEnabled() ||
@ -255,13 +257,13 @@ void GrDrawContext::internalClear(const GrFixedClip& clip,
} }
} }
void GrDrawContext::drawPaint(const GrClip& clip, void GrRenderTargetContext::drawPaint(const GrClip& clip,
const GrPaint& origPaint, const GrPaint& origPaint,
const SkMatrix& viewMatrix) { const SkMatrix& viewMatrix) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawPaint");
// set rect to be big enough to fill the space, but not super-huge, so we // set rect to be big enough to fill the space, but not super-huge, so we
// don't overflow fixed-point implementations // don't overflow fixed-point implementations
@ -382,11 +384,11 @@ static bool crop_filled_rect(int width, int height, const GrClip& clip,
return rect->intersect(clipBounds); return rect->intersect(clipBounds);
} }
bool GrDrawContext::drawFilledRect(const GrClip& clip, bool GrRenderTargetContext::drawFilledRect(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& rect, const SkRect& rect,
const GrUserStencilSettings* ss) { const GrUserStencilSettings* ss) {
SkRect croppedRect = rect; SkRect croppedRect = rect;
if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) {
return true; return true;
@ -436,18 +438,18 @@ bool GrDrawContext::drawFilledRect(const GrClip& clip,
return false; return false;
} }
void GrDrawContext::drawRect(const GrClip& clip, void GrRenderTargetContext::drawRect(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& rect, const SkRect& rect,
const GrStyle* style) { const GrStyle* style) {
if (!style) { if (!style) {
style = &GrStyle::SimpleFill(); style = &GrStyle::SimpleFill();
} }
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRect");
// Path effects should've been devolved to a path in SkGpuDevice // Path effects should've been devolved to a path in SkGpuDevice
SkASSERT(!style->pathEffect()); SkASSERT(!style->pathEffect());
@ -560,62 +562,67 @@ void GrDrawContext::drawRect(const GrClip& clip,
this->internalDrawPath(clip, paint, viewMatrix, path, *style); this->internalDrawPath(clip, paint, viewMatrix, path, *style);
} }
void GrDrawContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
RETURN_IF_ABANDONED_PRIV RETURN_IF_ABANDONED_PRIV
SkDEBUGCODE(fDrawContext->validate();) SkDEBUGCODE(fRenderTargetContext->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContextPriv::clearStencilClip"); GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
"GrRenderTargetContextPriv::clearStencilClip");
AutoCheckFlush acf(fDrawContext->fDrawingManager); AutoCheckFlush acf(fRenderTargetContext->fDrawingManager);
fDrawContext->getOpList()->clearStencilClip(clip, insideStencilMask, fRenderTargetContext->getOpList()->clearStencilClip(clip, insideStencilMask,
fDrawContext->accessRenderTarget()); fRenderTargetContext->accessRenderTarget());
} }
void GrDrawContextPriv::stencilPath(const GrClip& clip, void GrRenderTargetContextPriv::stencilPath(const GrClip& clip,
bool useHWAA, bool useHWAA,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const GrPath* path) { const GrPath* path) {
fDrawContext->getOpList()->stencilPath(fDrawContext, clip, useHWAA, viewMatrix, path); fRenderTargetContext->getOpList()->stencilPath(fRenderTargetContext, clip, useHWAA, viewMatrix,
path);
} }
void GrDrawContextPriv::stencilRect(const GrClip& clip, void GrRenderTargetContextPriv::stencilRect(const GrClip& clip,
const GrUserStencilSettings* ss, const GrUserStencilSettings* ss,
bool useHWAA, bool useHWAA,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& rect) { const SkRect& rect) {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
RETURN_IF_ABANDONED_PRIV RETURN_IF_ABANDONED_PRIV
SkDEBUGCODE(fDrawContext->validate();) SkDEBUGCODE(fRenderTargetContext->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencilRect"); GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
"GrRenderTargetContext::stencilRect");
AutoCheckFlush acf(fDrawContext->fDrawingManager); AutoCheckFlush acf(fRenderTargetContext->fDrawingManager);
GrPaint paint; GrPaint paint;
paint.setAntiAlias(useHWAA); paint.setAntiAlias(useHWAA);
paint.setXPFactory(GrDisableColorXPFactory::Make()); paint.setXPFactory(GrDisableColorXPFactory::Make());
fDrawContext->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nullptr, ss, useHWAA); fRenderTargetContext->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nullptr, ss,
useHWAA);
} }
bool GrDrawContextPriv::drawAndStencilRect(const GrClip& clip, bool GrRenderTargetContextPriv::drawAndStencilRect(const GrClip& clip,
const GrUserStencilSettings* ss, const GrUserStencilSettings* ss,
SkRegion::Op op, SkRegion::Op op,
bool invert, bool invert,
bool doAA, bool doAA,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& rect) { const SkRect& rect) {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
RETURN_FALSE_IF_ABANDONED_PRIV RETURN_FALSE_IF_ABANDONED_PRIV
SkDEBUGCODE(fDrawContext->validate();) SkDEBUGCODE(fRenderTargetContext->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawAndStencilRect"); GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail,
"GrRenderTargetContext::drawAndStencilRect");
AutoCheckFlush acf(fDrawContext->fDrawingManager); AutoCheckFlush acf(fRenderTargetContext->fDrawingManager);
GrPaint paint; GrPaint paint;
paint.setAntiAlias(doAA); paint.setAntiAlias(doAA);
paint.setCoverageSetOpXPFactory(op, invert); paint.setCoverageSetOpXPFactory(op, invert);
if (fDrawContext->drawFilledRect(clip, paint, viewMatrix, rect, ss)) { if (fRenderTargetContext->drawFilledRect(clip, paint, viewMatrix, rect, ss)) {
return true; return true;
} }
@ -625,15 +632,15 @@ bool GrDrawContextPriv::drawAndStencilRect(const GrClip& clip,
return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path); return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path);
} }
void GrDrawContext::fillRectToRect(const GrClip& clip, void GrRenderTargetContext::fillRectToRect(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& rectToDraw, const SkRect& rectToDraw,
const SkRect& localRect) { const SkRect& localRect) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::fillRectToRect");
SkRect croppedRect = rectToDraw; SkRect croppedRect = rectToDraw;
SkRect croppedLocalRect = localRect; SkRect croppedLocalRect = localRect;
@ -686,15 +693,15 @@ void GrDrawContext::fillRectToRect(const GrClip& clip,
this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle()); this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle());
} }
void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, void GrRenderTargetContext::fillRectWithLocalMatrix(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& rectToDraw, const SkRect& rectToDraw,
const SkMatrix& localMatrix) { const SkMatrix& localMatrix) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatrix"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::fillRectWithLocalMatrix");
SkRect croppedRect = rectToDraw; SkRect croppedRect = rectToDraw;
if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) { if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &croppedRect)) {
@ -744,20 +751,20 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip,
this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle()); this->internalDrawPath(clip, paint, viewAndUnLocalMatrix, path, GrStyle());
} }
void GrDrawContext::drawVertices(const GrClip& clip, void GrRenderTargetContext::drawVertices(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
GrPrimitiveType primitiveType, GrPrimitiveType primitiveType,
int vertexCount, int vertexCount,
const SkPoint positions[], const SkPoint positions[],
const SkPoint texCoords[], const SkPoint texCoords[],
const GrColor colors[], const GrColor colors[],
const uint16_t indices[], const uint16_t indices[],
int indexCount) { int indexCount) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawVertices"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawVertices");
AutoCheckFlush acf(fDrawingManager); AutoCheckFlush acf(fDrawingManager);
@ -781,17 +788,17 @@ void GrDrawContext::drawVertices(const GrClip& clip,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void GrDrawContext::drawAtlas(const GrClip& clip, void GrRenderTargetContext::drawAtlas(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
int spriteCount, int spriteCount,
const SkRSXform xform[], const SkRSXform xform[],
const SkRect texRect[], const SkRect texRect[],
const SkColor colors[]) { const SkColor colors[]) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawAtlas"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawAtlas");
AutoCheckFlush acf(fDrawingManager); AutoCheckFlush acf(fDrawingManager);
@ -804,15 +811,15 @@ void GrDrawContext::drawAtlas(const GrClip& clip,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void GrDrawContext::drawRRect(const GrClip& origClip, void GrRenderTargetContext::drawRRect(const GrClip& origClip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRRect& rrect, const SkRRect& rrect,
const GrStyle& style) { const GrStyle& style) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRRect");
if (rrect.isEmpty()) { if (rrect.isEmpty()) {
return; return;
} }
@ -871,11 +878,11 @@ void GrDrawContext::drawRRect(const GrClip& origClip,
this->internalDrawPath(*clip, paint, viewMatrix, path, style); this->internalDrawPath(*clip, paint, viewMatrix, path, style);
} }
bool GrDrawContext::drawFilledDRRect(const GrClip& clip, bool GrRenderTargetContext::drawFilledDRRect(const GrClip& clip,
const GrPaint& paintIn, const GrPaint& paintIn,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRRect& origOuter, const SkRRect& origOuter,
const SkRRect& origInner) { const SkRRect& origInner) {
SkASSERT(!origInner.isEmpty()); SkASSERT(!origInner.isEmpty());
SkASSERT(!origOuter.isEmpty()); SkASSERT(!origOuter.isEmpty());
@ -941,15 +948,15 @@ bool GrDrawContext::drawFilledDRRect(const GrClip& clip,
return true; return true;
} }
void GrDrawContext::drawDRRect(const GrClip& clip, void GrRenderTargetContext::drawDRRect(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRRect& outer, const SkRRect& outer,
const SkRRect& inner) { const SkRRect& inner) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawDRRect"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawDRRect");
SkASSERT(!outer.isEmpty()); SkASSERT(!outer.isEmpty());
SkASSERT(!inner.isEmpty()); SkASSERT(!inner.isEmpty());
@ -975,15 +982,15 @@ static inline bool is_int(float x) {
return x == (float) sk_float_round2int(x); return x == (float) sk_float_round2int(x);
} }
void GrDrawContext::drawRegion(const GrClip& clip, void GrRenderTargetContext::drawRegion(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRegion& region, const SkRegion& region,
const GrStyle& style) { const GrStyle& style) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRegion"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawRegion");
bool isNonTranslate = SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask)); bool isNonTranslate = SkToBool(viewMatrix.getType() & ~(SkMatrix::kTranslate_Mask));
bool complexStyle = !style.isSimpleFill(); bool complexStyle = !style.isSimpleFill();
@ -1000,15 +1007,15 @@ void GrDrawContext::drawRegion(const GrClip& clip,
this->getOpList()->drawBatch(pipelineBuilder, this, clip, batch); this->getOpList()->drawBatch(pipelineBuilder, this, clip, batch);
} }
void GrDrawContext::drawOval(const GrClip& clip, void GrRenderTargetContext::drawOval(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& oval, const SkRect& oval,
const GrStyle& style) { const GrStyle& style) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawOval");
if (oval.isEmpty()) { if (oval.isEmpty()) {
return; return;
@ -1053,14 +1060,14 @@ void GrDrawContext::drawOval(const GrClip& clip,
this->internalDrawPath(clip, paint, viewMatrix, path, style); this->internalDrawPath(clip, paint, viewMatrix, path, style);
} }
void GrDrawContext::drawArc(const GrClip& clip, void GrRenderTargetContext::drawArc(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& oval, const SkRect& oval,
SkScalar startAngle, SkScalar startAngle,
SkScalar sweepAngle, SkScalar sweepAngle,
bool useCenter, bool useCenter,
const GrStyle& style) { const GrStyle& style) {
bool useHWAA; bool useHWAA;
if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) {
GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
@ -1085,17 +1092,17 @@ void GrDrawContext::drawArc(const GrClip& clip,
return; return;
} }
void GrDrawContext::drawImageLattice(const GrClip& clip, void GrRenderTargetContext::drawImageLattice(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
int imageWidth, int imageWidth,
int imageHeight, int imageHeight,
std::unique_ptr<SkLatticeIter> iter, std::unique_ptr<SkLatticeIter> iter,
const SkRect& dst) { const SkRect& dst) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageLattice"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawImageLattice");
AutoCheckFlush acf(fDrawingManager); AutoCheckFlush acf(fDrawingManager);
@ -1107,25 +1114,25 @@ void GrDrawContext::drawImageLattice(const GrClip& clip,
this->getOpList()->drawBatch(pipelineBuilder, this, clip, batch); this->getOpList()->drawBatch(pipelineBuilder, this, clip, batch);
} }
void GrDrawContext::prepareForExternalIO() { void GrRenderTargetContext::prepareForExternalIO() {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::prepareForExternalIO"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::prepareForExternalIO");
ASSERT_OWNED_RESOURCE(fRenderTarget); ASSERT_OWNED_RESOURCE(fRenderTarget);
fDrawingManager->prepareSurfaceForExternalIO(fRenderTarget.get()); fDrawingManager->prepareSurfaceForExternalIO(fRenderTarget.get());
} }
void GrDrawContext::drawNonAAFilledRect(const GrClip& clip, void GrRenderTargetContext::drawNonAAFilledRect(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& rect, const SkRect& rect,
const SkRect* localRect, const SkRect* localRect,
const SkMatrix* localMatrix, const SkMatrix* localMatrix,
const GrUserStencilSettings* ss, const GrUserStencilSettings* ss,
bool useHWAA) { bool useHWAA) {
SkASSERT(!useHWAA || this->isStencilBufferMultisampled()); SkASSERT(!useHWAA || this->isStencilBufferMultisampled());
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect, localRect, GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect, localRect,
@ -1137,8 +1144,8 @@ void GrDrawContext::drawNonAAFilledRect(const GrClip& clip,
this->getOpList()->drawBatch(pipelineBuilder, this, clip, batch); this->getOpList()->drawBatch(pipelineBuilder, this, clip, batch);
} }
bool GrDrawContext::readPixels(const SkImageInfo& dstInfo, void* dstBuffer, size_t dstRowBytes, bool GrRenderTargetContext::readPixels(const SkImageInfo& dstInfo, void* dstBuffer,
int x, int y) { size_t dstRowBytes, int x, int y) {
// TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels // TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels
GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps()); GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps());
if (kUnknown_GrPixelConfig == config) { if (kUnknown_GrPixelConfig == config) {
@ -1154,8 +1161,8 @@ bool GrDrawContext::readPixels(const SkImageInfo& dstInfo, void* dstBuffer, size
config, dstBuffer, dstRowBytes, flags); config, dstBuffer, dstRowBytes, flags);
} }
bool GrDrawContext::writePixels(const SkImageInfo& srcInfo, const void* srcBuffer, bool GrRenderTargetContext::writePixels(const SkImageInfo& srcInfo, const void* srcBuffer,
size_t srcRowBytes, int x, int y) { size_t srcRowBytes, int x, int y) {
// TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels // TODO: teach fRenderTarget to take ImageInfo directly to specify the src pixels
GrPixelConfig config = SkImageInfo2GrPixelConfig(srcInfo, *fContext->caps()); GrPixelConfig config = SkImageInfo2GrPixelConfig(srcInfo, *fContext->caps());
if (kUnknown_GrPixelConfig == config) { if (kUnknown_GrPixelConfig == config) {
@ -1216,15 +1223,15 @@ static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path
return allEq || allGoE1; return allEq || allGoE1;
} }
void GrDrawContext::drawPath(const GrClip& clip, void GrRenderTargetContext::drawPath(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkPath& path, const SkPath& path,
const GrStyle& style) { const GrStyle& style) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawPath");
if (path.isEmpty()) { if (path.isEmpty()) {
if (path.isInverseFillType()) { if (path.isInverseFillType()) {
@ -1277,34 +1284,34 @@ void GrDrawContext::drawPath(const GrClip& clip,
this->internalDrawPath(clip, paint, viewMatrix, path, style); this->internalDrawPath(clip, paint, viewMatrix, path, style);
} }
bool GrDrawContextPriv::drawAndStencilPath(const GrClip& clip, bool GrRenderTargetContextPriv::drawAndStencilPath(const GrClip& clip,
const GrUserStencilSettings* ss, const GrUserStencilSettings* ss,
SkRegion::Op op, SkRegion::Op op,
bool invert, bool invert,
bool doAA, bool doAA,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkPath& path) { const SkPath& path) {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
RETURN_FALSE_IF_ABANDONED_PRIV RETURN_FALSE_IF_ABANDONED_PRIV
SkDEBUGCODE(fDrawContext->validate();) SkDEBUGCODE(fRenderTargetContext->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawPath"); GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, "GrRenderTargetContext::drawPath");
if (path.isEmpty() && path.isInverseFillType()) { if (path.isEmpty() && path.isInverseFillType()) {
this->drawAndStencilRect(clip, ss, op, invert, false, SkMatrix::I(), this->drawAndStencilRect(clip, ss, op, invert, false, SkMatrix::I(),
SkRect::MakeIWH(fDrawContext->width(), SkRect::MakeIWH(fRenderTargetContext->width(),
fDrawContext->height())); fRenderTargetContext->height()));
return true; return true;
} }
AutoCheckFlush acf(fDrawContext->fDrawingManager); AutoCheckFlush acf(fRenderTargetContext->fDrawingManager);
// An Assumption here is that path renderer would use some form of tweaking // An Assumption here is that path renderer would use some form of tweaking
// the src color (either the input alpha or in the frag shader) to implement // the src color (either the input alpha or in the frag shader) to implement
// aa. If we have some future driver-mojo path AA that can do the right // aa. If we have some future driver-mojo path AA that can do the right
// thing WRT to the blend then we'll need some query on the PR. // thing WRT to the blend then we'll need some query on the PR.
bool useCoverageAA = doAA && !fDrawContext->isUnifiedMultisampled(); bool useCoverageAA = doAA && !fRenderTargetContext->isUnifiedMultisampled();
bool hasUserStencilSettings = !ss->isUnused(); bool hasUserStencilSettings = !ss->isUnused();
bool isStencilBufferMSAA = fDrawContext->isStencilBufferMultisampled(); bool isStencilBufferMSAA = fRenderTargetContext->isStencilBufferMultisampled();
const GrPathRendererChain::DrawType type = const GrPathRendererChain::DrawType type =
useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType
@ -1312,7 +1319,8 @@ bool GrDrawContextPriv::drawAndStencilPath(const GrClip& clip,
GrShape shape(path, GrStyle::SimpleFill()); GrShape shape(path, GrStyle::SimpleFill());
GrPathRenderer::CanDrawPathArgs canDrawArgs; GrPathRenderer::CanDrawPathArgs canDrawArgs;
canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps()->shaderCaps(); canDrawArgs.fShaderCaps =
fRenderTargetContext->fDrawingManager->getContext()->caps()->shaderCaps();
canDrawArgs.fViewMatrix = &viewMatrix; canDrawArgs.fViewMatrix = &viewMatrix;
canDrawArgs.fShape = &shape; canDrawArgs.fShape = &shape;
canDrawArgs.fAntiAlias = useCoverageAA; canDrawArgs.fAntiAlias = useCoverageAA;
@ -1320,7 +1328,8 @@ bool GrDrawContextPriv::drawAndStencilPath(const GrClip& clip,
canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA;
// Don't allow the SW renderer // Don't allow the SW renderer
GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawArgs, false, type); GrPathRenderer* pr = fRenderTargetContext->fDrawingManager->getPathRenderer(canDrawArgs, false,
type);
if (!pr) { if (!pr) {
return false; return false;
} }
@ -1329,36 +1338,37 @@ bool GrDrawContextPriv::drawAndStencilPath(const GrClip& clip,
paint.setCoverageSetOpXPFactory(op, invert); paint.setCoverageSetOpXPFactory(op, invert);
GrPathRenderer::DrawPathArgs args; GrPathRenderer::DrawPathArgs args;
args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resourceProvider(); args.fResourceProvider =
fRenderTargetContext->fDrawingManager->getContext()->resourceProvider();
args.fPaint = &paint; args.fPaint = &paint;
args.fUserStencilSettings = ss; args.fUserStencilSettings = ss;
args.fDrawContext = fDrawContext; args.fRenderTargetContext = fRenderTargetContext;
args.fClip = &clip; args.fClip = &clip;
args.fViewMatrix = &viewMatrix; args.fViewMatrix = &viewMatrix;
args.fShape = &shape; args.fShape = &shape;
args.fAntiAlias = useCoverageAA; args.fAntiAlias = useCoverageAA;
args.fGammaCorrect = fDrawContext->isGammaCorrect(); args.fGammaCorrect = fRenderTargetContext->isGammaCorrect();
pr->drawPath(args); pr->drawPath(args);
return true; return true;
} }
SkBudgeted GrDrawContextPriv::isBudgeted() const { SkBudgeted GrRenderTargetContextPriv::isBudgeted() const {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
if (fDrawContext->wasAbandoned()) { if (fRenderTargetContext->wasAbandoned()) {
return SkBudgeted::kNo; return SkBudgeted::kNo;
} }
SkDEBUGCODE(fDrawContext->validate();) SkDEBUGCODE(fRenderTargetContext->validate();)
return fDrawContext->fRenderTarget->resourcePriv().isBudgeted(); return fRenderTargetContext->fRenderTarget->resourcePriv().isBudgeted();
} }
void GrDrawContext::internalDrawPath(const GrClip& clip, void GrRenderTargetContext::internalDrawPath(const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkPath& path, const SkPath& path,
const GrStyle& style) { const GrStyle& style) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkASSERT(!path.isEmpty()); SkASSERT(!path.isEmpty());
@ -1417,7 +1427,7 @@ void GrDrawContext::internalDrawPath(const GrClip& clip,
args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); args.fResourceProvider = fDrawingManager->getContext()->resourceProvider();
args.fPaint = &paint; args.fPaint = &paint;
args.fUserStencilSettings = &GrUserStencilSettings::kUnused; args.fUserStencilSettings = &GrUserStencilSettings::kUnused;
args.fDrawContext = this; args.fRenderTargetContext = this;
args.fClip = &clip; args.fClip = &clip;
args.fViewMatrix = &viewMatrix; args.fViewMatrix = &viewMatrix;
args.fShape = canDrawArgs.fShape; args.fShape = canDrawArgs.fShape;
@ -1426,12 +1436,12 @@ void GrDrawContext::internalDrawPath(const GrClip& clip,
pr->drawPath(args); pr->drawPath(args);
} }
void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const GrClip& clip, void GrRenderTargetContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const GrClip& clip,
GrDrawBatch* batch) { GrDrawBatch* batch) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::drawBatch");
this->getOpList()->drawBatch(pipelineBuilder, this, clip, batch); this->getOpList()->drawBatch(pipelineBuilder, this, clip, batch);
} }

View File

@ -5,10 +5,10 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#ifndef GrDrawContextPriv_DEFINED #ifndef GrRenderTargetContextPriv_DEFINED
#define GrDrawContextPriv_DEFINED #define GrRenderTargetContextPriv_DEFINED
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrRenderTargetOpList.h" #include "GrRenderTargetOpList.h"
#include "GrPathRendering.h" #include "GrPathRendering.h"
@ -16,13 +16,13 @@ class GrFixedClip;
class GrPath; class GrPath;
struct GrUserStencilSettings; struct GrUserStencilSettings;
/** Class that adds methods to GrDrawContext that are only intended for use internal to Skia. /** Class that adds methods to GrRenderTargetContext that are only intended for use internal to
This class is purely a privileged window into GrDrawContext. It should never have additional Skia. This class is purely a privileged window into GrRenderTargetContext. It should never have
data members or virtual methods. */ additional data members or virtual methods. */
class GrDrawContextPriv { class GrRenderTargetContextPriv {
public: public:
gr_instanced::InstancedRendering* accessInstancedRendering() const { gr_instanced::InstancedRendering* accessInstancedRendering() const {
return fDrawContext->getOpList()->instancedRendering(); return fRenderTargetContext->getOpList()->instancedRendering();
} }
void clear(const GrFixedClip&, const GrColor, bool canIgnoreClip); void clear(const GrFixedClip&, const GrColor, bool canIgnoreClip);
@ -64,23 +64,26 @@ public:
bool snapToCenters = false); bool snapToCenters = false);
private: private:
explicit GrDrawContextPriv(GrDrawContext* drawContext) : fDrawContext(drawContext) {} explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext)
GrDrawContextPriv(const GrRenderTargetPriv&) {} // unimpl : fRenderTargetContext(renderTargetContext) {}
GrDrawContextPriv& operator=(const GrRenderTargetPriv&); // unimpl GrRenderTargetContextPriv(const GrRenderTargetPriv&) {} // unimpl
GrRenderTargetContextPriv& operator=(const GrRenderTargetPriv&); // unimpl
// No taking addresses of this type. // No taking addresses of this type.
const GrDrawContextPriv* operator&() const; const GrRenderTargetContextPriv* operator&() const;
GrDrawContextPriv* operator&(); GrRenderTargetContextPriv* operator&();
GrDrawContext* fDrawContext; GrRenderTargetContext* fRenderTargetContext;
friend class GrDrawContext; // to construct/copy this type. friend class GrRenderTargetContext; // to construct/copy this type.
}; };
inline GrDrawContextPriv GrDrawContext::drawContextPriv() { return GrDrawContextPriv(this); } inline GrRenderTargetContextPriv GrRenderTargetContext::renderTargetContextPriv() {
return GrRenderTargetContextPriv(this);
}
inline const GrDrawContextPriv GrDrawContext::drawContextPriv () const { inline const GrRenderTargetContextPriv GrRenderTargetContext::renderTargetContextPriv () const {
return GrDrawContextPriv(const_cast<GrDrawContext*>(this)); return GrRenderTargetContextPriv(const_cast<GrRenderTargetContext*>(this));
} }
#endif #endif

View File

@ -10,7 +10,7 @@
#include "GrAppliedClip.h" #include "GrAppliedClip.h"
#include "GrAuditTrail.h" #include "GrAuditTrail.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrGpu.h" #include "GrGpu.h"
#include "GrGpuCommandBuffer.h" #include "GrGpuCommandBuffer.h"
#include "GrPath.h" #include "GrPath.h"
@ -277,14 +277,14 @@ static void batch_bounds(SkRect* bounds, const GrBatch* batch) {
} }
void GrRenderTargetOpList::drawBatch(const GrPipelineBuilder& pipelineBuilder, void GrRenderTargetOpList::drawBatch(const GrPipelineBuilder& pipelineBuilder,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
GrDrawBatch* batch) { GrDrawBatch* batch) {
// Setup clip // Setup clip
SkRect bounds; SkRect bounds;
batch_bounds(&bounds, batch); batch_bounds(&bounds, batch);
GrAppliedClip appliedClip(bounds); GrAppliedClip appliedClip(bounds);
if (!clip.apply(fContext, drawContext, pipelineBuilder.isHWAntialias(), if (!clip.apply(fContext, renderTargetContext, pipelineBuilder.isHWAntialias(),
pipelineBuilder.hasUserStencilSettings(), &appliedClip)) { pipelineBuilder.hasUserStencilSettings(), &appliedClip)) {
return; return;
} }
@ -297,7 +297,8 @@ void GrRenderTargetOpList::drawBatch(const GrPipelineBuilder& pipelineBuilder,
} }
if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip()) { if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip()) {
if (!fResourceProvider->attachStencilAttachment(drawContext->accessRenderTarget())) { if (!fResourceProvider->attachStencilAttachment(
renderTargetContext->accessRenderTarget())) {
SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); SkDebugf("ERROR creating stencil attachment. Draw skipped.\n");
return; return;
} }
@ -305,15 +306,15 @@ void GrRenderTargetOpList::drawBatch(const GrPipelineBuilder& pipelineBuilder,
GrPipeline::CreateArgs args; GrPipeline::CreateArgs args;
args.fPipelineBuilder = &pipelineBuilder; args.fPipelineBuilder = &pipelineBuilder;
args.fDrawContext = drawContext; args.fRenderTargetContext = renderTargetContext;
args.fCaps = this->caps(); args.fCaps = this->caps();
batch->getPipelineOptimizations(&args.fOpts); batch->getPipelineOptimizations(&args.fOpts);
if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) { if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) {
GrGLIRect viewport; GrGLIRect viewport;
viewport.fLeft = 0; viewport.fLeft = 0;
viewport.fBottom = 0; viewport.fBottom = 0;
viewport.fWidth = drawContext->width(); viewport.fWidth = renderTargetContext->width();
viewport.fHeight = drawContext->height(); viewport.fHeight = renderTargetContext->height();
SkIRect ibounds; SkIRect ibounds;
ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewport.fLeft, ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewport.fLeft,
viewport.fWidth); viewport.fWidth);
@ -336,7 +337,7 @@ void GrRenderTargetOpList::drawBatch(const GrPipelineBuilder& pipelineBuilder,
args.fScissor = &appliedClip.scissorState(); args.fScissor = &appliedClip.scissorState();
args.fWindowRectsState = &appliedClip.windowRectsState(); args.fWindowRectsState = &appliedClip.windowRectsState();
args.fHasStencilClip = appliedClip.hasStencilClip(); args.fHasStencilClip = appliedClip.hasStencilClip();
if (!this->setupDstReadIfNecessary(pipelineBuilder, drawContext->accessRenderTarget(), if (!this->setupDstReadIfNecessary(pipelineBuilder, renderTargetContext->accessRenderTarget(),
clip, args.fOpts, clip, args.fOpts,
&args.fDstTexture, batch->bounds())) { &args.fDstTexture, batch->bounds())) {
return; return;
@ -353,7 +354,7 @@ void GrRenderTargetOpList::drawBatch(const GrPipelineBuilder& pipelineBuilder,
this->recordBatch(batch, appliedClip.clippedDrawBounds()); this->recordBatch(batch, appliedClip.clippedDrawBounds());
} }
void GrRenderTargetOpList::stencilPath(GrDrawContext* drawContext, void GrRenderTargetOpList::stencilPath(GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
bool useHWAA, bool useHWAA,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -364,11 +365,11 @@ void GrRenderTargetOpList::stencilPath(GrDrawContext* drawContext,
// FIXME: Use path bounds instead of this WAR once // FIXME: Use path bounds instead of this WAR once
// https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved.
SkRect bounds = SkRect::MakeIWH(drawContext->width(), drawContext->height()); SkRect bounds = SkRect::MakeIWH(renderTargetContext->width(), renderTargetContext->height());
// Setup clip // Setup clip
GrAppliedClip appliedClip(bounds); GrAppliedClip appliedClip(bounds);
if (!clip.apply(fContext, drawContext, useHWAA, true, &appliedClip)) { if (!clip.apply(fContext, renderTargetContext, useHWAA, true, &appliedClip)) {
return; return;
} }
// TODO: respect fClipBatchToBounds if we ever start computing bounds here. // TODO: respect fClipBatchToBounds if we ever start computing bounds here.
@ -378,7 +379,7 @@ void GrRenderTargetOpList::stencilPath(GrDrawContext* drawContext,
SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); SkASSERT(!appliedClip.clipCoverageFragmentProcessor());
GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAttachment( GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAttachment(
drawContext->accessRenderTarget()); renderTargetContext->accessRenderTarget());
if (!stencilAttachment) { if (!stencilAttachment) {
SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); SkDebugf("ERROR creating stencil attachment. Draw skipped.\n");
return; return;
@ -390,7 +391,7 @@ void GrRenderTargetOpList::stencilPath(GrDrawContext* drawContext,
appliedClip.hasStencilClip(), appliedClip.hasStencilClip(),
stencilAttachment->bits(), stencilAttachment->bits(),
appliedClip.scissorState(), appliedClip.scissorState(),
drawContext->accessRenderTarget(), renderTargetContext->accessRenderTarget(),
path); path);
this->recordBatch(batch, appliedClip.clippedDrawBounds()); this->recordBatch(batch, appliedClip.clippedDrawBounds());
batch->unref(); batch->unref();

View File

@ -84,7 +84,7 @@ public:
*/ */
const GrCaps* caps() const { return fGpu->caps(); } const GrCaps* caps() const { return fGpu->caps(); }
void drawBatch(const GrPipelineBuilder&, GrDrawContext*, const GrClip&, GrDrawBatch*); void drawBatch(const GrPipelineBuilder&, GrRenderTargetContext*, const GrClip&, GrDrawBatch*);
void addBatch(sk_sp<GrBatch>); void addBatch(sk_sp<GrBatch>);
@ -95,7 +95,7 @@ public:
* possible in the 3D API). Note, we will never have an inverse fill with * possible in the 3D API). Note, we will never have an inverse fill with
* stencil path. * stencil path.
*/ */
void stencilPath(GrDrawContext*, void stencilPath(GrRenderTargetContext*,
const GrClip&, const GrClip&,
bool useHWAA, bool useHWAA,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -130,7 +130,7 @@ public:
SkDEBUGCODE(void dump() const override;) SkDEBUGCODE(void dump() const override;)
private: private:
friend class GrDrawContextPriv; // for clearStencilClip friend class GrRenderTargetContextPriv; // for clearStencilClip
// Returns the batch that the input batch was combined with or the input batch if it wasn't // Returns the batch that the input batch was combined with or the input batch if it wasn't
// combined. // combined.
@ -147,7 +147,7 @@ private:
GrXferProcessor::DstTexture*, GrXferProcessor::DstTexture*,
const SkRect& batchBounds); const SkRect& batchBounds);
// Used only by drawContextPriv. // Used only by renderTargetContextPriv.
void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*); void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*);
struct RecordedBatch { struct RecordedBatch {

View File

@ -10,7 +10,7 @@
#include "GrCaps.h" #include "GrCaps.h"
#include "GrContext.h" #include "GrContext.h"
#include "batches/GrDrawBatch.h" #include "batches/GrDrawBatch.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrPipelineBuilder.h" #include "GrPipelineBuilder.h"
#include "GrShape.h" #include "GrShape.h"
@ -163,7 +163,7 @@ GrTexture* GrSWMaskHelper::DrawShapeMaskToTexture(GrTextureProvider* texProvider
} }
void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture, void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
const GrPaint& paint, const GrPaint& paint,
const GrUserStencilSettings& userStencilSettings, const GrUserStencilSettings& userStencilSettings,
const GrClip& clip, const GrClip& clip,
@ -185,7 +185,7 @@ void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture,
maskMatrix.preTranslate(SkIntToScalar(-textureOriginInDeviceSpace.fX), maskMatrix.preTranslate(SkIntToScalar(-textureOriginInDeviceSpace.fX),
SkIntToScalar(-textureOriginInDeviceSpace.fY)); SkIntToScalar(-textureOriginInDeviceSpace.fY));
maskMatrix.preConcat(viewMatrix); maskMatrix.preConcat(viewMatrix);
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint)); GrPipelineBuilder pipelineBuilder(paint, renderTargetContext->mustUseHWAA(paint));
pipelineBuilder.setUserStencil(&userStencilSettings); pipelineBuilder.setUserStencil(&userStencilSettings);
pipelineBuilder.addCoverageFragmentProcessor( pipelineBuilder.addCoverageFragmentProcessor(
@ -197,5 +197,5 @@ void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture,
SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(paint.getColor(),
SkMatrix::I(), SkMatrix::I(),
dstRect, nullptr, &invert)); dstRect, nullptr, &invert));
drawContext->drawBatch(pipelineBuilder, clip, batch); renderTargetContext->drawBatch(pipelineBuilder, clip, batch);
} }

View File

@ -86,7 +86,7 @@ public:
// The rectangle is drawn in device space. The 'viewMatrix' will be used to ensure the correct // The rectangle is drawn in device space. The 'viewMatrix' will be used to ensure the correct
// local coords are provided to any fragment processors in the paint. // local coords are provided to any fragment processors in the paint.
static void DrawToTargetWithShapeMask(GrTexture* texture, static void DrawToTargetWithShapeMask(GrTexture* texture,
GrDrawContext*, GrRenderTargetContext*,
const GrPaint& paint, const GrPaint& paint,
const GrUserStencilSettings& userStencilSettings, const GrUserStencilSettings& userStencilSettings,
const GrClip&, const GrClip&,

View File

@ -60,7 +60,7 @@ static bool get_shape_and_clip_bounds(int width, int height,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void GrSoftwarePathRenderer::DrawNonAARect(GrDrawContext* drawContext, void GrSoftwarePathRenderer::DrawNonAARect(GrRenderTargetContext* renderTargetContext,
const GrPaint& paint, const GrPaint& paint,
const GrUserStencilSettings& userStencilSettings, const GrUserStencilSettings& userStencilSettings,
const GrClip& clip, const GrClip& clip,
@ -71,13 +71,13 @@ void GrSoftwarePathRenderer::DrawNonAARect(GrDrawContext* drawContext,
viewMatrix, rect, viewMatrix, rect,
nullptr, &localMatrix)); nullptr, &localMatrix));
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint)); GrPipelineBuilder pipelineBuilder(paint, renderTargetContext->mustUseHWAA(paint));
pipelineBuilder.setUserStencil(&userStencilSettings); pipelineBuilder.setUserStencil(&userStencilSettings);
drawContext->drawBatch(pipelineBuilder, clip, batch); renderTargetContext->drawBatch(pipelineBuilder, clip, batch);
} }
void GrSoftwarePathRenderer::DrawAroundInvPath(GrDrawContext* drawContext, void GrSoftwarePathRenderer::DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
const GrPaint& paint, const GrPaint& paint,
const GrUserStencilSettings& userStencilSettings, const GrUserStencilSettings& userStencilSettings,
const GrClip& clip, const GrClip& clip,
@ -93,25 +93,25 @@ void GrSoftwarePathRenderer::DrawAroundInvPath(GrDrawContext* drawContext,
if (devClipBounds.fTop < devPathBounds.fTop) { if (devClipBounds.fTop < devPathBounds.fTop) {
rect.iset(devClipBounds.fLeft, devClipBounds.fTop, rect.iset(devClipBounds.fLeft, devClipBounds.fTop,
devClipBounds.fRight, devPathBounds.fTop); devClipBounds.fRight, devPathBounds.fTop);
DrawNonAARect(drawContext, paint, userStencilSettings, clip, DrawNonAARect(renderTargetContext, paint, userStencilSettings, clip,
SkMatrix::I(), rect, invert); SkMatrix::I(), rect, invert);
} }
if (devClipBounds.fLeft < devPathBounds.fLeft) { if (devClipBounds.fLeft < devPathBounds.fLeft) {
rect.iset(devClipBounds.fLeft, devPathBounds.fTop, rect.iset(devClipBounds.fLeft, devPathBounds.fTop,
devPathBounds.fLeft, devPathBounds.fBottom); devPathBounds.fLeft, devPathBounds.fBottom);
DrawNonAARect(drawContext, paint, userStencilSettings, clip, DrawNonAARect(renderTargetContext, paint, userStencilSettings, clip,
SkMatrix::I(), rect, invert); SkMatrix::I(), rect, invert);
} }
if (devClipBounds.fRight > devPathBounds.fRight) { if (devClipBounds.fRight > devPathBounds.fRight) {
rect.iset(devPathBounds.fRight, devPathBounds.fTop, rect.iset(devPathBounds.fRight, devPathBounds.fTop,
devClipBounds.fRight, devPathBounds.fBottom); devClipBounds.fRight, devPathBounds.fBottom);
DrawNonAARect(drawContext, paint, userStencilSettings, clip, DrawNonAARect(renderTargetContext, paint, userStencilSettings, clip,
SkMatrix::I(), rect, invert); SkMatrix::I(), rect, invert);
} }
if (devClipBounds.fBottom > devPathBounds.fBottom) { if (devClipBounds.fBottom > devPathBounds.fBottom) {
rect.iset(devClipBounds.fLeft, devPathBounds.fBottom, rect.iset(devClipBounds.fLeft, devPathBounds.fBottom,
devClipBounds.fRight, devClipBounds.fBottom); devClipBounds.fRight, devClipBounds.fBottom);
DrawNonAARect(drawContext, paint, userStencilSettings, clip, DrawNonAARect(renderTargetContext, paint, userStencilSettings, clip,
SkMatrix::I(), rect, invert); SkMatrix::I(), rect, invert);
} }
} }
@ -119,7 +119,7 @@ void GrSoftwarePathRenderer::DrawAroundInvPath(GrDrawContext* drawContext,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// return true on success; false on failure // return true on success; false on failure
bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrSoftwarePathRenderer::onDrawPath"); "GrSoftwarePathRenderer::onDrawPath");
if (!fTexProvider) { if (!fTexProvider) {
return false; return false;
@ -137,13 +137,14 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
bool useCache = fAllowCaching && !inverseFilled && args.fViewMatrix->preservesAxisAlignment() && bool useCache = fAllowCaching && !inverseFilled && args.fViewMatrix->preservesAxisAlignment() &&
args.fShape->hasUnstyledKey() && args.fAntiAlias; args.fShape->hasUnstyledKey() && args.fAntiAlias;
if (!get_shape_and_clip_bounds(args.fDrawContext->width(), args.fDrawContext->height(), if (!get_shape_and_clip_bounds(args.fRenderTargetContext->width(),
args.fRenderTargetContext->height(),
*args.fClip, *args.fShape, *args.fClip, *args.fShape,
*args.fViewMatrix, &unclippedDevShapeBounds, *args.fViewMatrix, &unclippedDevShapeBounds,
&clippedDevShapeBounds, &clippedDevShapeBounds,
&devClipBounds)) { &devClipBounds)) {
if (inverseFilled) { if (inverseFilled) {
DrawAroundInvPath(args.fDrawContext, *args.fPaint, *args.fUserStencilSettings, DrawAroundInvPath(args.fRenderTargetContext, *args.fPaint, *args.fUserStencilSettings,
*args.fClip, *args.fClip,
*args.fViewMatrix, devClipBounds, unclippedDevShapeBounds); *args.fViewMatrix, devClipBounds, unclippedDevShapeBounds);
@ -158,7 +159,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
int unclippedHeight = unclippedDevShapeBounds.height(); int unclippedHeight = unclippedDevShapeBounds.height();
int unclippedArea = unclippedWidth * unclippedHeight; int unclippedArea = unclippedWidth * unclippedHeight;
int clippedArea = clippedDevShapeBounds.width() * clippedDevShapeBounds.height(); int clippedArea = clippedDevShapeBounds.width() * clippedDevShapeBounds.height();
int maxTextureSize = args.fDrawContext->caps()->maxTextureSize(); int maxTextureSize = args.fRenderTargetContext->caps()->maxTextureSize();
if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize || if (unclippedArea > 2 * clippedArea || unclippedWidth > maxTextureSize ||
unclippedHeight > maxTextureSize) { unclippedHeight > maxTextureSize) {
useCache = false; useCache = false;
@ -212,14 +213,14 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
} }
} }
GrSWMaskHelper::DrawToTargetWithShapeMask(texture.get(), args.fDrawContext, *args.fPaint, GrSWMaskHelper::DrawToTargetWithShapeMask(texture.get(), args.fRenderTargetContext,
*args.fUserStencilSettings, *args.fPaint, *args.fUserStencilSettings,
*args.fClip, *args.fViewMatrix, *args.fClip, *args.fViewMatrix,
SkIPoint {boundsForMask->fLeft, boundsForMask->fTop}, SkIPoint {boundsForMask->fLeft, boundsForMask->fTop},
*boundsForMask); *boundsForMask);
if (inverseFilled) { if (inverseFilled) {
DrawAroundInvPath(args.fDrawContext, *args.fPaint, *args.fUserStencilSettings, DrawAroundInvPath(args.fRenderTargetContext, *args.fPaint, *args.fUserStencilSettings,
*args.fClip, *args.fClip,
*args.fViewMatrix, devClipBounds, unclippedDevShapeBounds); *args.fViewMatrix, devClipBounds, unclippedDevShapeBounds);
} }

View File

@ -22,14 +22,14 @@ public:
: fTexProvider(texProvider) : fTexProvider(texProvider)
, fAllowCaching(allowCaching) {} , fAllowCaching(allowCaching) {}
private: private:
static void DrawNonAARect(GrDrawContext* drawContext, static void DrawNonAARect(GrRenderTargetContext* renderTargetContext,
const GrPaint& paint, const GrPaint& paint,
const GrUserStencilSettings& userStencilSettings, const GrUserStencilSettings& userStencilSettings,
const GrClip& clip, const GrClip& clip,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkRect& rect, const SkRect& rect,
const SkMatrix& localMatrix); const SkMatrix& localMatrix);
static void DrawAroundInvPath(GrDrawContext* drawContext, static void DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
const GrPaint& paint, const GrPaint& paint,
const GrUserStencilSettings& userStencilSettings, const GrUserStencilSettings& userStencilSettings,
const GrClip& clip, const GrClip& clip,

View File

@ -10,7 +10,7 @@
#include "GrCaps.h" #include "GrCaps.h"
#include "GrColorSpaceXform.h" #include "GrColorSpaceXform.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrGpu.h" #include "GrGpu.h"
#include "GrGpuResourcePriv.h" #include "GrGpuResourcePriv.h"
#include "GrResourceKey.h" #include "GrResourceKey.h"
@ -36,10 +36,8 @@ static GrTexture* copy_on_gpu(GrTexture* inputTexture, const SkIRect* subset,
GrPixelConfig config = GrMakePixelConfigUncompressed(inputTexture->config()); GrPixelConfig config = GrMakePixelConfigUncompressed(inputTexture->config());
sk_sp<GrDrawContext> copyDC = context->makeDrawContextWithFallback(SkBackingFit::kExact, sk_sp<GrRenderTargetContext> copyDC = context->makeRenderTargetContextWithFallback(
copyParams.fWidth, SkBackingFit::kExact, copyParams.fWidth, copyParams.fHeight, config, nullptr);
copyParams.fHeight,
config, nullptr);
if (!copyDC) { if (!copyDC) {
return nullptr; return nullptr;
} }

View File

@ -10,7 +10,7 @@
#include "effects/GrYUVEffect.h" #include "effects/GrYUVEffect.h"
#include "GrClip.h" #include "GrClip.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrPaint.h" #include "GrPaint.h"
#include "GrTextureProvider.h" #include "GrTextureProvider.h"
@ -19,7 +19,7 @@ namespace {
SkYUVColorSpace colorSpace); SkYUVColorSpace colorSpace);
}; };
static bool convert_texture(GrTexture* src, GrDrawContext* dst, int dstW, int dstH, static bool convert_texture(GrTexture* src, GrRenderTargetContext* dst, int dstW, int dstH,
SkYUVColorSpace colorSpace, MakeFPProc proc) { SkYUVColorSpace colorSpace, MakeFPProc proc) {
SkScalar xScale = SkIntToScalar(src->width()) / dstW / src->width(); SkScalar xScale = SkIntToScalar(src->width()) / dstW / src->width();
@ -52,88 +52,93 @@ bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons
if (GrContext* context = texture->getContext()) { if (GrContext* context = texture->getContext()) {
// Depending on the relative sizes of the y, u, and v planes we may do 1 to 3 draws/ // Depending on the relative sizes of the y, u, and v planes we may do 1 to 3 draws/
// readbacks. // readbacks.
sk_sp<GrDrawContext> yuvDrawContext; sk_sp<GrRenderTargetContext> yuvRenderTargetContext;
sk_sp<GrDrawContext> yDrawContext; sk_sp<GrRenderTargetContext> yRenderTargetContext;
sk_sp<GrDrawContext> uvDrawContext; sk_sp<GrRenderTargetContext> uvRenderTargetContext;
sk_sp<GrDrawContext> uDrawContext; sk_sp<GrRenderTargetContext> uRenderTargetContext;
sk_sp<GrDrawContext> vDrawContext; sk_sp<GrRenderTargetContext> vRenderTargetContext;
// We issue draw(s) to convert from RGBA to Y, U, and V. All three planes may have different // We issue draw(s) to convert from RGBA to Y, U, and V. All three planes may have different
// sizes however we optimize for two other cases - all planes are the same (1 draw to YUV), // sizes however we optimize for two other cases - all planes are the same (1 draw to YUV),
// and U and V are the same but Y differs (2 draws, one for Y, one for UV). // and U and V are the same but Y differs (2 draws, one for Y, one for UV).
if (sizes[0] == sizes[1] && sizes[1] == sizes[2]) { if (sizes[0] == sizes[1] && sizes[1] == sizes[2]) {
yuvDrawContext = context->makeDrawContextWithFallback(SkBackingFit::kApprox, yuvRenderTargetContext = context->makeRenderTargetContextWithFallback(
sizes[0].fWidth, SkBackingFit::kApprox,
sizes[0].fHeight, sizes[0].fWidth,
kRGBA_8888_GrPixelConfig, sizes[0].fHeight,
nullptr); kRGBA_8888_GrPixelConfig,
if (!yuvDrawContext) { nullptr);
if (!yuvRenderTargetContext) {
return false; return false;
} }
} else { } else {
yDrawContext = context->makeDrawContextWithFallback(SkBackingFit::kApprox, yRenderTargetContext = context->makeRenderTargetContextWithFallback(
sizes[0].fWidth, SkBackingFit::kApprox,
sizes[0].fHeight, sizes[0].fWidth,
kAlpha_8_GrPixelConfig, sizes[0].fHeight,
nullptr); kAlpha_8_GrPixelConfig,
if (!yDrawContext) { nullptr);
if (!yRenderTargetContext) {
return false; return false;
} }
if (sizes[1] == sizes[2]) { if (sizes[1] == sizes[2]) {
// TODO: Add support for GL_RG when available. // TODO: Add support for GL_RG when available.
uvDrawContext = context->makeDrawContextWithFallback(SkBackingFit::kApprox, uvRenderTargetContext = context->makeRenderTargetContextWithFallback(
sizes[1].fWidth, SkBackingFit::kApprox,
sizes[1].fHeight, sizes[1].fWidth,
kRGBA_8888_GrPixelConfig, sizes[1].fHeight,
nullptr); kRGBA_8888_GrPixelConfig,
if (!uvDrawContext) { nullptr);
if (!uvRenderTargetContext) {
return false; return false;
} }
} else { } else {
uDrawContext = context->makeDrawContextWithFallback(SkBackingFit::kApprox, uRenderTargetContext = context->makeRenderTargetContextWithFallback(
sizes[1].fWidth, SkBackingFit::kApprox,
sizes[1].fHeight, sizes[1].fWidth,
kAlpha_8_GrPixelConfig, sizes[1].fHeight,
nullptr); kAlpha_8_GrPixelConfig,
vDrawContext = context->makeDrawContextWithFallback(SkBackingFit::kApprox, nullptr);
sizes[2].fWidth, vRenderTargetContext = context->makeRenderTargetContextWithFallback(
sizes[2].fHeight, SkBackingFit::kApprox,
kAlpha_8_GrPixelConfig, sizes[2].fWidth,
nullptr); sizes[2].fHeight,
if (!uDrawContext || !vDrawContext) { kAlpha_8_GrPixelConfig,
nullptr);
if (!uRenderTargetContext || !vRenderTargetContext) {
return false; return false;
} }
} }
} }
// Do all the draws before any readback. // Do all the draws before any readback.
if (yuvDrawContext) { if (yuvRenderTargetContext) {
if (!convert_texture(texture, yuvDrawContext.get(), if (!convert_texture(texture, yuvRenderTargetContext.get(),
sizes[0].fWidth, sizes[0].fHeight, sizes[0].fWidth, sizes[0].fHeight,
colorSpace, GrYUVEffect::MakeRGBToYUV)) { colorSpace, GrYUVEffect::MakeRGBToYUV)) {
return false; return false;
} }
} else { } else {
SkASSERT(yDrawContext); SkASSERT(yRenderTargetContext);
if (!convert_texture(texture, yDrawContext.get(), if (!convert_texture(texture, yRenderTargetContext.get(),
sizes[0].fWidth, sizes[0].fHeight, sizes[0].fWidth, sizes[0].fHeight,
colorSpace, GrYUVEffect::MakeRGBToY)) { colorSpace, GrYUVEffect::MakeRGBToY)) {
return false; return false;
} }
if (uvDrawContext) { if (uvRenderTargetContext) {
if (!convert_texture(texture, uvDrawContext.get(), if (!convert_texture(texture, uvRenderTargetContext.get(),
sizes[1].fWidth, sizes[1].fHeight, sizes[1].fWidth, sizes[1].fHeight,
colorSpace, GrYUVEffect::MakeRGBToUV)) { colorSpace, GrYUVEffect::MakeRGBToUV)) {
return false; return false;
} }
} else { } else {
SkASSERT(uDrawContext && vDrawContext); SkASSERT(uRenderTargetContext && vRenderTargetContext);
if (!convert_texture(texture, uDrawContext.get(), if (!convert_texture(texture, uRenderTargetContext.get(),
sizes[1].fWidth, sizes[1].fHeight, sizes[1].fWidth, sizes[1].fHeight,
colorSpace, GrYUVEffect::MakeRGBToU)) { colorSpace, GrYUVEffect::MakeRGBToU)) {
return false; return false;
} }
if (!convert_texture(texture, vDrawContext.get(), if (!convert_texture(texture, vRenderTargetContext.get(),
sizes[2].fWidth, sizes[2].fHeight, sizes[2].fWidth, sizes[2].fHeight,
colorSpace, GrYUVEffect::MakeRGBToV)) { colorSpace, GrYUVEffect::MakeRGBToV)) {
return false; return false;
@ -141,9 +146,9 @@ bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons
} }
} }
if (yuvDrawContext) { if (yuvRenderTargetContext) {
SkASSERT(sizes[0] == sizes[1] && sizes[1] == sizes[2]); SkASSERT(sizes[0] == sizes[1] && sizes[1] == sizes[2]);
sk_sp<GrTexture> yuvTex(yuvDrawContext->asTexture()); sk_sp<GrTexture> yuvTex(yuvRenderTargetContext->asTexture());
SkASSERT(yuvTex); SkASSERT(yuvTex);
SkISize yuvSize = sizes[0]; SkISize yuvSize = sizes[0];
// We have no kRGB_888 pixel format, so readback rgba and then copy three channels. // We have no kRGB_888 pixel format, so readback rgba and then copy three channels.
@ -175,16 +180,16 @@ bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons
} }
return true; return true;
} else { } else {
SkASSERT(yDrawContext); SkASSERT(yRenderTargetContext);
sk_sp<GrTexture> yTex(yDrawContext->asTexture()); sk_sp<GrTexture> yTex(yRenderTargetContext->asTexture());
SkASSERT(yTex); SkASSERT(yTex);
if (!yTex->readPixels(0, 0, sizes[0].fWidth, sizes[0].fHeight, if (!yTex->readPixels(0, 0, sizes[0].fWidth, sizes[0].fHeight,
kAlpha_8_GrPixelConfig, planes[0], rowBytes[0])) { kAlpha_8_GrPixelConfig, planes[0], rowBytes[0])) {
return false; return false;
} }
if (uvDrawContext) { if (uvRenderTargetContext) {
SkASSERT(sizes[1].fWidth == sizes[2].fWidth); SkASSERT(sizes[1].fWidth == sizes[2].fWidth);
sk_sp<GrTexture> uvTex(uvDrawContext->asTexture()); sk_sp<GrTexture> uvTex(uvRenderTargetContext->asTexture());
SkASSERT(uvTex); SkASSERT(uvTex);
SkISize uvSize = sizes[1]; SkISize uvSize = sizes[1];
// We have no kRG_88 pixel format, so readback rgba and then copy two channels. // We have no kRG_88 pixel format, so readback rgba and then copy two channels.
@ -212,14 +217,14 @@ bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons
} }
return true; return true;
} else { } else {
SkASSERT(uDrawContext && vDrawContext); SkASSERT(uRenderTargetContext && vRenderTargetContext);
sk_sp<GrTexture> tex(uDrawContext->asTexture()); sk_sp<GrTexture> tex(uRenderTargetContext->asTexture());
SkASSERT(tex); SkASSERT(tex);
if (!tex->readPixels(0, 0, sizes[1].fWidth, sizes[1].fHeight, if (!tex->readPixels(0, 0, sizes[1].fWidth, sizes[1].fHeight,
kAlpha_8_GrPixelConfig, planes[1], rowBytes[1])) { kAlpha_8_GrPixelConfig, planes[1], rowBytes[1])) {
return false; return false;
} }
tex = vDrawContext->asTexture(); tex = vRenderTargetContext->asTexture();
SkASSERT(tex); SkASSERT(tex);
if (!tex->readPixels(0, 0, sizes[2].fWidth, sizes[2].fHeight, if (!tex->readPixels(0, 0, sizes[2].fWidth, sizes[2].fHeight,
kAlpha_8_GrPixelConfig, planes[2], rowBytes[2])) { kAlpha_8_GrPixelConfig, planes[2], rowBytes[2])) {

View File

@ -6,7 +6,7 @@
*/ */
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrYUVProvider.h" #include "GrYUVProvider.h"
#include "effects/GrGammaEffect.h" #include "effects/GrGammaEffect.h"
#include "effects/GrYUVEffect.h" #include "effects/GrYUVEffect.h"
@ -114,11 +114,12 @@ sk_sp<GrTexture> GrYUVProvider::refAsTexture(GrContext* ctx,
} }
// We never want to perform color-space conversion during the decode // We never want to perform color-space conversion during the decode
sk_sp<GrDrawContext> drawContext(ctx->makeDrawContext(SkBackingFit::kExact, sk_sp<GrRenderTargetContext> renderTargetContext(ctx->makeRenderTargetContext(
desc.fWidth, desc.fHeight, SkBackingFit::kExact,
desc.fConfig, nullptr, desc.fWidth, desc.fHeight,
desc.fSampleCnt)); desc.fConfig, nullptr,
if (!drawContext) { desc.fSampleCnt));
if (!renderTargetContext) {
return nullptr; return nullptr;
} }
@ -146,7 +147,7 @@ sk_sp<GrTexture> GrYUVProvider::refAsTexture(GrContext* ctx,
const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth, const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth,
yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), r); renderTargetContext->drawRect(GrNoClip(), paint, SkMatrix::I(), r);
return drawContext->asTexture(); return renderTargetContext->asTexture();
} }

View File

@ -9,7 +9,7 @@
#include "GrBlurUtils.h" #include "GrBlurUtils.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrGpu.h" #include "GrGpu.h"
#include "GrImageIDTextureAdjuster.h" #include "GrImageIDTextureAdjuster.h"
#include "GrStyle.h" #include "GrStyle.h"
@ -87,17 +87,18 @@ bool SkGpuDevice::CheckAlphaTypeAndGetFlags(
return true; return true;
} }
sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTargetContext> renderTargetContext,
int width, int height, int width, int height,
InitContents init) { InitContents init) {
if (!drawContext || drawContext->wasAbandoned()) { if (!renderTargetContext || renderTargetContext->wasAbandoned()) {
return nullptr; return nullptr;
} }
unsigned flags; unsigned flags;
if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) {
return nullptr; return nullptr;
} }
return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, height, flags)); return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(renderTargetContext), width, height,
flags));
} }
sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted,
@ -109,17 +110,18 @@ sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted,
return nullptr; return nullptr;
} }
sk_sp<GrDrawContext> drawContext(MakeDrawContext(context, budgeted, info, sk_sp<GrRenderTargetContext> renderTargetContext(MakeRenderTargetContext(context, budgeted,
sampleCount, origin, props)); info, sampleCount,
if (!drawContext) { origin, props));
if (!renderTargetContext) {
return nullptr; return nullptr;
} }
return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(renderTargetContext),
info.width(), info.height(), flags)); info.width(), info.height(), flags));
} }
static SkImageInfo make_info(GrDrawContext* context, int w, int h, bool opaque) { static SkImageInfo make_info(GrRenderTargetContext* context, int w, int h, bool opaque) {
SkColorType colorType; SkColorType colorType;
if (!GrPixelConfigToColorType(context->config(), &colorType)) { if (!GrPixelConfigToColorType(context->config(), &colorType)) {
colorType = kUnknown_SkColorType; colorType = kUnknown_SkColorType;
@ -129,11 +131,12 @@ static SkImageInfo make_info(GrDrawContext* context, int w, int h, bool opaque)
sk_ref_sp(context->getColorSpace())); sk_ref_sp(context->getColorSpace()));
} }
SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height, unsigned flags) SkGpuDevice::SkGpuDevice(sk_sp<GrRenderTargetContext> renderTargetContext, int width, int height,
: INHERITED(make_info(drawContext.get(), width, height, SkToBool(flags & kIsOpaque_Flag)), unsigned flags)
drawContext->surfaceProps()) : INHERITED(make_info(renderTargetContext.get(), width, height,
, fContext(SkRef(drawContext->accessRenderTarget()->getContext())) SkToBool(flags & kIsOpaque_Flag)), renderTargetContext->surfaceProps())
, fDrawContext(std::move(drawContext)) , fContext(SkRef(renderTargetContext->accessRenderTarget()->getContext()))
, fRenderTargetContext(std::move(renderTargetContext))
{ {
fSize.set(width, height); fSize.set(width, height);
fOpaque = SkToBool(flags & kIsOpaque_Flag); fOpaque = SkToBool(flags & kIsOpaque_Flag);
@ -143,12 +146,13 @@ SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
} }
} }
sk_sp<GrDrawContext> SkGpuDevice::MakeDrawContext(GrContext* context, sk_sp<GrRenderTargetContext> SkGpuDevice::MakeRenderTargetContext(
SkBudgeted budgeted, GrContext* context,
const SkImageInfo& origInfo, SkBudgeted budgeted,
int sampleCount, const SkImageInfo& origInfo,
GrSurfaceOrigin origin, int sampleCount,
const SkSurfaceProps* surfaceProps) { GrSurfaceOrigin origin,
const SkSurfaceProps* surfaceProps) {
if (kUnknown_SkColorType == origInfo.colorType() || if (kUnknown_SkColorType == origInfo.colorType() ||
origInfo.width() < 0 || origInfo.height() < 0) { origInfo.width() < 0 || origInfo.height() < 0) {
return nullptr; return nullptr;
@ -170,7 +174,7 @@ sk_sp<GrDrawContext> SkGpuDevice::MakeDrawContext(GrContext* context,
GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps()); GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps());
return context->makeDrawContext(SkBackingFit::kExact, // Why exact? return context->makeRenderTargetContext(SkBackingFit::kExact, // Why exact?
origInfo.width(), origInfo.height(), origInfo.width(), origInfo.height(),
config, sk_ref_sp(cs), sampleCount, config, sk_ref_sp(cs), sampleCount,
origin, surfaceProps, budgeted); origin, surfaceProps, budgeted);
@ -188,7 +192,7 @@ sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(const SkDraw& draw,
matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-left, -top); const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-left, -top);
SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache()); SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache());
SkImageFilter::OutputProperties outputProperties(fDrawContext->getColorSpace()); SkImageFilter::OutputProperties outputProperties(fRenderTargetContext->getColorSpace());
SkImageFilter::Context ctx(matrix, clipBounds, cache.get(), outputProperties); SkImageFilter::Context ctx(matrix, clipBounds, cache.get(), outputProperties);
return filter->filterImage(srcImg, ctx, offset); return filter->filterImage(srcImg, ctx, offset);
@ -200,14 +204,14 @@ bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
int x, int y) { int x, int y) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
return fDrawContext->readPixels(dstInfo, dstPixels, dstRowBytes, x, y); return fRenderTargetContext->readPixels(dstInfo, dstPixels, dstRowBytes, x, y);
} }
bool SkGpuDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, bool SkGpuDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels,
size_t srcRowBytes, int x, int y) { size_t srcRowBytes, int x, int y) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
return fDrawContext->writePixels(srcInfo, srcPixels, srcRowBytes, x, y); return fRenderTargetContext->writePixels(srcInfo, srcPixels, srcRowBytes, x, y);
} }
bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) {
@ -223,9 +227,9 @@ void SkGpuDevice::prepareDraw(const SkDraw& draw) {
fClip.reset(draw.fClipStack, &this->getOrigin()); fClip.reset(draw.fClipStack, &this->getOrigin());
} }
GrDrawContext* SkGpuDevice::accessDrawContext() { GrRenderTargetContext* SkGpuDevice::accessRenderTargetContext() {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
return fDrawContext.get(); return fRenderTargetContext.get();
} }
void SkGpuDevice::clearAll() { void SkGpuDevice::clearAll() {
@ -233,34 +237,35 @@ void SkGpuDevice::clearAll() {
GrColor color = 0; GrColor color = 0;
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext);
SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); SkIRect rect = SkIRect::MakeWH(this->width(), this->height());
fDrawContext->clear(&rect, color, true); fRenderTargetContext->clear(&rect, color, true);
} }
void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) { void SkGpuDevice::replaceRenderTargetContext(bool shouldRetainContent) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
SkBudgeted budgeted = fDrawContext->drawContextPriv().isBudgeted(); SkBudgeted budgeted = fRenderTargetContext->renderTargetContextPriv().isBudgeted();
sk_sp<GrDrawContext> newDC(MakeDrawContext(this->context(), sk_sp<GrRenderTargetContext> newDC(MakeRenderTargetContext(
budgeted, this->context(),
this->imageInfo(), budgeted,
fDrawContext->numColorSamples(), this->imageInfo(),
fDrawContext->origin(), fRenderTargetContext->numColorSamples(),
&this->surfaceProps())); fRenderTargetContext->origin(),
&this->surfaceProps()));
if (!newDC) { if (!newDC) {
return; return;
} }
if (shouldRetainContent) { if (shouldRetainContent) {
if (fDrawContext->wasAbandoned()) { if (fRenderTargetContext->wasAbandoned()) {
return; return;
} }
newDC->copySurface(fDrawContext->asTexture().get(), newDC->copySurface(fRenderTargetContext->asTexture().get(),
SkIRect::MakeWH(this->width(), this->height()), SkIRect::MakeWH(this->width(), this->height()),
SkIPoint::Make(0, 0)); SkIPoint::Make(0, 0));
} }
fDrawContext = newDC; fRenderTargetContext = newDC;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -271,11 +276,12 @@ void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext);
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return; return;
} }
fDrawContext->drawPaint(fClip, grPaint, *draw.fMatrix); fRenderTargetContext->drawPaint(fClip, grPaint, *draw.fMatrix);
} }
// must be in SkCanvas::PointMode order // must be in SkCanvas::PointMode order
@ -321,7 +327,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) { if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
GrStyle style(paint, SkPaint::kStroke_Style); GrStyle style(paint, SkPaint::kStroke_Style);
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) { &grPaint)) {
return; return;
} }
@ -329,7 +335,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
path.setIsVolatile(true); path.setIsVolatile(true);
path.moveTo(pts[0]); path.moveTo(pts[0]);
path.lineTo(pts[1]); path.lineTo(pts[1]);
fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, style); fRenderTargetContext->drawPath(fClip, grPaint, *draw.fMatrix, path, style);
return; return;
} }
@ -361,20 +367,21 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
#endif #endif
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *viewMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *viewMatrix,
&grPaint)) {
return; return;
} }
fDrawContext->drawVertices(fClip, fRenderTargetContext->drawVertices(fClip,
grPaint, grPaint,
*viewMatrix, *viewMatrix,
primitiveType, primitiveType,
SkToS32(count), SkToS32(count),
(SkPoint*)pts, (SkPoint*)pts,
nullptr, nullptr,
nullptr, nullptr,
nullptr, nullptr,
0); 0);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -390,7 +397,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
SkPath path; SkPath path;
path.setIsVolatile(true); path.setIsVolatile(true);
path.addRect(rect); path.addRect(rect);
GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), GrBlurUtils::drawPathWithMaskFilter(fContext, fRenderTargetContext.get(),
fClip, path, paint, fClip, path, paint,
*draw.fMatrix, nullptr, *draw.fMatrix, nullptr,
draw.fRC->getBounds(), true); draw.fRC->getBounds(), true);
@ -398,12 +405,13 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
} }
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return; return;
} }
GrStyle style(paint); GrStyle style(paint);
fDrawContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &style); fRenderTargetContext->drawRect(fClip, grPaint, *draw.fMatrix, rect, &style);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -415,7 +423,8 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect,
CHECK_SHOULD_DRAW(draw); CHECK_SHOULD_DRAW(draw);
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return; return;
} }
@ -440,8 +449,8 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect,
// clipped out // clipped out
return; return;
} }
if (mf->directFilterRRectMaskGPU(fContext, fDrawContext.get(), &grPaint, fClip, if (mf->directFilterRRectMaskGPU(fContext, fRenderTargetContext.get(), &grPaint,
*draw.fMatrix, style.strokeRec(), rrect, fClip, *draw.fMatrix, style.strokeRec(), rrect,
devRRect)) { devRRect)) {
return; return;
} }
@ -458,7 +467,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect,
SkPath path; SkPath path;
path.setIsVolatile(true); path.setIsVolatile(true);
path.addRRect(rrect); path.addRRect(rrect);
GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), GrBlurUtils::drawPathWithMaskFilter(fContext, fRenderTargetContext.get(),
fClip, path, paint, fClip, path, paint,
*draw.fMatrix, nullptr, *draw.fMatrix, nullptr,
draw.fRC->getBounds(), true); draw.fRC->getBounds(), true);
@ -467,7 +476,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect,
SkASSERT(!style.pathEffect()); SkASSERT(!style.pathEffect());
fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rrect, style); fRenderTargetContext->drawRRect(fClip, grPaint, *draw.fMatrix, rrect, style);
} }
@ -489,12 +498,12 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) { if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) {
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) { &grPaint)) {
return; return;
} }
fDrawContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner); fRenderTargetContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner);
return; return;
} }
@ -504,7 +513,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
path.addRRect(inner); path.addRRect(inner);
path.setFillType(SkPath::kEvenOdd_FillType); path.setFillType(SkPath::kEvenOdd_FillType);
GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), GrBlurUtils::drawPathWithMaskFilter(fContext, fRenderTargetContext.get(),
fClip, path, paint, fClip, path, paint,
*draw.fMatrix, nullptr, *draw.fMatrix, nullptr,
draw.fRC->getBounds(), true); draw.fRC->getBounds(), true);
@ -521,11 +530,12 @@ void SkGpuDevice::drawRegion(const SkDraw& draw, const SkRegion& region, const S
} }
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return; return;
} }
fDrawContext->drawRegion(fClip, grPaint, *draw.fMatrix, region, GrStyle(paint)); fRenderTargetContext->drawRegion(fClip, grPaint, *draw.fMatrix, region, GrStyle(paint));
} }
void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) {
@ -549,11 +559,12 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
} }
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return; return;
} }
fDrawContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, GrStyle(paint)); fRenderTargetContext->drawOval(fClip, grPaint, *draw.fMatrix, oval, GrStyle(paint));
} }
void SkGpuDevice::drawArc(const SkDraw& draw, const SkRect& oval, SkScalar startAngle, void SkGpuDevice::drawArc(const SkDraw& draw, const SkRect& oval, SkScalar startAngle,
@ -567,12 +578,13 @@ void SkGpuDevice::drawArc(const SkDraw& draw, const SkRect& oval, SkScalar start
return; return;
} }
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return; return;
} }
fDrawContext->drawArc(fClip, grPaint, *draw.fMatrix, oval, startAngle, sweepAngle, useCenter, fRenderTargetContext->drawArc(fClip, grPaint, *draw.fMatrix, oval, startAngle, sweepAngle,
GrStyle(paint)); useCenter, GrStyle(paint));
} }
#include "SkMaskFilter.h" #include "SkMaskFilter.h"
@ -585,8 +597,8 @@ void SkGpuDevice::drawStrokedLine(const SkPoint points[2],
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawStrokedLine", fContext); GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawStrokedLine", fContext);
CHECK_SHOULD_DRAW(draw); CHECK_SHOULD_DRAW(draw);
// Adding support for round capping would require a GrDrawContext::fillRRectWithLocalMatrix // Adding support for round capping would require a
// entry point // GrRenderTargetContext::fillRRectWithLocalMatrix entry point
SkASSERT(SkPaint::kRound_Cap != origPaint.getStrokeCap()); SkASSERT(SkPaint::kRound_Cap != origPaint.getStrokeCap());
SkASSERT(SkPaint::kStroke_Style == origPaint.getStyle()); SkASSERT(SkPaint::kStroke_Style == origPaint.getStyle());
SkASSERT(!origPaint.getPathEffect()); SkASSERT(!origPaint.getPathEffect());
@ -624,11 +636,11 @@ void SkGpuDevice::drawStrokedLine(const SkPoint points[2],
m.postConcat(*draw.fMatrix); m.postConcat(*draw.fMatrix);
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), newPaint, m, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), newPaint, m, &grPaint)) {
return; return;
} }
fDrawContext->fillRectWithLocalMatrix(fClip, grPaint, m, rect, local); fRenderTargetContext->fillRectWithLocalMatrix(fClip, grPaint, m, rect, local);
} }
void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
@ -669,7 +681,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
CHECK_SHOULD_DRAW(draw); CHECK_SHOULD_DRAW(draw);
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext);
GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), GrBlurUtils::drawPathWithMaskFilter(fContext, fRenderTargetContext.get(),
fClip, origSrcPath, paint, fClip, origSrcPath, paint,
*draw.fMatrix, prePathMatrix, *draw.fMatrix, prePathMatrix,
draw.fRC->getBounds(), pathIsMutable); draw.fRC->getBounds(), pathIsMutable);
@ -742,8 +754,9 @@ bool SkGpuDevice::shouldTileImageID(uint32_t imageID, const SkIRect& imageRect,
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
// if it's larger than the max tile size, then we have no choice but tiling. // if it's larger than the max tile size, then we have no choice but tiling.
if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) { if (imageRect.width() > maxTileSize || imageRect.height() > maxTileSize) {
determine_clipped_src_rect(fDrawContext->width(), fDrawContext->height(), fClip, viewMatrix, determine_clipped_src_rect(fRenderTargetContext->width(), fRenderTargetContext->height(),
srcToDstRect, imageRect.size(), srcRectPtr, clippedSubset); fClip, viewMatrix, srcToDstRect, imageRect.size(), srcRectPtr,
clippedSubset);
*tileSize = determine_tile_size(*clippedSubset, maxTileSize); *tileSize = determine_tile_size(*clippedSubset, maxTileSize);
return true; return true;
} }
@ -770,8 +783,9 @@ bool SkGpuDevice::shouldTileImageID(uint32_t imageID, const SkIRect& imageRect,
// Figure out how much of the src we will need based on the src rect and clipping. Reject if // Figure out how much of the src we will need based on the src rect and clipping. Reject if
// tiling memory savings would be < 50%. // tiling memory savings would be < 50%.
determine_clipped_src_rect(fDrawContext->width(), fDrawContext->height(), fClip, viewMatrix, determine_clipped_src_rect(fRenderTargetContext->width(), fRenderTargetContext->height(), fClip,
srcToDstRect, imageRect.size(), srcRectPtr, clippedSubset); viewMatrix, srcToDstRect, imageRect.size(), srcRectPtr,
clippedSubset);
*tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile. *tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile.
size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) * size_t usedTileBytes = get_tile_count(*clippedSubset, kBmpSmallTileSize) *
kBmpSmallTileSize * kBmpSmallTileSize; kBmpSmallTileSize * kBmpSmallTileSize;
@ -828,7 +842,7 @@ void SkGpuDevice::drawBitmap(const SkDraw& origDraw,
// The tile code path doesn't currently support AA, so if the paint asked for aa and we could // The tile code path doesn't currently support AA, so if the paint asked for aa and we could
// draw untiled, then we bypass checking for tiling purely for optimization reasons. // draw untiled, then we bypass checking for tiling purely for optimization reasons.
bool drawAA = !fDrawContext->isUnifiedMultisampled() && bool drawAA = !fRenderTargetContext->isUnifiedMultisampled() &&
paint.isAntiAlias() && paint.isAntiAlias() &&
bitmap.width() <= maxTileSize && bitmap.width() <= maxTileSize &&
bitmap.height() <= maxTileSize; bitmap.height() <= maxTileSize;
@ -931,7 +945,7 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
const SkPaint* paint = &origPaint; const SkPaint* paint = &origPaint;
SkPaint tempPaint; SkPaint tempPaint;
if (origPaint.isAntiAlias() && !fDrawContext->isUnifiedMultisampled()) { if (origPaint.isAntiAlias() && !fRenderTargetContext->isUnifiedMultisampled()) {
// Drop antialiasing to avoid seams at tile boundaries. // Drop antialiasing to avoid seams at tile boundaries.
tempPaint = origPaint; tempPaint = origPaint;
tempPaint.setAntiAlias(false); tempPaint.setAntiAlias(false);
@ -1018,13 +1032,13 @@ void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap,
SkASSERT(bitmap.width() <= fContext->caps()->maxTileSize() && SkASSERT(bitmap.width() <= fContext->caps()->maxTileSize() &&
bitmap.height() <= fContext->caps()->maxTileSize()); bitmap.height() <= fContext->caps()->maxTileSize());
sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext, bitmap, params, sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(
fDrawContext->sourceGammaTreatment()); fContext, bitmap, params, fRenderTargetContext->sourceGammaTreatment());
if (nullptr == texture) { if (nullptr == texture) {
return; return;
} }
sk_sp<GrColorSpaceXform> colorSpaceXform = sk_sp<GrColorSpaceXform> colorSpaceXform =
GrColorSpaceXform::Make(bitmap.colorSpace(), fDrawContext->getColorSpace()); GrColorSpaceXform::Make(bitmap.colorSpace(), fRenderTargetContext->getColorSpace());
SkScalar iw = 1.f / texture->width(); SkScalar iw = 1.f / texture->width();
SkScalar ih = 1.f / texture->height(); SkScalar ih = 1.f / texture->height();
@ -1070,13 +1084,13 @@ void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap,
} }
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, viewMatrix, if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint, viewMatrix,
std::move(fp), kAlpha_8_SkColorType == bitmap.colorType(), std::move(fp), kAlpha_8_SkColorType == bitmap.colorType(),
&grPaint)) { &grPaint)) {
return; return;
} }
fDrawContext->drawRect(fClip, grPaint, viewMatrix, dstRect); fRenderTargetContext->drawRect(fClip, grPaint, viewMatrix, dstRect);
} }
void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
@ -1149,7 +1163,7 @@ void SkGpuDevice::drawSpecial(const SkDraw& draw,
tmpUnfiltered.setImageFilter(nullptr); tmpUnfiltered.setImageFilter(nullptr);
sk_sp<GrColorSpaceXform> colorSpaceXform = sk_sp<GrColorSpaceXform> colorSpaceXform =
GrColorSpaceXform::Make(result->getColorSpace(), fDrawContext->getColorSpace()); GrColorSpaceXform::Make(result->getColorSpace(), fRenderTargetContext->getColorSpace());
GrPaint grPaint; GrPaint grPaint;
sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(),
std::move(colorSpaceXform), std::move(colorSpaceXform),
@ -1159,22 +1173,25 @@ void SkGpuDevice::drawSpecial(const SkDraw& draw,
} else { } else {
fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp));
} }
if (!SkPaintToGrPaintReplaceShader(this->context(), fDrawContext.get(), tmpUnfiltered, if (!SkPaintToGrPaintReplaceShader(this->context(), fRenderTargetContext.get(), tmpUnfiltered,
std::move(fp), &grPaint)) { std::move(fp), &grPaint)) {
return; return;
} }
const SkIRect& subset = result->subset(); const SkIRect& subset = result->subset();
fDrawContext->fillRectToRect(fClip, fRenderTargetContext->fillRectToRect(fClip,
grPaint, grPaint,
SkMatrix::I(), SkMatrix::I(),
SkRect::Make(SkIRect::MakeXYWH(left + offset.fX, top + offset.fY, SkRect::Make(SkIRect::MakeXYWH(left + offset.fX,
subset.width(), subset.height())), top + offset.fY,
SkRect::MakeXYWH(SkIntToScalar(subset.fLeft) / texture->width(), subset.width(),
SkIntToScalar(subset.fTop) / texture->height(), subset.height())),
SkIntToScalar(subset.width()) / texture->width(), SkRect::MakeXYWH(
SkIntToScalar(subset.height()) / texture->height())); SkIntToScalar(subset.fLeft) / texture->width(),
SkIntToScalar(subset.fTop) / texture->height(),
SkIntToScalar(subset.width()) / texture->width(),
SkIntToScalar(subset.height()) / texture->height()));
} }
void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
@ -1215,7 +1232,7 @@ void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
// The tile code path doesn't currently support AA, so if the paint asked for aa and we could // The tile code path doesn't currently support AA, so if the paint asked for aa and we could
// draw untiled, then we bypass checking for tiling purely for optimization reasons. // draw untiled, then we bypass checking for tiling purely for optimization reasons.
bool drawAA = !fDrawContext->isUnifiedMultisampled() && bool drawAA = !fRenderTargetContext->isUnifiedMultisampled() &&
paint.isAntiAlias() && paint.isAntiAlias() &&
bitmap.width() <= maxTileSize && bitmap.width() <= maxTileSize &&
bitmap.height() <= maxTileSize; bitmap.height() <= maxTileSize;
@ -1297,18 +1314,19 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) {
} }
sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() { sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() {
sk_sp<GrTexture> texture(this->accessDrawContext()->asTexture()); sk_sp<GrTexture> texture(this->accessRenderTargetContext()->asTexture());
if (!texture) { if (!texture) {
// When the device doesn't have a texture, we create a temporary texture. // When the device doesn't have a texture, we create a temporary texture.
// TODO: we should actually only copy the portion of the source needed to apply the image // TODO: we should actually only copy the portion of the source needed to apply the image
// filter // filter
texture.reset(fContext->textureProvider()->createTexture(this->accessDrawContext()->desc(), texture.reset(fContext->textureProvider()->createTexture(
SkBudgeted::kYes)); this->accessRenderTargetContext()->desc(), SkBudgeted::kYes));
if (!texture) { if (!texture) {
return nullptr; return nullptr;
} }
if (!fContext->copySurface(texture.get(), this->accessDrawContext()->accessRenderTarget())){ if (!fContext->copySurface(texture.get(),
this->accessRenderTargetContext()->accessRenderTarget())) {
return nullptr; return nullptr;
} }
} }
@ -1415,7 +1433,7 @@ void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
CHECK_SHOULD_DRAW(draw); CHECK_SHOULD_DRAW(draw);
bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() || bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() ||
fDrawContext->isUnifiedMultisampled(); fRenderTargetContext->isUnifiedMultisampled();
bool doBicubic; bool doBicubic;
GrTextureParams::FilterMode textureFilterMode = GrTextureParams::FilterMode textureFilterMode =
GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix, SkMatrix::I(), GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix, SkMatrix::I(),
@ -1436,18 +1454,19 @@ void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
producer->createFragmentProcessor(SkMatrix::I(), producer->createFragmentProcessor(SkMatrix::I(),
SkRect::MakeIWH(producer->width(), producer->height()), SkRect::MakeIWH(producer->width(), producer->height()),
GrTextureProducer::kNo_FilterConstraint, true, GrTextureProducer::kNo_FilterConstraint, true,
&kMode, fDrawContext->getColorSpace(), &kMode, fRenderTargetContext->getColorSpace(),
fDrawContext->sourceGammaTreatment())); fRenderTargetContext->sourceGammaTreatment()));
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, *draw.fMatrix, if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint,
std::move(fp), producer->isAlphaOnly(), &grPaint)) { *draw.fMatrix, std::move(fp), producer->isAlphaOnly(),
&grPaint)) {
return; return;
} }
std::unique_ptr<SkLatticeIter> iter( std::unique_ptr<SkLatticeIter> iter(
new SkLatticeIter(producer->width(), producer->height(), center, dst)); new SkLatticeIter(producer->width(), producer->height(), center, dst));
fDrawContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->width(), fRenderTargetContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->width(),
producer->height(), std::move(iter), dst); producer->height(), std::move(iter), dst);
} }
void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image,
@ -1489,18 +1508,19 @@ void SkGpuDevice::drawProducerLattice(const SkDraw& draw, GrTextureProducer* pro
producer->createFragmentProcessor(SkMatrix::I(), producer->createFragmentProcessor(SkMatrix::I(),
SkRect::MakeIWH(producer->width(), producer->height()), SkRect::MakeIWH(producer->width(), producer->height()),
GrTextureProducer::kNo_FilterConstraint, true, GrTextureProducer::kNo_FilterConstraint, true,
&kMode, fDrawContext->getColorSpace(), &kMode, fRenderTargetContext->getColorSpace(),
fDrawContext->sourceGammaTreatment())); fRenderTargetContext->sourceGammaTreatment()));
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, *draw.fMatrix, if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint,
std::move(fp), producer->isAlphaOnly(), &grPaint)) { *draw.fMatrix, std::move(fp), producer->isAlphaOnly(),
&grPaint)) {
return; return;
} }
std::unique_ptr<SkLatticeIter> iter( std::unique_ptr<SkLatticeIter> iter(
new SkLatticeIter(lattice, dst)); new SkLatticeIter(lattice, dst));
fDrawContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->width(), fRenderTargetContext->drawImageLattice(fClip, grPaint, *draw.fMatrix, producer->width(),
producer->height(), std::move(iter), dst); producer->height(), std::move(iter), dst);
} }
void SkGpuDevice::drawImageLattice(const SkDraw& draw, const SkImage* image, void SkGpuDevice::drawImageLattice(const SkDraw& draw, const SkImage* image,
@ -1562,7 +1582,8 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
GrPaint grPaint; GrPaint grPaint;
// we ignore the shader if texs is null. // we ignore the shader if texs is null.
if (!SkPaintToGrPaintNoShader(this->context(), fDrawContext.get(), copy, &grPaint)) { if (!SkPaintToGrPaintNoShader(this->context(), fRenderTargetContext.get(), copy,
&grPaint)) {
return; return;
} }
@ -1595,16 +1616,16 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
lineIndices[i + 5] = state.f0; lineIndices[i + 5] = state.f0;
i += 6; i += 6;
} }
fDrawContext->drawVertices(fClip, fRenderTargetContext->drawVertices(fClip,
grPaint, grPaint,
*draw.fMatrix, *draw.fMatrix,
kLines_GrPrimitiveType, kLines_GrPrimitiveType,
vertexCount, vertexCount,
vertices, vertices,
texs, texs,
colors, colors,
lineIndices.get(), lineIndices.get(),
indexCount); indexCount);
return; return;
} }
@ -1633,13 +1654,13 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
} else { } else {
colorMode = SkXfermode::kModulate_Mode; colorMode = SkXfermode::kModulate_Mode;
} }
if (!SkPaintToGrPaintWithXfermode(this->context(), fDrawContext.get(), paint, if (!SkPaintToGrPaintWithXfermode(this->context(), fRenderTargetContext.get(), paint,
*draw.fMatrix, colorMode, false, &grPaint)) { *draw.fMatrix, colorMode, false, &grPaint)) {
return; return;
} }
} else { } else {
// We have a shader, but no colors to blend it against. // We have a shader, but no colors to blend it against.
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) { &grPaint)) {
return; return;
} }
@ -1648,28 +1669,29 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
if (colors) { if (colors) {
// We have colors, but either have no shader or no texture coords (which implies that // We have colors, but either have no shader or no texture coords (which implies that
// we should ignore the shader). // we should ignore the shader).
if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), fDrawContext.get(), paint, if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), fRenderTargetContext.get(),
&grPaint)) { paint, &grPaint)) {
return; return;
} }
} else { } else {
// No colors and no shaders. Just draw with the paint color. // No colors and no shaders. Just draw with the paint color.
if (!SkPaintToGrPaintNoShader(this->context(), fDrawContext.get(), paint, &grPaint)) { if (!SkPaintToGrPaintNoShader(this->context(), fRenderTargetContext.get(), paint,
&grPaint)) {
return; return;
} }
} }
} }
fDrawContext->drawVertices(fClip, fRenderTargetContext->drawVertices(fClip,
grPaint, grPaint,
*draw.fMatrix, *draw.fMatrix,
primType, primType,
vertexCount, vertexCount,
vertices, vertices,
texs, texs,
colors, colors,
indices, indices,
indexCount); indexCount);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -1691,18 +1713,19 @@ void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS
GrPaint grPaint; GrPaint grPaint;
if (colors) { if (colors) {
if (!SkPaintToGrPaintWithXfermode(this->context(), fDrawContext.get(), p, *draw.fMatrix, if (!SkPaintToGrPaintWithXfermode(this->context(), fRenderTargetContext.get(), p,
mode, true, &grPaint)) { *draw.fMatrix, mode, true, &grPaint)) {
return; return;
} }
} else { } else {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), p, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), p, *draw.fMatrix,
&grPaint)) {
return; return;
} }
} }
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
fDrawContext->drawAtlas(fClip, grPaint, *draw.fMatrix, count, xform, texRect, colors); fRenderTargetContext->drawAtlas(fClip, grPaint, *draw.fMatrix, count, xform, texRect, colors);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -1715,14 +1738,15 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext); GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext);
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return; return;
} }
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
fDrawContext->drawText(fClip, grPaint, paint, *draw.fMatrix, fRenderTargetContext->drawText(fClip, grPaint, paint, *draw.fMatrix,
(const char *)text, byteLength, x, y, draw.fRC->getBounds()); (const char *)text, byteLength, x, y, draw.fRC->getBounds());
} }
void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength, void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength,
@ -1733,15 +1757,16 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
CHECK_SHOULD_DRAW(draw); CHECK_SHOULD_DRAW(draw);
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) { if (!SkPaintToGrPaint(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return; return;
} }
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
fDrawContext->drawPosText(fClip, grPaint, paint, *draw.fMatrix, fRenderTargetContext->drawPosText(fClip, grPaint, paint, *draw.fMatrix,
(const char *)text, byteLength, pos, scalarsPerPos, offset, (const char *)text, byteLength, pos, scalarsPerPos, offset,
draw.fRC->getBounds()); draw.fRC->getBounds());
} }
void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y, void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y,
@ -1752,8 +1777,8 @@ void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
fDrawContext->drawTextBlob(fClip, paint, *draw.fMatrix, fRenderTargetContext->drawTextBlob(fClip, paint, *draw.fMatrix,
blob, x, y, drawFilter, draw.fRC->getBounds()); blob, x, y, drawFilter, draw.fRC->getBounds());
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -1765,7 +1790,7 @@ bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const {
void SkGpuDevice::flush() { void SkGpuDevice::flush() {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
fDrawContext->prepareForExternalIO(); fRenderTargetContext->prepareForExternalIO();
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -1780,21 +1805,22 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
SkBackingFit fit = kNever_TileUsage == cinfo.fTileUsage ? SkBackingFit::kApprox SkBackingFit fit = kNever_TileUsage == cinfo.fTileUsage ? SkBackingFit::kApprox
: SkBackingFit::kExact; : SkBackingFit::kExact;
sk_sp<GrDrawContext> dc(fContext->makeDrawContext(fit, sk_sp<GrRenderTargetContext> rtc(fContext->makeRenderTargetContext(
cinfo.fInfo.width(), cinfo.fInfo.height(), fit,
fDrawContext->config(), cinfo.fInfo.width(), cinfo.fInfo.height(),
sk_ref_sp(fDrawContext->getColorSpace()), fRenderTargetContext->config(),
fDrawContext->desc().fSampleCnt, sk_ref_sp(fRenderTargetContext->getColorSpace()),
kDefault_GrSurfaceOrigin, fRenderTargetContext->desc().fSampleCnt,
&props)); kDefault_GrSurfaceOrigin,
if (!dc) { &props));
if (!rtc) {
return nullptr; return nullptr;
} }
// Skia's convention is to only clear a device if it is non-opaque. // Skia's convention is to only clear a device if it is non-opaque.
InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_InitContents; InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_InitContents;
return SkGpuDevice::Make(std::move(dc), return SkGpuDevice::Make(std::move(rtc),
cinfo.fInfo.width(), cinfo.fInfo.height(), cinfo.fInfo.width(), cinfo.fInfo.height(),
init).release(); init).release();
} }
@ -1803,8 +1829,9 @@ sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
// TODO: Change the signature of newSurface to take a budgeted parameter. // TODO: Change the signature of newSurface to take a budgeted parameter.
static const SkBudgeted kBudgeted = SkBudgeted::kNo; static const SkBudgeted kBudgeted = SkBudgeted::kNo;
return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->desc().fSampleCnt, return SkSurface::MakeRenderTarget(fContext, kBudgeted, info,
fDrawContext->origin(), &props); fRenderTargetContext->desc().fSampleCnt,
fRenderTargetContext->origin(), &props);
} }
SkImageFilterCache* SkGpuDevice::getImageFilterCache() { SkImageFilterCache* SkGpuDevice::getImageFilterCache() {

View File

@ -16,7 +16,7 @@
#include "SkRegion.h" #include "SkRegion.h"
#include "SkSurface.h" #include "SkSurface.h"
#include "GrClipStackClip.h" #include "GrClipStackClip.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrSurfacePriv.h" #include "GrSurfacePriv.h"
#include "GrTypes.h" #include "GrTypes.h"
@ -39,10 +39,10 @@ public:
}; };
/** /**
* Creates an SkGpuDevice from a GrDrawContext whose backing width/height is * Creates an SkGpuDevice from a GrRenderTargetContext whose backing width/height is
* different than its actual width/height (e.g., approx-match scratch texture). * different than its actual width/height (e.g., approx-match scratch texture).
*/ */
static sk_sp<SkGpuDevice> Make(sk_sp<GrDrawContext> drawContext, static sk_sp<SkGpuDevice> Make(sk_sp<GrRenderTargetContext> renderTargetContext,
int width, int height, int width, int height,
InitContents); InitContents);
@ -62,9 +62,9 @@ public:
// set all pixels to 0 // set all pixels to 0
void clearAll(); void clearAll();
void replaceDrawContext(bool shouldRetainContent); void replaceRenderTargetContext(bool shouldRetainContent);
GrDrawContext* accessDrawContext() override; GrRenderTargetContext* accessRenderTargetContext() override;
void drawPaint(const SkDraw&, const SkPaint& paint) override; void drawPaint(const SkDraw&, const SkPaint& paint) override;
void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, const SkPoint[], void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, const SkPoint[],
@ -131,9 +131,9 @@ protected:
bool onShouldDisableLCD(const SkPaint&) const final; bool onShouldDisableLCD(const SkPaint&) const final;
private: private:
// We want these unreffed in DrawContext, GrContext order. // We want these unreffed in RenderTargetContext, GrContext order.
SkAutoTUnref<GrContext> fContext; SkAutoTUnref<GrContext> fContext;
sk_sp<GrDrawContext> fDrawContext; sk_sp<GrRenderTargetContext> fRenderTargetContext;
SkIPoint fClipOrigin; SkIPoint fClipOrigin;
GrClipStackClip fClip; GrClipStackClip fClip;
@ -148,7 +148,7 @@ private:
static bool CheckAlphaTypeAndGetFlags(const SkImageInfo* info, InitContents init, static bool CheckAlphaTypeAndGetFlags(const SkImageInfo* info, InitContents init,
unsigned* flags); unsigned* flags);
SkGpuDevice(sk_sp<GrDrawContext>, int width, int height, unsigned flags); SkGpuDevice(sk_sp<GrRenderTargetContext>, int width, int height, unsigned flags);
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
@ -239,12 +239,12 @@ private:
bool drawDashLine(const SkPoint pts[2], const SkPaint& paint); bool drawDashLine(const SkPoint pts[2], const SkPaint& paint);
void drawStrokedLine(const SkPoint pts[2], const SkDraw&, const SkPaint&); void drawStrokedLine(const SkPoint pts[2], const SkDraw&, const SkPaint&);
static sk_sp<GrDrawContext> MakeDrawContext(GrContext*, static sk_sp<GrRenderTargetContext> MakeRenderTargetContext(GrContext*,
SkBudgeted, SkBudgeted,
const SkImageInfo&, const SkImageInfo&,
int sampleCount, int sampleCount,
GrSurfaceOrigin, GrSurfaceOrigin,
const SkSurfaceProps*); const SkSurfaceProps*);
friend class GrAtlasTextContext; friend class GrAtlasTextContext;
friend class SkSurface_Gpu; // for access to surfaceProps friend class SkSurface_Gpu; // for access to surfaceProps

View File

@ -9,7 +9,7 @@
#include "GrBlurUtils.h" #include "GrBlurUtils.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrStyle.h" #include "GrStyle.h"
#include "GrTextureParamsAdjuster.h" #include "GrTextureParamsAdjuster.h"
#include "SkDraw.h" #include "SkDraw.h"
@ -186,7 +186,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
SkMatrix combinedMatrix; SkMatrix combinedMatrix;
combinedMatrix.setConcat(viewMatrix, srcToDstMatrix); combinedMatrix.setConcat(viewMatrix, srcToDstMatrix);
if (can_ignore_bilerp_constraint(*producer, clippedSrcRect, combinedMatrix, if (can_ignore_bilerp_constraint(*producer, clippedSrcRect, combinedMatrix,
fDrawContext->isUnifiedMultisampled())) { fRenderTargetContext->isUnifiedMultisampled())) {
constraintMode = GrTextureAdjuster::kNo_FilterConstraint; constraintMode = GrTextureAdjuster::kNo_FilterConstraint;
} }
} }
@ -203,24 +203,25 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
} }
sk_sp<GrFragmentProcessor> fp(producer->createFragmentProcessor( sk_sp<GrFragmentProcessor> fp(producer->createFragmentProcessor(
*textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode, *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode,
fDrawContext->getColorSpace(), fDrawContext->sourceGammaTreatment())); fRenderTargetContext->getColorSpace(), fRenderTargetContext->sourceGammaTreatment()));
if (!fp) { if (!fp) {
return; return;
} }
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(fContext, fDrawContext.get(), paint, viewMatrix, fp, if (!SkPaintToGrPaintWithTexture(fContext, fRenderTargetContext.get(), paint, viewMatrix, fp,
producer->isAlphaOnly(), &grPaint)) { producer->isAlphaOnly(), &grPaint)) {
return; return;
} }
if (canUseTextureCoordsAsLocalCoords) { if (canUseTextureCoordsAsLocalCoords) {
fDrawContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect, clippedSrcRect); fRenderTargetContext->fillRectToRect(clip, grPaint, viewMatrix, clippedDstRect,
clippedSrcRect);
return; return;
} }
if (!mf) { if (!mf) {
fDrawContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect); fRenderTargetContext->drawRect(clip, grPaint, viewMatrix, clippedDstRect);
return; return;
} }
@ -231,7 +232,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
if (mf->directFilterRRectMaskGPU(fContext, if (mf->directFilterRRectMaskGPU(fContext,
fDrawContext.get(), fRenderTargetContext.get(),
&grPaint, &grPaint,
clip, clip,
viewMatrix, viewMatrix,
@ -245,7 +246,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
SkPath rectPath; SkPath rectPath;
rectPath.addRect(clippedDstRect); rectPath.addRect(clippedDstRect);
rectPath.setIsVolatile(true); rectPath.setIsVolatile(true);
GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext.get(), fClip, GrBlurUtils::drawPathWithMaskFilter(this->context(), fRenderTargetContext.get(), fClip,
rectPath, &grPaint, viewMatrix, mf, GrStyle::SimpleFill(), rectPath, &grPaint, viewMatrix, mf, GrStyle::SimpleFill(),
true); true);
} }

View File

@ -11,7 +11,7 @@
#include "GrCaps.h" #include "GrCaps.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrGpuResourcePriv.h" #include "GrGpuResourcePriv.h"
#include "GrImageIDTextureAdjuster.h" #include "GrImageIDTextureAdjuster.h"
#include "GrTextureParamsAdjuster.h" #include "GrTextureParamsAdjuster.h"
@ -575,7 +575,7 @@ static inline bool blend_requires_shader(const SkXfermode::Mode mode, bool primi
} }
static inline bool skpaint_to_grpaint_impl(GrContext* context, static inline bool skpaint_to_grpaint_impl(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewM, const SkMatrix& viewM,
sk_sp<GrFragmentProcessor>* shaderProcessor, sk_sp<GrFragmentProcessor>* shaderProcessor,
@ -583,11 +583,11 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
bool primitiveIsSrc, bool primitiveIsSrc,
GrPaint* grPaint) { GrPaint* grPaint) {
grPaint->setAntiAlias(skPaint.isAntiAlias()); grPaint->setAntiAlias(skPaint.isAntiAlias());
grPaint->setAllowSRGBInputs(dc->isGammaCorrect()); grPaint->setAllowSRGBInputs(rtc->isGammaCorrect());
// Convert SkPaint color to 4f format, including optional linearizing and gamut conversion. // Convert SkPaint color to 4f format, including optional linearizing and gamut conversion.
GrColor4f origColor = SkColorToUnpremulGrColor4f(skPaint.getColor(), dc->isGammaCorrect(), GrColor4f origColor = SkColorToUnpremulGrColor4f(skPaint.getColor(), rtc->isGammaCorrect(),
dc->getColorXformFromSRGB()); rtc->getColorXformFromSRGB());
// Setup the initial color considering the shader, the SkPaint color, and the presence or not // Setup the initial color considering the shader, the SkPaint color, and the presence or not
// of per-vertex colors. // of per-vertex colors.
@ -598,8 +598,8 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
} else if (const SkShader* shader = skPaint.getShader()) { } else if (const SkShader* shader = skPaint.getShader()) {
shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, &viewM, nullptr, shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, &viewM, nullptr,
skPaint.getFilterQuality(), skPaint.getFilterQuality(),
dc->getColorSpace(), rtc->getColorSpace(),
dc->sourceGammaTreatment())); rtc->sourceGammaTreatment()));
if (!shaderFP) { if (!shaderFP) {
return false; return false;
} }
@ -688,7 +688,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
if (applyColorFilterToPaintColor) { if (applyColorFilterToPaintColor) {
// If we're in legacy mode, we *must* avoid using the 4f version of the color filter, // If we're in legacy mode, we *must* avoid using the 4f version of the color filter,
// because that will combine with the linearized version of the stored color. // because that will combine with the linearized version of the stored color.
if (dc->isGammaCorrect()) { if (rtc->isGammaCorrect()) {
grPaint->setColor4f(GrColor4f::FromSkColor4f( grPaint->setColor4f(GrColor4f::FromSkColor4f(
colorFilter->filterColor4f(origColor.toSkColor4f())).premul()); colorFilter->filterColor4f(origColor.toSkColor4f())).premul());
} else { } else {
@ -697,7 +697,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
} }
} else { } else {
sk_sp<GrFragmentProcessor> cfFP(colorFilter->asFragmentProcessor(context, sk_sp<GrFragmentProcessor> cfFP(colorFilter->asFragmentProcessor(context,
dc->getColorSpace())); rtc->getColorSpace()));
if (cfFP) { if (cfFP) {
grPaint->addColorFragmentProcessor(std::move(cfFP)); grPaint->addColorFragmentProcessor(std::move(cfFP));
} else { } else {
@ -722,58 +722,58 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
} }
#ifndef SK_IGNORE_GPU_DITHER #ifndef SK_IGNORE_GPU_DITHER
if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !dc->isGammaCorrect()) { if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !rtc->isGammaCorrect()) {
grPaint->addColorFragmentProcessor(GrDitherEffect::Make()); grPaint->addColorFragmentProcessor(GrDitherEffect::Make());
} }
#endif #endif
return true; return true;
} }
bool SkPaintToGrPaint(GrContext* context, GrDrawContext* dc, const SkPaint& skPaint, bool SkPaintToGrPaint(GrContext* context, GrRenderTargetContext* rtc, const SkPaint& skPaint,
const SkMatrix& viewM, GrPaint* grPaint) { const SkMatrix& viewM, GrPaint* grPaint) {
return skpaint_to_grpaint_impl(context, dc, skPaint, viewM, nullptr, nullptr, false, grPaint); return skpaint_to_grpaint_impl(context, rtc, skPaint, viewM, nullptr, nullptr, false, grPaint);
} }
/** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. */ /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. */
bool SkPaintToGrPaintReplaceShader(GrContext* context, bool SkPaintToGrPaintReplaceShader(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkPaint& skPaint, const SkPaint& skPaint,
sk_sp<GrFragmentProcessor> shaderFP, sk_sp<GrFragmentProcessor> shaderFP,
GrPaint* grPaint) { GrPaint* grPaint) {
if (!shaderFP) { if (!shaderFP) {
return false; return false;
} }
return skpaint_to_grpaint_impl(context, dc, skPaint, SkMatrix::I(), &shaderFP, nullptr, false, return skpaint_to_grpaint_impl(context, rtc, skPaint, SkMatrix::I(), &shaderFP, nullptr, false,
grPaint); grPaint);
} }
/** Ignores the SkShader (if any) on skPaint. */ /** Ignores the SkShader (if any) on skPaint. */
bool SkPaintToGrPaintNoShader(GrContext* context, bool SkPaintToGrPaintNoShader(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkPaint& skPaint, const SkPaint& skPaint,
GrPaint* grPaint) { GrPaint* grPaint) {
// Use a ptr to a nullptr to to indicate that the SkShader is ignored and not replaced. // Use a ptr to a nullptr to to indicate that the SkShader is ignored and not replaced.
static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr); static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr);
static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP; static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP;
return skpaint_to_grpaint_impl(context, dc, skPaint, SkMatrix::I(), kIgnoreShader, nullptr, return skpaint_to_grpaint_impl(context, rtc, skPaint, SkMatrix::I(), kIgnoreShader, nullptr,
false, grPaint); false, grPaint);
} }
/** Blends the SkPaint's shader (or color if no shader) with a per-primitive color which must /** Blends the SkPaint's shader (or color if no shader) with a per-primitive color which must
be setup as a vertex attribute using the specified SkXfermode::Mode. */ be setup as a vertex attribute using the specified SkXfermode::Mode. */
bool SkPaintToGrPaintWithXfermode(GrContext* context, bool SkPaintToGrPaintWithXfermode(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewM, const SkMatrix& viewM,
SkXfermode::Mode primColorMode, SkXfermode::Mode primColorMode,
bool primitiveIsSrc, bool primitiveIsSrc,
GrPaint* grPaint) { GrPaint* grPaint) {
return skpaint_to_grpaint_impl(context, dc, skPaint, viewM, nullptr, &primColorMode, return skpaint_to_grpaint_impl(context, rtc, skPaint, viewM, nullptr, &primColorMode,
primitiveIsSrc, grPaint); primitiveIsSrc, grPaint);
} }
bool SkPaintToGrPaintWithTexture(GrContext* context, bool SkPaintToGrPaintWithTexture(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkPaint& paint, const SkPaint& paint,
const SkMatrix& viewM, const SkMatrix& viewM,
sk_sp<GrFragmentProcessor> fp, sk_sp<GrFragmentProcessor> fp,
@ -786,8 +786,8 @@ bool SkPaintToGrPaintWithTexture(GrContext* context,
&viewM, &viewM,
nullptr, nullptr,
paint.getFilterQuality(), paint.getFilterQuality(),
dc->getColorSpace(), rtc->getColorSpace(),
dc->sourceGammaTreatment())); rtc->sourceGammaTreatment()));
if (!shaderFP) { if (!shaderFP) {
return false; return false;
} }
@ -800,7 +800,7 @@ bool SkPaintToGrPaintWithTexture(GrContext* context,
shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp); shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp);
} }
return SkPaintToGrPaintReplaceShader(context, dc, paint, std::move(shaderFP), grPaint); return SkPaintToGrPaintReplaceShader(context, rtc, paint, std::move(shaderFP), grPaint);
} }

View File

@ -16,7 +16,7 @@
class GrCaps; class GrCaps;
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
class GrFragmentProcessor; class GrFragmentProcessor;
class GrPaint; class GrPaint;
class GrTexture; class GrTexture;
@ -47,14 +47,14 @@ void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix
/** Converts an SkPaint to a GrPaint for a given GrContext. The matrix is required in order /** Converts an SkPaint to a GrPaint for a given GrContext. The matrix is required in order
to convert the SkShader (if any) on the SkPaint. The primitive itself has no color. */ to convert the SkShader (if any) on the SkPaint. The primitive itself has no color. */
bool SkPaintToGrPaint(GrContext*, bool SkPaintToGrPaint(GrContext*,
GrDrawContext*, GrRenderTargetContext*,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewM, const SkMatrix& viewM,
GrPaint* grPaint); GrPaint* grPaint);
/** Same as above but ignores the SkShader (if any) on skPaint. */ /** Same as above but ignores the SkShader (if any) on skPaint. */
bool SkPaintToGrPaintNoShader(GrContext* context, bool SkPaintToGrPaintNoShader(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkPaint& skPaint, const SkPaint& skPaint,
GrPaint* grPaint); GrPaint* grPaint);
@ -62,7 +62,7 @@ bool SkPaintToGrPaintNoShader(GrContext* context,
should expect an unpremul input color and produce a premultiplied output color. There is should expect an unpremul input color and produce a premultiplied output color. There is
no primitive color. */ no primitive color. */
bool SkPaintToGrPaintReplaceShader(GrContext*, bool SkPaintToGrPaintReplaceShader(GrContext*,
GrDrawContext*, GrRenderTargetContext*,
const SkPaint& skPaint, const SkPaint& skPaint,
sk_sp<GrFragmentProcessor> shaderFP, sk_sp<GrFragmentProcessor> shaderFP,
GrPaint* grPaint); GrPaint* grPaint);
@ -72,7 +72,7 @@ bool SkPaintToGrPaintReplaceShader(GrContext*,
primitive color is the dst or src color to the blend in order to work around differences between primitive color is the dst or src color to the blend in order to work around differences between
drawVertices and drawAtlas. */ drawVertices and drawAtlas. */
bool SkPaintToGrPaintWithXfermode(GrContext* context, bool SkPaintToGrPaintWithXfermode(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewM, const SkMatrix& viewM,
SkXfermode::Mode primColorMode, SkXfermode::Mode primColorMode,
@ -83,16 +83,16 @@ bool SkPaintToGrPaintWithXfermode(GrContext* context,
the expectation is that the primitive color will be premultiplied, though it really should be the expectation is that the primitive color will be premultiplied, though it really should be
unpremultiplied so that interpolation is done in unpremul space. The paint's alpha will be unpremultiplied so that interpolation is done in unpremul space. The paint's alpha will be
applied to the primitive color after interpolation. */ applied to the primitive color after interpolation. */
inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, GrDrawContext* dc, inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, GrRenderTargetContext* rtc,
const SkPaint& skPaint, GrPaint* grPaint) { const SkPaint& skPaint, GrPaint* grPaint) {
return SkPaintToGrPaintWithXfermode(context, dc, skPaint, SkMatrix::I(), SkXfermode::kDst_Mode, return SkPaintToGrPaintWithXfermode(context, rtc, skPaint, SkMatrix::I(), SkXfermode::kDst_Mode,
false, grPaint); false, grPaint);
} }
/** This is used when there may or may not be a shader, and the caller wants to plugin a texture /** This is used when there may or may not be a shader, and the caller wants to plugin a texture
lookup. If there is a shader, then its output will only be used if the texture is alpha8. */ lookup. If there is a shader, then its output will only be used if the texture is alpha8. */
bool SkPaintToGrPaintWithTexture(GrContext* context, bool SkPaintToGrPaintWithTexture(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkPaint& paint, const SkPaint& paint,
const SkMatrix& viewM, const SkMatrix& viewM,
sk_sp<GrFragmentProcessor> fp, sk_sp<GrFragmentProcessor> fp,
@ -105,9 +105,10 @@ GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&, const GrCaps&);
bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*); bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*);
/** When image filter code needs to construct a draw context to do intermediate rendering, we need /** When image filter code needs to construct a render target context to do intermediate rendering,
a renderable pixel config. The source (SkSpecialImage) may not be in a renderable format, but we need a renderable pixel config. The source (SkSpecialImage) may not be in a renderable
we want to preserve the color space of that source. This picks an appropriate format to use. */ format, but we want to preserve the color space of that source. This picks an appropriate format
to use. */
GrPixelConfig GrRenderableConfigForColorSpace(const SkColorSpace*); GrPixelConfig GrRenderableConfigForColorSpace(const SkColorSpace*);
/** /**

View File

@ -982,9 +982,9 @@ private:
}; };
bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrAAConvexPathRenderer::onDrawPath"); "GrAAConvexPathRenderer::onDrawPath");
SkASSERT(!args.fDrawContext->isUnifiedMultisampled()); SkASSERT(!args.fRenderTargetContext->isUnifiedMultisampled());
SkASSERT(!args.fShape->isEmpty()); SkASSERT(!args.fShape->isEmpty());
SkPath path; SkPath path;
@ -996,7 +996,7 @@ bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
GrPipelineBuilder pipelineBuilder(*args.fPaint); GrPipelineBuilder pipelineBuilder(*args.fPaint);
pipelineBuilder.setUserStencil(args.fUserStencilSettings); pipelineBuilder.setUserStencil(args.fUserStencilSettings);
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, batch);
return true; return true;

View File

@ -507,9 +507,9 @@ private:
}; };
bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrAADistanceFieldPathRenderer::onDrawPath"); "GrAADistanceFieldPathRenderer::onDrawPath");
SkASSERT(!args.fDrawContext->isUnifiedMultisampled()); SkASSERT(!args.fRenderTargetContext->isUnifiedMultisampled());
SkASSERT(args.fShape->style().isSimpleFill()); SkASSERT(args.fShape->style().isSimpleFill());
// we've already bailed on inverse filled paths, so this is safe // we've already bailed on inverse filled paths, so this is safe
@ -535,7 +535,7 @@ bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) {
GrPipelineBuilder pipelineBuilder(*args.fPaint); GrPipelineBuilder pipelineBuilder(*args.fPaint);
pipelineBuilder.setUserStencil(args.fUserStencilSettings); pipelineBuilder.setUserStencil(args.fUserStencilSettings);
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, batch);
return true; return true;
} }

View File

@ -956,12 +956,13 @@ static GrDrawBatch* create_hairline_batch(GrColor color,
} }
bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrAAHairlinePathRenderer::onDrawPath"); "GrAAHairlinePathRenderer::onDrawPath");
SkASSERT(!args.fDrawContext->isUnifiedMultisampled()); SkASSERT(!args.fRenderTargetContext->isUnifiedMultisampled());
SkIRect devClipBounds; SkIRect devClipBounds;
args.fClip->getConservativeBounds(args.fDrawContext->width(), args.fDrawContext->height(), args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
args.fRenderTargetContext->height(),
&devClipBounds); &devClipBounds);
SkPath path; SkPath path;
@ -972,7 +973,7 @@ bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
GrPipelineBuilder pipelineBuilder(*args.fPaint); GrPipelineBuilder pipelineBuilder(*args.fPaint);
pipelineBuilder.setUserStencil(args.fUserStencilSettings); pipelineBuilder.setUserStencil(args.fUserStencilSettings);
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, batch);
return true; return true;
} }

View File

@ -329,9 +329,9 @@ private:
}; };
bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrAALinearizingConvexPathRenderer::onDrawPath"); "GrAALinearizingConvexPathRenderer::onDrawPath");
SkASSERT(!args.fDrawContext->isUnifiedMultisampled()); SkASSERT(!args.fRenderTargetContext->isUnifiedMultisampled());
SkASSERT(!args.fShape->isEmpty()); SkASSERT(!args.fShape->isEmpty());
SkASSERT(!args.fShape->style().pathEffect()); SkASSERT(!args.fShape->style().pathEffect());
@ -352,7 +352,7 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
GrPipelineBuilder pipelineBuilder(*args.fPaint); GrPipelineBuilder pipelineBuilder(*args.fPaint);
pipelineBuilder.setUserStencil(args.fUserStencilSettings); pipelineBuilder.setUserStencil(args.fUserStencilSettings);
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, batch);
return true; return true;
} }

View File

@ -24,9 +24,9 @@ bool GrDashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
} }
bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrDashLinePathRenderer::onDrawPath"); "GrDashLinePathRenderer::onDrawPath");
bool useHWAA = args.fDrawContext->isUnifiedMultisampled(); bool useHWAA = args.fRenderTargetContext->isUnifiedMultisampled();
GrDashingEffect::AAMode aaMode; GrDashingEffect::AAMode aaMode;
if (useHWAA) { if (useHWAA) {
// We ignore args.fAntiAlias here and force anti aliasing when using MSAA. Otherwise, // We ignore args.fAntiAlias here and force anti aliasing when using MSAA. Otherwise,
@ -51,6 +51,6 @@ bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
GrPipelineBuilder pipelineBuilder(*args.fPaint, useHWAA); GrPipelineBuilder pipelineBuilder(*args.fPaint, useHWAA);
pipelineBuilder.setUserStencil(args.fUserStencilSettings); pipelineBuilder.setUserStencil(args.fUserStencilSettings);
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, batch);
return true; return true;
} }

View File

@ -412,7 +412,7 @@ private:
typedef GrVertexBatch INHERITED; typedef GrVertexBatch INHERITED;
}; };
bool GrDefaultPathRenderer::internalDrawPath(GrDrawContext* drawContext, bool GrDefaultPathRenderer::internalDrawPath(GrRenderTargetContext* renderTargetContext,
const GrPaint& paint, const GrPaint& paint,
const GrUserStencilSettings& userStencilSettings, const GrUserStencilSettings& userStencilSettings,
const GrClip& clip, const GrClip& clip,
@ -528,7 +528,8 @@ bool GrDefaultPathRenderer::internalDrawPath(GrDrawContext* drawContext,
SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds()); SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds());
SkRect devBounds; SkRect devBounds;
GetPathDevBounds(path, drawContext->width(), drawContext->height(), viewMatrix, &devBounds); GetPathDevBounds(path, renderTargetContext->width(), renderTargetContext->height(), viewMatrix,
&devBounds);
for (int p = 0; p < passCount; ++p) { for (int p = 0; p < passCount; ++p) {
if (lastPassIsBounds && (p == passCount-1)) { if (lastPassIsBounds && (p == passCount-1)) {
@ -556,25 +557,25 @@ bool GrDefaultPathRenderer::internalDrawPath(GrDrawContext* drawContext,
&localMatrix)); &localMatrix));
SkASSERT(GrDrawFace::kBoth == drawFace[p]); SkASSERT(GrDrawFace::kBoth == drawFace[p]);
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint)); GrPipelineBuilder pipelineBuilder(paint, renderTargetContext->mustUseHWAA(paint));
pipelineBuilder.setDrawFace(drawFace[p]); pipelineBuilder.setDrawFace(drawFace[p]);
pipelineBuilder.setUserStencil(passes[p]); pipelineBuilder.setUserStencil(passes[p]);
drawContext->drawBatch(pipelineBuilder, clip, batch); renderTargetContext->drawBatch(pipelineBuilder, clip, batch);
} else { } else {
SkAutoTUnref<GrDrawBatch> batch(new DefaultPathBatch(paint.getColor(), path, SkAutoTUnref<GrDrawBatch> batch(new DefaultPathBatch(paint.getColor(), path,
srcSpaceTol, srcSpaceTol,
newCoverage, viewMatrix, newCoverage, viewMatrix,
isHairline, devBounds)); isHairline, devBounds));
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint)); GrPipelineBuilder pipelineBuilder(paint, renderTargetContext->mustUseHWAA(paint));
pipelineBuilder.setDrawFace(drawFace[p]); pipelineBuilder.setDrawFace(drawFace[p]);
pipelineBuilder.setUserStencil(passes[p]); pipelineBuilder.setUserStencil(passes[p]);
if (passCount > 1) { if (passCount > 1) {
pipelineBuilder.setDisableColorXPFactory(); pipelineBuilder.setDisableColorXPFactory();
} }
drawContext->drawBatch(pipelineBuilder, clip, batch); renderTargetContext->drawBatch(pipelineBuilder, clip, batch);
} }
} }
return true; return true;
@ -588,9 +589,9 @@ bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
} }
bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrDefaultPathRenderer::onDrawPath"); "GrDefaultPathRenderer::onDrawPath");
return this->internalDrawPath(args.fDrawContext, return this->internalDrawPath(args.fRenderTargetContext,
*args.fPaint, *args.fPaint,
*args.fUserStencilSettings, *args.fUserStencilSettings,
*args.fClip, *args.fClip,
@ -600,7 +601,7 @@ bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
} }
void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) { void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrDefaultPathRenderer::onStencilPath"); "GrDefaultPathRenderer::onStencilPath");
SkASSERT(!args.fShape->inverseFilled()); SkASSERT(!args.fShape->inverseFilled());
@ -608,8 +609,8 @@ void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
paint.setXPFactory(GrDisableColorXPFactory::Make()); paint.setXPFactory(GrDisableColorXPFactory::Make());
paint.setAntiAlias(args.fIsAA); paint.setAntiAlias(args.fIsAA);
this->internalDrawPath(args.fDrawContext, paint, GrUserStencilSettings::kUnused, *args.fClip, this->internalDrawPath(args.fRenderTargetContext, paint, GrUserStencilSettings::kUnused,
*args.fViewMatrix, *args.fShape, true); *args.fClip, *args.fViewMatrix, *args.fShape, true);
} }
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -30,7 +30,7 @@ private:
void onStencilPath(const StencilPathArgs&) override; void onStencilPath(const StencilPathArgs&) override;
bool internalDrawPath(GrDrawContext*, bool internalDrawPath(GrRenderTargetContext*,
const GrPaint&, const GrPaint&,
const GrUserStencilSettings&, const GrUserStencilSettings&,
const GrClip&, const GrClip&,

View File

@ -549,7 +549,7 @@ private:
typedef GrVertexBatch INHERITED; typedef GrVertexBatch INHERITED;
}; };
bool GrMSAAPathRenderer::internalDrawPath(GrDrawContext* drawContext, bool GrMSAAPathRenderer::internalDrawPath(GrRenderTargetContext* renderTargetContext,
const GrPaint& paint, const GrPaint& paint,
const GrUserStencilSettings& userStencilSettings, const GrUserStencilSettings& userStencilSettings,
const GrClip& clip, const GrClip& clip,
@ -621,7 +621,8 @@ bool GrMSAAPathRenderer::internalDrawPath(GrDrawContext* drawContext,
} }
SkRect devBounds; SkRect devBounds;
GetPathDevBounds(path, drawContext->width(), drawContext->height(), viewMatrix, &devBounds); GetPathDevBounds(path, renderTargetContext->width(), renderTargetContext->height(), viewMatrix,
&devBounds);
SkASSERT(passCount <= kMaxNumPasses); SkASSERT(passCount <= kMaxNumPasses);
@ -650,10 +651,10 @@ bool GrMSAAPathRenderer::internalDrawPath(GrDrawContext* drawContext,
GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM, bounds, nullptr, GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM, bounds, nullptr,
&localMatrix)); &localMatrix));
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint)); GrPipelineBuilder pipelineBuilder(paint, renderTargetContext->mustUseHWAA(paint));
pipelineBuilder.setUserStencil(passes[p]); pipelineBuilder.setUserStencil(passes[p]);
drawContext->drawBatch(pipelineBuilder, clip, batch); renderTargetContext->drawBatch(pipelineBuilder, clip, batch);
} else { } else {
SkAutoTUnref<MSAAPathBatch> batch(new MSAAPathBatch(paint.getColor(), path, SkAutoTUnref<MSAAPathBatch> batch(new MSAAPathBatch(paint.getColor(), path,
viewMatrix, devBounds)); viewMatrix, devBounds));
@ -661,13 +662,13 @@ bool GrMSAAPathRenderer::internalDrawPath(GrDrawContext* drawContext,
return false; return false;
} }
GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(paint)); GrPipelineBuilder pipelineBuilder(paint, renderTargetContext->mustUseHWAA(paint));
pipelineBuilder.setUserStencil(passes[p]); pipelineBuilder.setUserStencil(passes[p]);
if (passCount > 1) { if (passCount > 1) {
pipelineBuilder.setDisableColorXPFactory(); pipelineBuilder.setDisableColorXPFactory();
} }
drawContext->drawBatch(pipelineBuilder, clip, batch); renderTargetContext->drawBatch(pipelineBuilder, clip, batch);
} }
} }
return true; return true;
@ -681,7 +682,7 @@ bool GrMSAAPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
} }
bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrMSAAPathRenderer::onDrawPath"); "GrMSAAPathRenderer::onDrawPath");
SkTLazy<GrShape> tmpShape; SkTLazy<GrShape> tmpShape;
const GrShape* shape = args.fShape; const GrShape* shape = args.fShape;
@ -690,7 +691,7 @@ bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) {
tmpShape.init(args.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale)); tmpShape.init(args.fShape->applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, styleScale));
shape = tmpShape.get(); shape = tmpShape.get();
} }
return this->internalDrawPath(args.fDrawContext, return this->internalDrawPath(args.fRenderTargetContext,
*args.fPaint, *args.fPaint,
*args.fUserStencilSettings, *args.fUserStencilSettings,
*args.fClip, *args.fClip,
@ -700,7 +701,7 @@ bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) {
} }
void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) { void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrMSAAPathRenderer::onStencilPath"); "GrMSAAPathRenderer::onStencilPath");
SkASSERT(args.fShape->style().isSimpleFill()); SkASSERT(args.fShape->style().isSimpleFill());
SkASSERT(!args.fShape->mayBeInverseFilledAfterStyling()); SkASSERT(!args.fShape->mayBeInverseFilledAfterStyling());
@ -709,8 +710,8 @@ void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) {
paint.setXPFactory(GrDisableColorXPFactory::Make()); paint.setXPFactory(GrDisableColorXPFactory::Make());
paint.setAntiAlias(args.fIsAA); paint.setAntiAlias(args.fIsAA);
this->internalDrawPath(args.fDrawContext, paint, GrUserStencilSettings::kUnused, *args.fClip, this->internalDrawPath(args.fRenderTargetContext, paint, GrUserStencilSettings::kUnused,
*args.fViewMatrix, *args.fShape, true); *args.fClip, *args.fViewMatrix, *args.fShape, true);
} }
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -21,7 +21,7 @@ private:
void onStencilPath(const StencilPathArgs&) override; void onStencilPath(const StencilPathArgs&) override;
bool internalDrawPath(GrDrawContext*, bool internalDrawPath(GrRenderTargetContext*,
const GrPaint&, const GrPaint&,
const GrUserStencilSettings&, const GrUserStencilSettings&,
const GrClip&, const GrClip&,

View File

@ -930,10 +930,11 @@ bool GrPLSPathRenderer::onDrawPath(const DrawPathArgs& args) {
SkAutoTUnref<GrDrawBatch> batch(new PLSPathBatch(args.fPaint->getColor(), SkAutoTUnref<GrDrawBatch> batch(new PLSPathBatch(args.fPaint->getColor(),
path, *args.fViewMatrix)); path, *args.fViewMatrix));
GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fDrawContext->mustUseHWAA(*args.fPaint)); GrPipelineBuilder pipelineBuilder(*args.fPaint,
args.fRenderTargetContext->mustUseHWAA(*args.fPaint));
pipelineBuilder.setUserStencil(args.fUserStencilSettings); pipelineBuilder.setUserStencil(args.fUserStencilSettings);
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, batch);
SkDEBUGCODE(inPLSDraw = false;) SkDEBUGCODE(inPLSDraw = false;)
return true; return true;

View File

@ -9,7 +9,7 @@
#include "GrStencilAndCoverPathRenderer.h" #include "GrStencilAndCoverPathRenderer.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrDrawPathBatch.h" #include "GrDrawPathBatch.h"
#include "GrFixedClip.h" #include "GrFixedClip.h"
#include "GrGpu.h" #include "GrGpu.h"
@ -78,18 +78,20 @@ static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const GrShape&
} }
void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrStencilAndCoverPathRenderer::onStencilPath"); "GrStencilAndCoverPathRenderer::onStencilPath");
SkASSERT(!args.fIsAA || args.fDrawContext->isStencilBufferMultisampled()); SkASSERT(!args.fIsAA || args.fRenderTargetContext->isStencilBufferMultisampled());
SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fShape)); SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fShape));
args.fDrawContext->drawContextPriv().stencilPath(*args.fClip, args.fIsAA, *args.fViewMatrix, p); args.fRenderTargetContext->renderTargetContextPriv().stencilPath(*args.fClip, args.fIsAA,
*args.fViewMatrix, p);
} }
bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrStencilAndCoverPathRenderer::onDrawPath"); "GrStencilAndCoverPathRenderer::onDrawPath");
SkASSERT(!args.fPaint->isAntiAlias() || args.fDrawContext->isStencilBufferMultisampled()); SkASSERT(!args.fPaint->isAntiAlias() ||
args.fRenderTargetContext->isStencilBufferMultisampled());
SkASSERT(!args.fShape->style().strokeRec().isHairlineStyle()); SkASSERT(!args.fShape->style().strokeRec().isHairlineStyle());
const SkMatrix& viewMatrix = *args.fViewMatrix; const SkMatrix& viewMatrix = *args.fViewMatrix;
@ -101,8 +103,8 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) {
SkMatrix invert = SkMatrix::I(); SkMatrix invert = SkMatrix::I();
SkRect bounds = SkRect bounds =
SkRect::MakeLTRB(0, 0, SkRect::MakeLTRB(0, 0,
SkIntToScalar(args.fDrawContext->width()), SkIntToScalar(args.fRenderTargetContext->width()),
SkIntToScalar(args.fDrawContext->height())); SkIntToScalar(args.fRenderTargetContext->height()));
SkMatrix vmi; SkMatrix vmi;
// mapRect through persp matrix may not be correct // mapRect through persp matrix may not be correct
if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) {
@ -123,8 +125,9 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) {
nullptr, &invert)); nullptr, &invert));
// fake inverse with a stencil and cover // fake inverse with a stencil and cover
args.fDrawContext->drawContextPriv().stencilPath(*args.fClip, args.fPaint->isAntiAlias(), args.fRenderTargetContext->renderTargetContextPriv().stencilPath(*args.fClip,
viewMatrix, path); args.fPaint->isAntiAlias(),
viewMatrix, path);
{ {
static constexpr GrUserStencilSettings kInvertedCoverPass( static constexpr GrUserStencilSettings kInvertedCoverPass(
@ -142,10 +145,10 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) {
GrPipelineBuilder pipelineBuilder(*args.fPaint, GrPipelineBuilder pipelineBuilder(*args.fPaint,
args.fPaint->isAntiAlias() && args.fPaint->isAntiAlias() &&
!args.fDrawContext->hasMixedSamples()); !args.fRenderTargetContext->hasMixedSamples());
pipelineBuilder.setUserStencil(&kInvertedCoverPass); pipelineBuilder.setUserStencil(&kInvertedCoverPass);
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, coverBatch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, coverBatch);
} }
} else { } else {
static constexpr GrUserStencilSettings kCoverPass( static constexpr GrUserStencilSettings kCoverPass(
@ -164,11 +167,11 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) {
GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fPaint->isAntiAlias()); GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fPaint->isAntiAlias());
pipelineBuilder.setUserStencil(&kCoverPass); pipelineBuilder.setUserStencil(&kCoverPass);
if (args.fAntiAlias) { if (args.fAntiAlias) {
SkASSERT(args.fDrawContext->isStencilBufferMultisampled()); SkASSERT(args.fRenderTargetContext->isStencilBufferMultisampled());
pipelineBuilder.enableState(GrPipelineBuilder::kHWAntialias_Flag); pipelineBuilder.enableState(GrPipelineBuilder::kHWAntialias_Flag);
} }
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, batch);
} }
return true; return true;

View File

@ -350,10 +350,11 @@ private:
}; };
bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) { bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrTessellatingPathRenderer::onDrawPath"); "GrTessellatingPathRenderer::onDrawPath");
SkIRect clipBoundsI; SkIRect clipBoundsI;
args.fClip->getConservativeBounds(args.fDrawContext->width(), args.fDrawContext->height(), args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
args.fRenderTargetContext->height(),
&clipBoundsI); &clipBoundsI);
SkAutoTUnref<GrDrawBatch> batch(TessellatingPathBatch::Create(args.fPaint->getColor(), SkAutoTUnref<GrDrawBatch> batch(TessellatingPathBatch::Create(args.fPaint->getColor(),
*args.fShape, *args.fShape,
@ -361,10 +362,11 @@ bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) {
clipBoundsI, clipBoundsI,
args.fAntiAlias)); args.fAntiAlias));
GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fDrawContext->mustUseHWAA(*args.fPaint)); GrPipelineBuilder pipelineBuilder(*args.fPaint,
args.fRenderTargetContext->mustUseHWAA(*args.fPaint));
pipelineBuilder.setUserStencil(args.fUserStencilSettings); pipelineBuilder.setUserStencil(args.fUserStencilSettings);
args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); args.fRenderTargetContext->drawBatch(pipelineBuilder, *args.fClip, batch);
return true; return true;
} }

View File

@ -7,7 +7,7 @@
#include "GrConfigConversionEffect.h" #include "GrConfigConversionEffect.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrInvariantOutput.h" #include "GrInvariantOutput.h"
#include "GrSimpleTextureEffect.h" #include "GrSimpleTextureEffect.h"
#include "SkMatrix.h" #include "SkMatrix.h"
@ -184,10 +184,12 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
} }
} }
sk_sp<GrDrawContext> readDC(context->makeDrawContext(SkBackingFit::kExact, kSize, kSize, sk_sp<GrRenderTargetContext> readDC(context->makeRenderTargetContext(SkBackingFit::kExact,
kConfig, nullptr)); kSize, kSize,
sk_sp<GrDrawContext> tempDC(context->makeDrawContext(SkBackingFit::kExact, kSize, kSize, kConfig, nullptr));
kConfig, nullptr)); sk_sp<GrRenderTargetContext> tempDC(context->makeRenderTargetContext(SkBackingFit::kExact,
kSize, kSize,
kConfig, nullptr));
if (!readDC || !tempDC) { if (!readDC || !tempDC) {
return; return;
} }

View File

@ -8,7 +8,7 @@
#include "effects/GrCoverageSetOpXP.h" #include "effects/GrCoverageSetOpXP.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrColor.h" #include "GrColor.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrPipeline.h" #include "GrPipeline.h"
#include "GrProcessor.h" #include "GrProcessor.h"
#include "GrProcOptInfo.h" #include "GrProcOptInfo.h"
@ -339,6 +339,6 @@ GR_DEFINE_XP_FACTORY_TEST(GrCoverageSetOpXPFactory);
sk_sp<GrXPFactory> GrCoverageSetOpXPFactory::TestCreate(GrProcessorTestData* d) { sk_sp<GrXPFactory> GrCoverageSetOpXPFactory::TestCreate(GrProcessorTestData* d) {
SkRegion::Op regionOp = SkRegion::Op(d->fRandom->nextULessThan(SkRegion::kLastOp + 1)); SkRegion::Op regionOp = SkRegion::Op(d->fRandom->nextULessThan(SkRegion::kLastOp + 1));
bool invertCoverage = !d->fDrawContext->hasMixedSamples() && d->fRandom->nextBool(); bool invertCoverage = !d->fRenderTargetContext->hasMixedSamples() && d->fRandom->nextBool();
return GrCoverageSetOpXPFactory::Make(regionOp, invertCoverage); return GrCoverageSetOpXPFactory::Make(regionOp, invertCoverage);
} }

View File

@ -9,7 +9,7 @@
#include "GrBlurUtils.h" #include "GrBlurUtils.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrPipelineBuilder.h" #include "GrPipelineBuilder.h"
#include "GrTextUtils.h" #include "GrTextUtils.h"
#include "SkColorFilter.h" #include "SkColorFilter.h"
@ -303,7 +303,7 @@ inline GrDrawBatch* GrAtlasTextBlob::createBatch(
} }
inline inline
void GrAtlasTextBlob::flushRun(GrDrawContext* dc, const GrPaint& grPaint, void GrAtlasTextBlob::flushRun(GrRenderTargetContext* rtc, const GrPaint& grPaint,
const GrClip& clip, int run, const SkMatrix& viewMatrix, SkScalar x, const GrClip& clip, int run, const SkMatrix& viewMatrix, SkScalar x,
SkScalar y, SkScalar y,
const SkPaint& skPaint, const SkSurfaceProps& props, const SkPaint& skPaint, const SkSurfaceProps& props,
@ -321,12 +321,13 @@ void GrAtlasTextBlob::flushRun(GrDrawContext* dc, const GrPaint& grPaint,
SkAutoTUnref<GrDrawBatch> batch(this->createBatch(info, glyphCount, run, SkAutoTUnref<GrDrawBatch> batch(this->createBatch(info, glyphCount, run,
subRun, viewMatrix, x, y, color, subRun, viewMatrix, x, y, color,
skPaint, props, skPaint, props,
distanceAdjustTable, dc->isGammaCorrect(), distanceAdjustTable,
rtc->isGammaCorrect(),
cache)); cache));
GrPipelineBuilder pipelineBuilder(grPaint, dc->mustUseHWAA(grPaint)); GrPipelineBuilder pipelineBuilder(grPaint, rtc->mustUseHWAA(grPaint));
dc->drawBatch(pipelineBuilder, clip, batch); rtc->drawBatch(pipelineBuilder, clip, batch);
} }
} }
@ -351,7 +352,7 @@ static void calculate_translation(bool applyVM,
} }
void GrAtlasTextBlob::flushBigGlyphs(GrContext* context, GrDrawContext* dc, void GrAtlasTextBlob::flushBigGlyphs(GrContext* context, GrRenderTargetContext* rtc,
const GrClip& clip, const SkPaint& skPaint, const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkMatrix& viewMatrix, SkScalar x, SkScalar y,
const SkIRect& clipBounds) { const SkIRect& clipBounds) {
@ -367,12 +368,12 @@ void GrAtlasTextBlob::flushBigGlyphs(GrContext* context, GrDrawContext* dc,
ctm.postConcat(viewMatrix); ctm.postConcat(viewMatrix);
} }
GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, bigGlyph.fPath, GrBlurUtils::drawPathWithMaskFilter(context, rtc, clip, bigGlyph.fPath,
skPaint, ctm, nullptr, clipBounds, false); skPaint, ctm, nullptr, clipBounds, false);
} }
} }
void GrAtlasTextBlob::flushRunAsPaths(GrContext* context, GrDrawContext* dc, void GrAtlasTextBlob::flushRunAsPaths(GrContext* context, GrRenderTargetContext* rtc,
const SkSurfaceProps& props, const SkSurfaceProps& props,
const SkTextBlobRunIterator& it, const SkTextBlobRunIterator& it,
const GrClip& clip, const SkPaint& skPaint, const GrClip& clip, const SkPaint& skPaint,
@ -393,18 +394,18 @@ void GrAtlasTextBlob::flushRunAsPaths(GrContext* context, GrDrawContext* dc,
switch (it.positioning()) { switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning: case SkTextBlob::kDefault_Positioning:
GrTextUtils::DrawTextAsPath(context, dc, clip, runPaint, viewMatrix, GrTextUtils::DrawTextAsPath(context, rtc, clip, runPaint, viewMatrix,
(const char *)it.glyphs(), (const char *)it.glyphs(),
textLen, x + offset.x(), y + offset.y(), clipBounds); textLen, x + offset.x(), y + offset.y(), clipBounds);
break; break;
case SkTextBlob::kHorizontal_Positioning: case SkTextBlob::kHorizontal_Positioning:
GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, runPaint, viewMatrix, GrTextUtils::DrawPosTextAsPath(context, rtc, props, clip, runPaint, viewMatrix,
(const char*)it.glyphs(), (const char*)it.glyphs(),
textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()), textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
clipBounds); clipBounds);
break; break;
case SkTextBlob::kFull_Positioning: case SkTextBlob::kFull_Positioning:
GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, runPaint, viewMatrix, GrTextUtils::DrawPosTextAsPath(context, rtc, props, clip, runPaint, viewMatrix,
(const char*)it.glyphs(), (const char*)it.glyphs(),
textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds); textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
break; break;
@ -412,7 +413,7 @@ void GrAtlasTextBlob::flushRunAsPaths(GrContext* context, GrDrawContext* dc,
} }
void GrAtlasTextBlob::flushCached(GrContext* context, void GrAtlasTextBlob::flushCached(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkTextBlob* blob, const SkTextBlob* blob,
const SkSurfaceProps& props, const SkSurfaceProps& props,
const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrDistanceFieldAdjustTable* distanceAdjustTable,
@ -428,20 +429,20 @@ void GrAtlasTextBlob::flushCached(GrContext* context,
SkTextBlobRunIterator it(blob); SkTextBlobRunIterator it(blob);
for (int run = 0; !it.done(); it.next(), run++) { for (int run = 0; !it.done(); it.next(), run++) {
if (fRuns[run].fDrawAsPaths) { if (fRuns[run].fDrawAsPaths) {
this->flushRunAsPaths(context, dc, props, it, clip, skPaint, this->flushRunAsPaths(context, rtc, props, it, clip, skPaint,
drawFilter, viewMatrix, clipBounds, x, y); drawFilter, viewMatrix, clipBounds, x, y);
continue; continue;
} }
this->flushRun(dc, grPaint, clip, run, viewMatrix, x, y, skPaint, props, this->flushRun(rtc, grPaint, clip, run, viewMatrix, x, y, skPaint, props,
distanceAdjustTable, context->getBatchFontCache()); distanceAdjustTable, context->getBatchFontCache());
} }
// Now flush big glyphs // Now flush big glyphs
this->flushBigGlyphs(context, dc, clip, skPaint, viewMatrix, x, y, clipBounds); this->flushBigGlyphs(context, rtc, clip, skPaint, viewMatrix, x, y, clipBounds);
} }
void GrAtlasTextBlob::flushThrowaway(GrContext* context, void GrAtlasTextBlob::flushThrowaway(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkSurfaceProps& props, const SkSurfaceProps& props,
const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrDistanceFieldAdjustTable* distanceAdjustTable,
const SkPaint& skPaint, const SkPaint& skPaint,
@ -451,12 +452,12 @@ void GrAtlasTextBlob::flushThrowaway(GrContext* context,
const SkIRect& clipBounds, const SkIRect& clipBounds,
SkScalar x, SkScalar y) { SkScalar x, SkScalar y) {
for (int run = 0; run < fRunCount; run++) { for (int run = 0; run < fRunCount; run++) {
this->flushRun(dc, grPaint, clip, run, viewMatrix, x, y, skPaint, props, this->flushRun(rtc, grPaint, clip, run, viewMatrix, x, y, skPaint, props,
distanceAdjustTable, context->getBatchFontCache()); distanceAdjustTable, context->getBatchFontCache());
} }
// Now flush big glyphs // Now flush big glyphs
this->flushBigGlyphs(context, dc, clip, skPaint, viewMatrix, x, y, clipBounds); this->flushBigGlyphs(context, rtc, clip, skPaint, viewMatrix, x, y, clipBounds);
} }
GrDrawBatch* GrAtlasTextBlob::test_createBatch( GrDrawBatch* GrAtlasTextBlob::test_createBatch(

View File

@ -182,7 +182,7 @@ public:
// flush a GrAtlasTextBlob associated with a SkTextBlob // flush a GrAtlasTextBlob associated with a SkTextBlob
void flushCached(GrContext* context, void flushCached(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkTextBlob* blob, const SkTextBlob* blob,
const SkSurfaceProps& props, const SkSurfaceProps& props,
const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrDistanceFieldAdjustTable* distanceAdjustTable,
@ -196,7 +196,7 @@ public:
// flush a throwaway GrAtlasTextBlob *not* associated with an SkTextBlob // flush a throwaway GrAtlasTextBlob *not* associated with an SkTextBlob
void flushThrowaway(GrContext* context, void flushThrowaway(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkSurfaceProps& props, const SkSurfaceProps& props,
const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrDistanceFieldAdjustTable* distanceAdjustTable,
const SkPaint& skPaint, const SkPaint& skPaint,
@ -294,19 +294,19 @@ private:
void appendLargeGlyph(GrGlyph* glyph, SkGlyphCache* cache, const SkGlyph& skGlyph, void appendLargeGlyph(GrGlyph* glyph, SkGlyphCache* cache, const SkGlyph& skGlyph,
SkScalar x, SkScalar y, SkScalar scale, bool applyVM); SkScalar x, SkScalar y, SkScalar scale, bool applyVM);
inline void flushRun(GrDrawContext* dc, const GrPaint&, const GrClip&, inline void flushRun(GrRenderTargetContext* rtc, const GrPaint&, const GrClip&,
int run, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, int run, const SkMatrix& viewMatrix, SkScalar x, SkScalar y,
const SkPaint& skPaint, const SkSurfaceProps& props, const SkPaint& skPaint, const SkSurfaceProps& props,
const GrDistanceFieldAdjustTable* distanceAdjustTable, const GrDistanceFieldAdjustTable* distanceAdjustTable,
GrBatchFontCache* cache); GrBatchFontCache* cache);
void flushBigGlyphs(GrContext* context, GrDrawContext* dc, void flushBigGlyphs(GrContext* context, GrRenderTargetContext* rtc,
const GrClip& clip, const SkPaint& skPaint, const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkMatrix& viewMatrix, SkScalar x, SkScalar y,
const SkIRect& clipBounds); const SkIRect& clipBounds);
void flushRunAsPaths(GrContext* context, void flushRunAsPaths(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkSurfaceProps& props, const SkSurfaceProps& props,
const SkTextBlobRunIterator& it, const SkTextBlobRunIterator& it,
const GrClip& clip, const SkPaint& skPaint, const GrClip& clip, const SkPaint& skPaint,

View File

@ -7,7 +7,7 @@
#include "GrAtlasTextContext.h" #include "GrAtlasTextContext.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrTextBlobCache.h" #include "GrTextBlobCache.h"
#include "GrTextUtils.h" #include "GrTextUtils.h"
@ -53,10 +53,10 @@ GrColor GrAtlasTextContext::ComputeCanonicalColor(const SkPaint& paint, bool lcd
return canonicalColor; return canonicalColor;
} }
uint32_t GrAtlasTextContext::ComputeScalerContextFlags(GrDrawContext* dc) { uint32_t GrAtlasTextContext::ComputeScalerContextFlags(GrRenderTargetContext* rtc) {
// If we're doing gamma-correct rendering, then we can disable the gamma hacks. // If we're doing gamma-correct rendering, then we can disable the gamma hacks.
// Otherwise, leave them on. In either case, we still want the contrast boost: // Otherwise, leave them on. In either case, we still want the contrast boost:
if (dc->isGammaCorrect()) { if (rtc->isGammaCorrect()) {
return SkPaint::kBoostContrast_ScalerContextFlag; return SkPaint::kBoostContrast_ScalerContextFlag;
} else { } else {
return SkPaint::kFakeGammaAndBoostContrast_ScalerContextFlags; return SkPaint::kFakeGammaAndBoostContrast_ScalerContextFlags;
@ -76,7 +76,7 @@ bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) {
return false; return false;
} }
void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc, void GrAtlasTextContext::drawTextBlob(GrContext* context, GrRenderTargetContext* rtc,
const GrClip& clip, const SkPaint& skPaint, const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkSurfaceProps& props, const SkTextBlob* blob, const SkSurfaceProps& props, const SkTextBlob* blob,
@ -96,7 +96,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
bool canCache = !(skPaint.getPathEffect() || bool canCache = !(skPaint.getPathEffect() ||
(mf && !mf->asABlur(&blurRec)) || (mf && !mf->asABlur(&blurRec)) ||
drawFilter); drawFilter);
uint32_t scalerContextFlags = ComputeScalerContextFlags(dc); uint32_t scalerContextFlags = ComputeScalerContextFlags(rtc);
GrTextBlobCache* cache = context->getTextBlobCache(); GrTextBlobCache* cache = context->getTextBlobCache();
if (canCache) { if (canCache) {
@ -124,7 +124,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
// Though for the time being runs in the textblob can override the paint, they only touch font // Though for the time being runs in the textblob can override the paint, they only touch font
// info. // info.
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(context, dc, skPaint, viewMatrix, &grPaint)) { if (!SkPaintToGrPaint(context, rtc, skPaint, viewMatrix, &grPaint)) {
return; return;
} }
@ -167,7 +167,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
blob, x, y, drawFilter); blob, x, y, drawFilter);
} }
cacheBlob->flushCached(context, dc, blob, props, fDistanceAdjustTable, skPaint, cacheBlob->flushCached(context, rtc, blob, props, fDistanceAdjustTable, skPaint,
grPaint, drawFilter, clip, viewMatrix, clipBounds, x, y); grPaint, drawFilter, clip, viewMatrix, clipBounds, x, y);
} }
@ -313,7 +313,7 @@ GrAtlasTextContext::CreateDrawPosTextBlob(GrTextBlobCache* blobCache, GrBatchFon
} }
void GrAtlasTextContext::drawText(GrContext* context, void GrAtlasTextContext::drawText(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const GrClip& clip, const GrClip& clip,
const GrPaint& paint, const SkPaint& skPaint, const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -327,21 +327,21 @@ void GrAtlasTextContext::drawText(GrContext* context,
CreateDrawTextBlob(context->getTextBlobCache(), context->getBatchFontCache(), CreateDrawTextBlob(context->getTextBlobCache(), context->getBatchFontCache(),
*context->caps()->shaderCaps(), *context->caps()->shaderCaps(),
paint, skPaint, paint, skPaint,
ComputeScalerContextFlags(dc), ComputeScalerContextFlags(rtc),
viewMatrix, props, viewMatrix, props,
text, byteLength, x, y)); text, byteLength, x, y));
blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint, blob->flushThrowaway(context, rtc, props, fDistanceAdjustTable, skPaint, paint,
clip, viewMatrix, regionClipBounds, x, y); clip, viewMatrix, regionClipBounds, x, y);
return; return;
} }
// fall back to drawing as a path // fall back to drawing as a path
GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, byteLength, x, y, GrTextUtils::DrawTextAsPath(context, rtc, clip, skPaint, viewMatrix, text, byteLength, x, y,
regionClipBounds); regionClipBounds);
} }
void GrAtlasTextContext::drawPosText(GrContext* context, void GrAtlasTextContext::drawPosText(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const GrClip& clip, const GrClip& clip,
const GrPaint& paint, const SkPaint& skPaint, const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -357,18 +357,18 @@ void GrAtlasTextContext::drawPosText(GrContext* context,
context->getBatchFontCache(), context->getBatchFontCache(),
*context->caps()->shaderCaps(), *context->caps()->shaderCaps(),
paint, skPaint, paint, skPaint,
ComputeScalerContextFlags(dc), ComputeScalerContextFlags(rtc),
viewMatrix, props, viewMatrix, props,
text, byteLength, text, byteLength,
pos, scalarsPerPosition, pos, scalarsPerPosition,
offset)); offset));
blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint, blob->flushThrowaway(context, rtc, props, fDistanceAdjustTable, skPaint, paint,
clip, viewMatrix, regionClipBounds, offset.fX, offset.fY); clip, viewMatrix, regionClipBounds, offset.fX, offset.fY);
return; return;
} }
// fall back to drawing as a path // fall back to drawing as a path
GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, skPaint, viewMatrix, text, GrTextUtils::DrawPosTextAsPath(context, rtc, props, clip, skPaint, viewMatrix, text,
byteLength, pos, scalarsPerPosition, offset, regionClipBounds); byteLength, pos, scalarsPerPosition, offset, regionClipBounds);
} }
@ -388,9 +388,9 @@ DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
gTextContext = GrAtlasTextContext::Create(); gTextContext = GrAtlasTextContext::Create();
} }
// Setup dummy SkPaint / GrPaint / GrDrawContext // Setup dummy SkPaint / GrPaint / GrRenderTargetContext
sk_sp<GrDrawContext> drawContext(context->makeDrawContext(SkBackingFit::kApprox, 1024, 1024, sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
kRGBA_8888_GrPixelConfig, nullptr)); SkBackingFit::kApprox, 1024, 1024, kRGBA_8888_GrPixelConfig, nullptr));
GrColor color = GrRandomColor(random); GrColor color = GrRandomColor(random);
SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
@ -401,7 +401,7 @@ DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
skPaint.setSubpixelText(random->nextBool()); skPaint.setSubpixelText(random->nextBool());
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(context, drawContext.get(), skPaint, viewMatrix, &grPaint)) { if (!SkPaintToGrPaint(context, renderTargetContext.get(), skPaint, viewMatrix, &grPaint)) {
SkFAIL("couldn't convert paint\n"); SkFAIL("couldn't convert paint\n");
} }

View File

@ -18,7 +18,7 @@
#endif #endif
class GrDrawBatch; class GrDrawBatch;
class GrDrawContext; class GrRenderTargetContext;
class GrPipelineBuilder; class GrPipelineBuilder;
class GrTextBlobCache; class GrTextBlobCache;
class SkGlyph; class SkGlyph;
@ -32,16 +32,16 @@ public:
bool canDraw(const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&, bool canDraw(const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&,
const GrShaderCaps&); const GrShaderCaps&);
void drawText(GrContext*, GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&, void drawText(GrContext*, GrRenderTargetContext*, const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[], const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[],
size_t byteLength, SkScalar x, SkScalar y, size_t byteLength, SkScalar x, SkScalar y,
const SkIRect& regionClipBounds); const SkIRect& regionClipBounds);
void drawPosText(GrContext*, GrDrawContext*, const GrClip&, const GrPaint&, void drawPosText(GrContext*, GrRenderTargetContext*, const GrClip&, const GrPaint&,
const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& regionClipBounds); const SkPoint& offset, const SkIRect& regionClipBounds);
void drawTextBlob(GrContext*, GrDrawContext*, const GrClip&, const SkPaint&, void drawTextBlob(GrContext*, GrRenderTargetContext*, const GrClip&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*, const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*,
SkScalar x, SkScalar y, SkScalar x, SkScalar y,
SkDrawFilter*, const SkIRect& clipBounds); SkDrawFilter*, const SkIRect& clipBounds);
@ -52,7 +52,7 @@ private:
// sets up the descriptor on the blob and returns a detached cache. Client must attach // sets up the descriptor on the blob and returns a detached cache. Client must attach
inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
// Determines if we need to use fake gamma (and contrast boost): // Determines if we need to use fake gamma (and contrast boost):
inline static uint32_t ComputeScalerContextFlags(GrDrawContext*); inline static uint32_t ComputeScalerContextFlags(GrRenderTargetContext*);
static void RegenerateTextBlob(GrAtlasTextBlob* bmp, static void RegenerateTextBlob(GrAtlasTextBlob* bmp,
GrBatchFontCache*, GrBatchFontCache*,
const GrShaderCaps&, const GrShaderCaps&,

View File

@ -8,7 +8,7 @@
#include "GrStencilAndCoverTextContext.h" #include "GrStencilAndCoverTextContext.h"
#include "GrAtlasTextContext.h" #include "GrAtlasTextContext.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrPath.h" #include "GrPath.h"
#include "GrPathRange.h" #include "GrPathRange.h"
#include "GrPipelineBuilder.h" #include "GrPipelineBuilder.h"
@ -68,7 +68,7 @@ bool GrStencilAndCoverTextContext::internalCanDraw(const SkPaint& skPaint) {
return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrokeWidth(); return SkPaint::kStroke_Style != skPaint.getStyle() || 0 != skPaint.getStrokeWidth();
} }
void GrStencilAndCoverTextContext::drawText(GrContext* context, GrDrawContext* dc, void GrStencilAndCoverTextContext::drawText(GrContext* context, GrRenderTargetContext* rtc,
const GrClip& clip, const GrPaint& paint, const GrClip& clip, const GrPaint& paint,
const SkPaint& skPaint, const SkMatrix& viewMatrix, const SkPaint& skPaint, const SkMatrix& viewMatrix,
const SkSurfaceProps& props, const SkSurfaceProps& props,
@ -80,23 +80,23 @@ void GrStencilAndCoverTextContext::drawText(GrContext* context, GrDrawContext* d
if (skPaint.getTextSize() > 0) { if (skPaint.getTextSize() > 0) {
TextRun run(skPaint); TextRun run(skPaint);
run.setText(text, byteLength, x, y); run.setText(text, byteLength, x, y);
run.draw(context, dc, paint, clip, viewMatrix, props, 0, 0, run.draw(context, rtc, paint, clip, viewMatrix, props, 0, 0,
clipBounds, fFallbackTextContext, skPaint); clipBounds, fFallbackTextContext, skPaint);
} }
return; return;
} else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props,
*context->caps()->shaderCaps())) { *context->caps()->shaderCaps())) {
fFallbackTextContext->drawText(context, dc, clip, paint, skPaint, viewMatrix, props, text, fFallbackTextContext->drawText(context, rtc, clip, paint, skPaint, viewMatrix, props, text,
byteLength, x, y, clipBounds); byteLength, x, y, clipBounds);
return; return;
} }
// fall back to drawing as a path // fall back to drawing as a path
GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, byteLength, x, y, GrTextUtils::DrawTextAsPath(context, rtc, clip, skPaint, viewMatrix, text, byteLength, x, y,
clipBounds); clipBounds);
} }
void GrStencilAndCoverTextContext::drawPosText(GrContext* context, GrDrawContext* dc, void GrStencilAndCoverTextContext::drawPosText(GrContext* context, GrRenderTargetContext* rtc,
const GrClip& clip, const GrClip& clip,
const GrPaint& paint, const GrPaint& paint,
const SkPaint& skPaint, const SkPaint& skPaint,
@ -114,25 +114,25 @@ void GrStencilAndCoverTextContext::drawPosText(GrContext* context, GrDrawContext
if (skPaint.getTextSize() > 0) { if (skPaint.getTextSize() > 0) {
TextRun run(skPaint); TextRun run(skPaint);
run.setPosText(text, byteLength, pos, scalarsPerPosition, offset); run.setPosText(text, byteLength, pos, scalarsPerPosition, offset);
run.draw(context, dc, paint, clip, viewMatrix, props, 0, 0, run.draw(context, rtc, paint, clip, viewMatrix, props, 0, 0,
clipBounds, fFallbackTextContext, skPaint); clipBounds, fFallbackTextContext, skPaint);
} }
return; return;
} else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props, } else if (fFallbackTextContext->canDraw(skPaint, viewMatrix, props,
*context->caps()->shaderCaps())) { *context->caps()->shaderCaps())) {
fFallbackTextContext->drawPosText(context, dc, clip, paint, skPaint, viewMatrix, props, fFallbackTextContext->drawPosText(context, rtc, clip, paint, skPaint, viewMatrix, props,
text, byteLength, pos, text, byteLength, pos,
scalarsPerPosition, offset, clipBounds); scalarsPerPosition, offset, clipBounds);
return; return;
} }
// fall back to drawing as a path // fall back to drawing as a path
GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, skPaint, viewMatrix, text, GrTextUtils::DrawPosTextAsPath(context, rtc, props, clip, skPaint, viewMatrix, text,
byteLength, pos, scalarsPerPosition, offset, clipBounds); byteLength, pos, scalarsPerPosition, offset, clipBounds);
} }
void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrContext* context, void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const GrClip& clip, const GrClip& clip,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -161,24 +161,24 @@ void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrContext* context,
runPaint.setFlags(GrTextUtils::FilterTextFlags(props, runPaint)); runPaint.setFlags(GrTextUtils::FilterTextFlags(props, runPaint));
GrPaint grPaint; GrPaint grPaint;
if (!SkPaintToGrPaint(context, dc, runPaint, viewMatrix, &grPaint)) { if (!SkPaintToGrPaint(context, rtc, runPaint, viewMatrix, &grPaint)) {
return; return;
} }
switch (it.positioning()) { switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning: case SkTextBlob::kDefault_Positioning:
this->drawText(context, dc, clip, grPaint, runPaint, viewMatrix, props, this->drawText(context, rtc, clip, grPaint, runPaint, viewMatrix, props,
(const char *)it.glyphs(), (const char *)it.glyphs(),
textLen, x + offset.x(), y + offset.y(), clipBounds); textLen, x + offset.x(), y + offset.y(), clipBounds);
break; break;
case SkTextBlob::kHorizontal_Positioning: case SkTextBlob::kHorizontal_Positioning:
this->drawPosText(context, dc, clip, grPaint, runPaint, viewMatrix, props, this->drawPosText(context, rtc, clip, grPaint, runPaint, viewMatrix, props,
(const char*)it.glyphs(), (const char*)it.glyphs(),
textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()), textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
clipBounds); clipBounds);
break; break;
case SkTextBlob::kFull_Positioning: case SkTextBlob::kFull_Positioning:
this->drawPosText(context, dc, clip, grPaint, runPaint, viewMatrix, props, this->drawPosText(context, rtc, clip, grPaint, runPaint, viewMatrix, props,
(const char*)it.glyphs(), (const char*)it.glyphs(),
textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds); textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
break; break;
@ -191,7 +191,7 @@ void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrContext* context,
} }
} }
void GrStencilAndCoverTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc, void GrStencilAndCoverTextContext::drawTextBlob(GrContext* context, GrRenderTargetContext* rtc,
const GrClip& clip, const SkPaint& skPaint, const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkSurfaceProps& props, const SkSurfaceProps& props,
@ -203,20 +203,20 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrContext* context, GrDrawContex
} }
if (!this->internalCanDraw(skPaint)) { if (!this->internalCanDraw(skPaint)) {
fFallbackTextContext->drawTextBlob(context, dc, clip, skPaint, viewMatrix, props, skBlob, fFallbackTextContext->drawTextBlob(context, rtc, clip, skPaint, viewMatrix, props, skBlob,
x, y, drawFilter, clipBounds); x, y, drawFilter, clipBounds);
return; return;
} }
if (drawFilter || skPaint.getPathEffect()) { if (drawFilter || skPaint.getPathEffect()) {
// This draw can't be cached. // This draw can't be cached.
this->uncachedDrawTextBlob(context, dc, clip, skPaint, viewMatrix, props, skBlob, x, y, this->uncachedDrawTextBlob(context, rtc, clip, skPaint, viewMatrix, props, skBlob, x, y,
drawFilter, clipBounds); drawFilter, clipBounds);
return; return;
} }
GrPaint paint; GrPaint paint;
if (!SkPaintToGrPaint(context, dc, skPaint, viewMatrix, &paint)) { if (!SkPaintToGrPaint(context, rtc, skPaint, viewMatrix, &paint)) {
return; return;
} }
@ -226,7 +226,7 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrContext* context, GrDrawContex
for (TextRun* run = iter.get(); run; run = iter.next()) { for (TextRun* run = iter.get(); run; run = iter.next()) {
// The run's "font" overrides the anti-aliasing of the passed in paint! // The run's "font" overrides the anti-aliasing of the passed in paint!
paint.setAntiAlias(run->isAntiAlias()); paint.setAntiAlias(run->isAntiAlias());
run->draw(context, dc, paint, clip, viewMatrix, props, x, y, run->draw(context, rtc, paint, clip, viewMatrix, props, x, y,
clipBounds, fFallbackTextContext, skPaint); clipBounds, fFallbackTextContext, skPaint);
run->releaseGlyphCache(); run->releaseGlyphCache();
} }
@ -596,7 +596,7 @@ inline void GrStencilAndCoverTextContext::TextRun::appendGlyph(const SkGlyph& gl
} }
void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx,
GrDrawContext* drawContext, GrRenderTargetContext* renderTargetContext,
const GrPaint& grPaint, const GrPaint& grPaint,
const GrClip& clip, const GrClip& clip,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -606,7 +606,7 @@ void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx,
GrAtlasTextContext* fallbackTextContext, GrAtlasTextContext* fallbackTextContext,
const SkPaint& originalSkPaint) const { const SkPaint& originalSkPaint) const {
SkASSERT(fInstanceData); SkASSERT(fInstanceData);
SkASSERT(drawContext->isStencilBufferMultisampled() || !grPaint.isAntiAlias()); SkASSERT(renderTargetContext->isStencilBufferMultisampled() || !grPaint.isAntiAlias());
if (fInstanceData->count()) { if (fInstanceData->count()) {
static constexpr GrUserStencilSettings kCoverPass( static constexpr GrUserStencilSettings kCoverPass(
@ -631,7 +631,8 @@ void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx,
// NV_path_rendering will also support NV_blend_equation_advanced. // NV_path_rendering will also support NV_blend_equation_advanced.
// For clipping we'll just skip any optimizations based on the bounds. This does, however, // For clipping we'll just skip any optimizations based on the bounds. This does, however,
// hurt batching. // hurt batching.
const SkRect bounds = SkRect::MakeIWH(drawContext->width(), drawContext->height()); const SkRect bounds = SkRect::MakeIWH(renderTargetContext->width(),
renderTargetContext->height());
SkAutoTUnref<GrDrawBatch> batch( SkAutoTUnref<GrDrawBatch> batch(
GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRatio * x, GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRatio * x,
@ -643,7 +644,7 @@ void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx,
pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, grPaint.isAntiAlias()); pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, grPaint.isAntiAlias());
pipelineBuilder.setUserStencil(&kCoverPass); pipelineBuilder.setUserStencil(&kCoverPass);
drawContext->drawBatch(pipelineBuilder, clip, batch); renderTargetContext->drawBatch(pipelineBuilder, clip, batch);
} }
if (fFallbackTextBlob) { if (fFallbackTextBlob) {
@ -653,8 +654,8 @@ void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx,
fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fTextRatio); fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fTextRatio);
} }
fallbackTextContext->drawTextBlob(ctx, drawContext, clip, fallbackSkPaint, viewMatrix, fallbackTextContext->drawTextBlob(ctx, renderTargetContext, clip, fallbackSkPaint,
props, fFallbackTextBlob.get(), x, y, nullptr, viewMatrix, props, fFallbackTextBlob.get(), x, y, nullptr,
clipBounds); clipBounds);
} }
} }

View File

@ -8,7 +8,7 @@
#ifndef GrStencilAndCoverTextContext_DEFINED #ifndef GrStencilAndCoverTextContext_DEFINED
#define GrStencilAndCoverTextContext_DEFINED #define GrStencilAndCoverTextContext_DEFINED
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrStyle.h" #include "GrStyle.h"
#include "SkDrawFilter.h" #include "SkDrawFilter.h"
#include "SkOpts.h" #include "SkOpts.h"
@ -31,18 +31,18 @@ class GrStencilAndCoverTextContext {
public: public:
static GrStencilAndCoverTextContext* Create(GrAtlasTextContext* fallbackTextContext); static GrStencilAndCoverTextContext* Create(GrAtlasTextContext* fallbackTextContext);
void drawText(GrContext*, GrDrawContext* dc, void drawText(GrContext*, GrRenderTargetContext* rtc,
const GrClip&, const GrPaint&, const SkPaint&, const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[], const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[],
size_t byteLength, SkScalar x, size_t byteLength, SkScalar x,
SkScalar y, const SkIRect& clipBounds); SkScalar y, const SkIRect& clipBounds);
void drawPosText(GrContext*, GrDrawContext*, void drawPosText(GrContext*, GrRenderTargetContext*,
const GrClip&, const GrPaint&, const SkPaint&, const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkMatrix& viewMatrix, const SkSurfaceProps&,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& clipBounds); const SkPoint& offset, const SkIRect& clipBounds);
void drawTextBlob(GrContext*, GrDrawContext*, const GrClip&, const SkPaint&, void drawTextBlob(GrContext*, GrRenderTargetContext*, const GrClip&, const SkPaint&,
const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*, const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*,
SkScalar x, SkScalar y, SkScalar x, SkScalar y,
SkDrawFilter*, const SkIRect& clipBounds); SkDrawFilter*, const SkIRect& clipBounds);
@ -58,7 +58,7 @@ private:
bool internalCanDraw(const SkPaint&); bool internalCanDraw(const SkPaint&);
void uncachedDrawTextBlob(GrContext*, GrDrawContext* dc, void uncachedDrawTextBlob(GrContext*, GrRenderTargetContext* rtc,
const GrClip& clip, const SkPaint& skPaint, const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const SkSurfaceProps&, const SkSurfaceProps&,
@ -79,7 +79,7 @@ private:
void setPosText(const char text[], size_t byteLength, const SkScalar pos[], void setPosText(const char text[], size_t byteLength, const SkScalar pos[],
int scalarsPerPosition, const SkPoint& offset); int scalarsPerPosition, const SkPoint& offset);
void draw(GrContext*, GrDrawContext*, const GrPaint&, const GrClip&, void draw(GrContext*, GrRenderTargetContext*, const GrPaint&, const GrClip&,
const SkMatrix&, const SkSurfaceProps&, const SkMatrix&, const SkSurfaceProps&,
SkScalar x, SkScalar y, const SkIRect& clipBounds, SkScalar x, SkScalar y, const SkIRect& clipBounds,
GrAtlasTextContext* fallbackTextContext, const SkPaint& originalSkPaint) const; GrAtlasTextContext* fallbackTextContext, const SkPaint& originalSkPaint) const;

View File

@ -12,7 +12,7 @@
#include "GrBlurUtils.h" #include "GrBlurUtils.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "SkDistanceFieldGen.h" #include "SkDistanceFieldGen.h"
#include "SkDrawProcs.h" #include "SkDrawProcs.h"
@ -468,7 +468,7 @@ bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFont
return true; return true;
} }
void GrTextUtils::DrawTextAsPath(GrContext* context, GrDrawContext* dc, void GrTextUtils::DrawTextAsPath(GrContext* context, GrRenderTargetContext* rtc,
const GrClip& clip, const GrClip& clip,
const SkPaint& skPaint, const SkMatrix& viewMatrix, const SkPaint& skPaint, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, SkScalar x, SkScalar y, const char text[], size_t byteLength, SkScalar x, SkScalar y,
@ -486,7 +486,7 @@ void GrTextUtils::DrawTextAsPath(GrContext* context, GrDrawContext* dc,
matrix.postTranslate(xpos - prevXPos, 0); matrix.postTranslate(xpos - prevXPos, 0);
if (iterPath) { if (iterPath) {
const SkPaint& pnt = iter.getPaint(); const SkPaint& pnt = iter.getPaint();
GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, *iterPath, GrBlurUtils::drawPathWithMaskFilter(context, rtc, clip, *iterPath,
pnt, viewMatrix, &matrix, clipBounds, false); pnt, viewMatrix, &matrix, clipBounds, false);
} }
prevXPos = xpos; prevXPos = xpos;
@ -494,7 +494,7 @@ void GrTextUtils::DrawTextAsPath(GrContext* context, GrDrawContext* dc,
} }
void GrTextUtils::DrawPosTextAsPath(GrContext* context, void GrTextUtils::DrawPosTextAsPath(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkSurfaceProps& props, const SkSurfaceProps& props,
const GrClip& clip, const GrClip& clip,
const SkPaint& origPaint, const SkMatrix& viewMatrix, const SkPaint& origPaint, const SkMatrix& viewMatrix,
@ -538,7 +538,7 @@ void GrTextUtils::DrawPosTextAsPath(GrContext* context,
matrix[SkMatrix::kMTransX] = loc.fX; matrix[SkMatrix::kMTransX] = loc.fX;
matrix[SkMatrix::kMTransY] = loc.fY; matrix[SkMatrix::kMTransY] = loc.fY;
GrBlurUtils::drawPathWithMaskFilter(context, dc, clip, *path, paint, GrBlurUtils::drawPathWithMaskFilter(context, rtc, clip, *path, paint,
viewMatrix, &matrix, clipBounds, false); viewMatrix, &matrix, clipBounds, false);
} }
} }

View File

@ -17,7 +17,7 @@ class GrBatchFontCache;
class GrBatchTextStrike; class GrBatchTextStrike;
class GrClip; class GrClip;
class GrContext; class GrContext;
class GrDrawContext; class GrRenderTargetContext;
class GrShaderCaps; class GrShaderCaps;
class SkGlyph; class SkGlyph;
class SkMatrix; class SkMatrix;
@ -68,13 +68,13 @@ public:
const SkPoint& offset); const SkPoint& offset);
// Functions for drawing text as paths // Functions for drawing text as paths
static void DrawTextAsPath(GrContext*, GrDrawContext*, const GrClip& clip, static void DrawTextAsPath(GrContext*, GrRenderTargetContext*, const GrClip& clip,
const SkPaint& origPaint, const SkMatrix& viewMatrix, const SkPaint& origPaint, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, SkScalar x, SkScalar y, const char text[], size_t byteLength, SkScalar x, SkScalar y,
const SkIRect& clipBounds); const SkIRect& clipBounds);
static void DrawPosTextAsPath(GrContext* context, static void DrawPosTextAsPath(GrContext* context,
GrDrawContext* dc, GrRenderTargetContext* rtc,
const SkSurfaceProps& props, const SkSurfaceProps& props,
const GrClip& clip, const GrClip& clip,
const SkPaint& origPaint, const SkMatrix& viewMatrix, const SkPaint& origPaint, const SkMatrix& viewMatrix,

View File

@ -12,7 +12,7 @@
#include "SkAutoPixmapStorage.h" #include "SkAutoPixmapStorage.h"
#include "GrCaps.h" #include "GrCaps.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrImageIDTextureAdjuster.h" #include "GrImageIDTextureAdjuster.h"
#include "GrTexturePriv.h" #include "GrTexturePriv.h"
#include "effects/GrYUVEffect.h" #include "effects/GrYUVEffect.h"
@ -251,13 +251,14 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac
const int height = yuvSizes[0].fHeight; const int height = yuvSizes[0].fHeight;
// Needs to be a render target in order to draw to it for the yuv->rgb conversion. // Needs to be a render target in order to draw to it for the yuv->rgb conversion.
sk_sp<GrDrawContext> drawContext(ctx->makeDrawContext(SkBackingFit::kExact, sk_sp<GrRenderTargetContext> renderTargetContext(ctx->makeRenderTargetContext(
width, height, SkBackingFit::kExact,
kRGBA_8888_GrPixelConfig, width, height,
std::move(imageColorSpace), kRGBA_8888_GrPixelConfig,
0, std::move(imageColorSpace),
origin)); 0,
if (!drawContext) { origin));
if (!renderTargetContext) {
return nullptr; return nullptr;
} }
@ -268,11 +269,11 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac
const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); renderTargetContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect);
ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); ctx->flushSurfaceWrites(renderTargetContext->accessRenderTarget());
return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID,
kOpaque_SkAlphaType, drawContext->asTexture(), kOpaque_SkAlphaType, renderTargetContext->asTexture(),
sk_ref_sp(drawContext->getColorSpace()), budgeted); sk_ref_sp(renderTargetContext->getColorSpace()), budgeted);
} }
sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace, sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace,

View File

@ -40,8 +40,8 @@ static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface,
// Grab the render target *after* firing notifications, as it may get switched if CoW kicks in. // Grab the render target *after* firing notifications, as it may get switched if CoW kicks in.
surface->getDevice()->flush(); surface->getDevice()->flush();
GrDrawContext* dc = surface->getDevice()->accessDrawContext(); GrRenderTargetContext* rtc = surface->getDevice()->accessRenderTargetContext();
return dc->accessRenderTarget(); return rtc->accessRenderTarget();
} }
GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) {
@ -67,8 +67,8 @@ SkCanvas* SkSurface_Gpu::onNewCanvas() {
} }
sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
int sampleCount = fDevice->accessDrawContext()->numColorSamples(); int sampleCount = fDevice->accessRenderTargetContext()->numColorSamples();
GrSurfaceOrigin origin = fDevice->accessDrawContext()->origin(); GrSurfaceOrigin origin = fDevice->accessRenderTargetContext()->origin();
// TODO: Make caller specify this (change virtual signature of onNewSurface). // TODO: Make caller specify this (change virtual signature of onNewSurface).
static const SkBudgeted kBudgeted = SkBudgeted::kNo; static const SkBudgeted kBudgeted = SkBudgeted::kNo;
return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, sampleCount, return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, sampleCount,
@ -76,7 +76,7 @@ sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
} }
sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, SkCopyPixelsMode cpm) { sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, SkCopyPixelsMode cpm) {
GrRenderTarget* rt = fDevice->accessDrawContext()->accessRenderTarget(); GrRenderTarget* rt = fDevice->accessRenderTargetContext()->accessRenderTarget();
SkASSERT(rt); SkASSERT(rt);
GrTexture* tex = rt->asTexture(); GrTexture* tex = rt->asTexture();
sk_sp<GrTexture> copy; sk_sp<GrTexture> copy;
@ -84,7 +84,7 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, SkCopyPixe
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid // want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
// copy-on-write. // copy-on-write.
if (kAlways_SkCopyPixelsMode == cpm || !tex || rt->resourcePriv().refsWrappedObjects()) { if (kAlways_SkCopyPixelsMode == cpm || !tex || rt->resourcePriv().refsWrappedObjects()) {
GrSurfaceDesc desc = fDevice->accessDrawContext()->desc(); GrSurfaceDesc desc = fDevice->accessRenderTargetContext()->desc();
GrContext* ctx = fDevice->context(); GrContext* ctx = fDevice->context();
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag; desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
copy.reset(ctx->textureProvider()->createTexture(desc, budgeted)); copy.reset(ctx->textureProvider()->createTexture(desc, budgeted));
@ -110,13 +110,13 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, SkCopyPixe
// render target into it. Note that this flushes the SkGpuDevice but // render target into it. Note that this flushes the SkGpuDevice but
// doesn't force an OpenGL flush. // doesn't force an OpenGL flush.
void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
GrRenderTarget* rt = fDevice->accessDrawContext()->accessRenderTarget(); GrRenderTarget* rt = fDevice->accessRenderTargetContext()->accessRenderTarget();
// are we sharing our render target with the image? Note this call should never create a new // are we sharing our render target with the image? Note this call should never create a new
// image because onCopyOnWrite is only called when there is a cached image. // image because onCopyOnWrite is only called when there is a cached image.
sk_sp<SkImage> image(this->refCachedImage(SkBudgeted::kNo, kNo_ForceUnique)); sk_sp<SkImage> image(this->refCachedImage(SkBudgeted::kNo, kNo_ForceUnique));
SkASSERT(image); SkASSERT(image);
if (rt->asTexture() == as_IB(image)->peekTexture()) { if (rt->asTexture() == as_IB(image)->peekTexture()) {
this->fDevice->replaceDrawContext(SkSurface::kRetain_ContentChangeMode == mode); this->fDevice->replaceRenderTargetContext(SkSurface::kRetain_ContentChangeMode == mode);
SkTextureImageApplyBudgetedDecision(image.get()); SkTextureImageApplyBudgetedDecision(image.get());
} else if (kDiscard_ContentChangeMode == mode) { } else if (kDiscard_ContentChangeMode == mode) {
this->SkSurface_Gpu::onDiscard(); this->SkSurface_Gpu::onDiscard();
@ -124,7 +124,7 @@ void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
} }
void SkSurface_Gpu::onDiscard() { void SkSurface_Gpu::onDiscard() {
fDevice->accessDrawContext()->discard(); fDevice->accessRenderTargetContext()->discard();
} }
void SkSurface_Gpu::onPrepareForExternalIO() { void SkSurface_Gpu::onPrepareForExternalIO() {
@ -192,16 +192,16 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
return nullptr; return nullptr;
} }
sk_sp<GrDrawContext> dc(context->contextPriv().makeBackendTextureDrawContext( sk_sp<GrRenderTargetContext> rtc(context->contextPriv().makeBackendTextureRenderTargetContext(
desc, desc,
std::move(colorSpace), std::move(colorSpace),
props, props,
kBorrow_GrWrapOwnership)); kBorrow_GrWrapOwnership));
if (!dc) { if (!rtc) {
return nullptr; return nullptr;
} }
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(dc), desc.fWidth, desc.fHeight, sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rtc), desc.fWidth, desc.fHeight,
SkGpuDevice::kUninit_InitContents)); SkGpuDevice::kUninit_InitContents));
if (!device) { if (!device) {
return nullptr; return nullptr;
@ -220,15 +220,15 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
return nullptr; return nullptr;
} }
sk_sp<GrDrawContext> dc(context->contextPriv().makeBackendRenderTargetDrawContext( sk_sp<GrRenderTargetContext> rtc(
desc, context->contextPriv().makeBackendRenderTargetRenderTargetContext(desc,
std::move(colorSpace), std::move(colorSpace),
props)); props));
if (!dc) { if (!rtc) {
return nullptr; return nullptr;
} }
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(dc), desc.fWidth, desc.fHeight, sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rtc), desc.fWidth, desc.fHeight,
SkGpuDevice::kUninit_InitContents)); SkGpuDevice::kUninit_InitContents));
if (!device) { if (!device) {
return nullptr; return nullptr;
@ -248,15 +248,16 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont
return nullptr; return nullptr;
} }
sk_sp<GrDrawContext> dc(context->contextPriv().makeBackendTextureAsRenderTargetDrawContext( sk_sp<GrRenderTargetContext> rtc(
desc, context->contextPriv().makeBackendTextureAsRenderTargetRenderTargetContext(
std::move(colorSpace), desc,
props)); std::move(colorSpace),
if (!dc) { props));
if (!rtc) {
return nullptr; return nullptr;
} }
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(dc), desc.fWidth, desc.fHeight, sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rtc), desc.fWidth, desc.fHeight,
SkGpuDevice::kUninit_InitContents)); SkGpuDevice::kUninit_InitContents));
if (!device) { if (!device) {
return nullptr; return nullptr;

View File

@ -9,15 +9,15 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrGpu.h" #include "GrGpu.h"
#include "GrRenderTarget.h" #include "GrRenderTarget.h"
#include "GrTexture.h" #include "GrTexture.h"
#include "GrTextureProvider.h" #include "GrTextureProvider.h"
static bool check_rect(GrDrawContext* dc, const SkIRect& rect, uint32_t expectedValue, static bool check_rect(GrRenderTargetContext* rtc, const SkIRect& rect, uint32_t expectedValue,
uint32_t* actualValue, int* failX, int* failY) { uint32_t* actualValue, int* failX, int* failY) {
GrRenderTarget* rt = dc->accessRenderTarget(); GrRenderTarget* rt = rtc->accessRenderTarget();
int w = rect.width(); int w = rect.width();
int h = rect.height(); int h = rect.height();
SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]); SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]);
@ -37,19 +37,20 @@ static bool check_rect(GrDrawContext* dc, const SkIRect& rect, uint32_t expected
return true; return true;
} }
static bool reset_dc(sk_sp<GrDrawContext>* dc, GrContext* context, int w, int h) { static bool reset_rtc(sk_sp<GrRenderTargetContext>* rtc, GrContext* context, int w, int h) {
SkDEBUGCODE(uint32_t oldID = 0;) SkDEBUGCODE(uint32_t oldID = 0;)
if (*dc) { if (*rtc) {
SkDEBUGCODE(oldID = (*dc)->accessRenderTarget()->uniqueID();) SkDEBUGCODE(oldID = (*rtc)->accessRenderTarget()->uniqueID();)
dc->reset(nullptr); rtc->reset(nullptr);
} }
context->freeGpuResources(); context->freeGpuResources();
*dc = context->makeDrawContext(SkBackingFit::kExact, w, h, kRGBA_8888_GrPixelConfig, nullptr); *rtc = context->makeRenderTargetContext(SkBackingFit::kExact, w, h, kRGBA_8888_GrPixelConfig,
nullptr);
SkASSERT((*dc)->accessRenderTarget()->uniqueID() != oldID); SkASSERT((*rtc)->accessRenderTarget()->uniqueID() != oldID);
return *dc != nullptr; return *rtc != nullptr;
} }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) {
@ -58,7 +59,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) {
static const int kH = 10; static const int kH = 10;
SkIRect fullRect = SkIRect::MakeWH(kW, kH); SkIRect fullRect = SkIRect::MakeWH(kW, kH);
sk_sp<GrDrawContext> drawContext; sk_sp<GrRenderTargetContext> rtContext;
// A rectangle that is inset by one on all sides and the 1-pixel wide rectangles that surround // A rectangle that is inset by one on all sides and the 1-pixel wide rectangles that surround
// it. // it.
@ -82,140 +83,140 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) {
static const GrColor kColor1 = 0xABCDEF01; static const GrColor kColor1 = 0xABCDEF01;
static const GrColor kColor2 = ~kColor1; static const GrColor kColor2 = ~kColor1;
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Check a full clear // Check a full clear
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Check two full clears, same color // Check two full clears, same color
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Check two full clears, different colors // Check two full clears, different colors
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
drawContext->clear(&fullRect, kColor2, false); rtContext->clear(&fullRect, kColor2, false);
if (!check_rect(drawContext.get(), fullRect, kColor2, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), fullRect, kColor2, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
failX, failY); failX, failY);
} }
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Test a full clear followed by a same color inset clear // Test a full clear followed by a same color inset clear
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
drawContext->clear(&mid1Rect, kColor1, false); rtContext->clear(&mid1Rect, kColor1, false);
if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Test a inset clear followed by same color full clear // Test a inset clear followed by same color full clear
drawContext->clear(&mid1Rect, kColor1, false); rtContext->clear(&mid1Rect, kColor1, false);
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Test a full clear followed by a different color inset clear // Test a full clear followed by a different color inset clear
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
drawContext->clear(&mid1Rect, kColor2, false); rtContext->clear(&mid1Rect, kColor2, false);
if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
failX, failY); failX, failY);
} }
if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || if (!check_rect(rtContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || !check_rect(rtContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || !check_rect(rtContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { !check_rect(rtContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Test a inset clear followed by a different full clear // Test a inset clear followed by a different full clear
drawContext->clear(&mid1Rect, kColor2, false); rtContext->clear(&mid1Rect, kColor2, false);
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Check three nested clears from largest to smallest where outermost and innermost are same // Check three nested clears from largest to smallest where outermost and innermost are same
// color. // color.
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
drawContext->clear(&mid1Rect, kColor2, false); rtContext->clear(&mid1Rect, kColor2, false);
drawContext->clear(&mid2Rect, kColor1, false); rtContext->clear(&mid2Rect, kColor1, false);
if (!check_rect(drawContext.get(), mid2Rect, kColor1, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), mid2Rect, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }
if (!check_rect(drawContext.get(), innerLeftEdge, kColor2, &actualValue, &failX, &failY) || if (!check_rect(rtContext.get(), innerLeftEdge, kColor2, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), innerTopEdge, kColor2, &actualValue, &failX, &failY) || !check_rect(rtContext.get(), innerTopEdge, kColor2, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), innerRightEdge, kColor2, &actualValue, &failX, &failY) || !check_rect(rtContext.get(), innerRightEdge, kColor2, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), innerBottomEdge, kColor2, &actualValue, &failX, &failY)) { !check_rect(rtContext.get(), innerBottomEdge, kColor2, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
failX, failY); failX, failY);
} }
if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || if (!check_rect(rtContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || !check_rect(rtContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || !check_rect(rtContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { !check_rect(rtContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }
if (!reset_dc(&drawContext, context, kW, kH)) { if (!reset_rtc(&rtContext, context, kW, kH)) {
ERRORF(reporter, "Could not create draw context."); ERRORF(reporter, "Could not create render target context.");
return; return;
} }
// Swap the order of the second two clears in the above test. // Swap the order of the second two clears in the above test.
drawContext->clear(&fullRect, kColor1, false); rtContext->clear(&fullRect, kColor1, false);
drawContext->clear(&mid2Rect, kColor1, false); rtContext->clear(&mid2Rect, kColor1, false);
drawContext->clear(&mid1Rect, kColor2, false); rtContext->clear(&mid1Rect, kColor2, false);
if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) { if (!check_rect(rtContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
failX, failY); failX, failY);
} }
if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || if (!check_rect(rtContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || !check_rect(rtContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || !check_rect(rtContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
!check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { !check_rect(rtContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
failX, failY); failX, failY);
} }

View File

@ -17,7 +17,7 @@
// Because of inaccuracies in large floating point values this causes the // Because of inaccuracies in large floating point values this causes the
// the path renderer to attempt to add a path DF to its atlas that is larger // the path renderer to attempt to add a path DF to its atlas that is larger
// than the plot size which used to crash rather than fail gracefully. // than the plot size which used to crash rather than fail gracefully.
static void test_far_from_origin(GrDrawContext* drawContext, GrPathRenderer* pr, static void test_far_from_origin(GrRenderTargetContext* renderTargetContext, GrPathRenderer* pr,
GrResourceProvider* rp) { GrResourceProvider* rp) {
SkPath path; SkPath path;
path.lineTo(49.0255089839f, 0.473541f); path.lineTo(49.0255089839f, 0.473541f);
@ -48,7 +48,7 @@ static void test_far_from_origin(GrDrawContext* drawContext, GrPathRenderer* pr,
GrPathRenderer::DrawPathArgs args; GrPathRenderer::DrawPathArgs args;
args.fPaint = &paint; args.fPaint = &paint;
args.fUserStencilSettings = &GrUserStencilSettings::kUnused; args.fUserStencilSettings = &GrUserStencilSettings::kUnused;
args.fDrawContext = drawContext; args.fRenderTargetContext = renderTargetContext;
args.fClip = &noClip; args.fClip = &noClip;
args.fResourceProvider = rp; args.fResourceProvider = rp;
args.fViewMatrix = &matrix; args.fViewMatrix = &matrix;
@ -63,22 +63,23 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(AADistanceFieldPathRenderer, reporter, ctxInfo)
if (!ctxInfo.grContext()->caps()->shaderCaps()->shaderDerivativeSupport()) { if (!ctxInfo.grContext()->caps()->shaderCaps()->shaderDerivativeSupport()) {
return; return;
} }
sk_sp<GrDrawContext> dc(ctxInfo.grContext()->makeDrawContext(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> rtc(ctxInfo.grContext()->makeRenderTargetContext(
800, 800, SkBackingFit::kApprox,
kRGBA_8888_GrPixelConfig, 800, 800,
nullptr, kRGBA_8888_GrPixelConfig,
0, nullptr,
kTopLeft_GrSurfaceOrigin)); 0,
if (!dc) { kTopLeft_GrSurfaceOrigin));
if (!rtc) {
return; return;
} }
GrAADistanceFieldPathRenderer dfpr; GrAADistanceFieldPathRenderer dfpr;
GrTestTarget tt; GrTestTarget tt;
ctxInfo.grContext()->getTestTarget(&tt, dc); ctxInfo.grContext()->getTestTarget(&tt, rtc);
GrResourceProvider* rp = tt.resourceProvider(); GrResourceProvider* rp = tt.resourceProvider();
test_far_from_origin(dc.get(), &dfpr, rp); test_far_from_origin(rtc.get(), &dfpr, rp);
ctxInfo.grContext()->flush(); ctxInfo.grContext()->flush();
} }
#endif #endif

View File

@ -15,7 +15,7 @@
#include "GrBatchTest.h" #include "GrBatchTest.h"
#include "GrContextFactory.h" #include "GrContextFactory.h"
#include "GrContextPriv.h" #include "GrContextPriv.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrDrawingManager.h" #include "GrDrawingManager.h"
#include "GrInvariantOutput.h" #include "GrInvariantOutput.h"
#include "GrPipeline.h" #include "GrPipeline.h"
@ -148,21 +148,22 @@ private:
static const int kRenderTargetHeight = 1; static const int kRenderTargetHeight = 1;
static const int kRenderTargetWidth = 1; static const int kRenderTargetWidth = 1;
static sk_sp<GrDrawContext> random_draw_context(GrContext* context, static sk_sp<GrRenderTargetContext> random_render_target_context(GrContext* context,
SkRandom* random, SkRandom* random,
const GrCaps* caps) { const GrCaps* caps) {
GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin
: kBottomLeft_GrSurfaceOrigin; : kBottomLeft_GrSurfaceOrigin;
int sampleCnt = random->nextBool() ? SkTMin(4, caps->maxSampleCount()) : 0; int sampleCnt = random->nextBool() ? SkTMin(4, caps->maxSampleCount()) : 0;
sk_sp<GrDrawContext> drawContext(context->makeDrawContext(SkBackingFit::kExact, sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
kRenderTargetWidth, SkBackingFit::kExact,
kRenderTargetHeight, kRenderTargetWidth,
kRGBA_8888_GrPixelConfig, kRenderTargetHeight,
nullptr, kRGBA_8888_GrPixelConfig,
sampleCnt, nullptr,
origin)); sampleCnt,
return drawContext; origin));
return renderTargetContext;
} }
static void set_random_xpf(GrPaint* paint, GrProcessorTestData* d) { static void set_random_xpf(GrPaint* paint, GrProcessorTestData* d) {
@ -320,9 +321,10 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
static const int NUM_TESTS = 1024; static const int NUM_TESTS = 1024;
for (int t = 0; t < NUM_TESTS; t++) { for (int t = 0; t < NUM_TESTS; t++) {
// setup random render target(can fail) // setup random render target(can fail)
sk_sp<GrDrawContext> drawContext(random_draw_context(context, &random, context->caps())); sk_sp<GrRenderTargetContext> renderTargetContext(random_render_target_context(
if (!drawContext) { context, &random, context->caps()));
SkDebugf("Could not allocate drawContext"); if (!renderTargetContext) {
SkDebugf("Could not allocate renderTargetContext");
return false; return false;
} }
@ -332,25 +334,27 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
SkASSERT(batch); SkASSERT(batch);
GrProcessorTestData ptd(&random, context, context->caps(), GrProcessorTestData ptd(&random, context, context->caps(),
drawContext.get(), dummyTextures); renderTargetContext.get(), dummyTextures);
set_random_color_coverage_stages(&grPaint, &ptd, maxStages); set_random_color_coverage_stages(&grPaint, &ptd, maxStages);
set_random_xpf(&grPaint, &ptd); set_random_xpf(&grPaint, &ptd);
bool snapToCenters = set_random_state(&grPaint, &random); bool snapToCenters = set_random_state(&grPaint, &random);
const GrUserStencilSettings* uss = get_random_stencil(&random); const GrUserStencilSettings* uss = get_random_stencil(&random);
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch, uss, snapToCenters); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint, batch, uss,
snapToCenters);
} }
// Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes) // Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
drawingManager->flush(); drawingManager->flush();
// Validate that GrFPs work correctly without an input. // Validate that GrFPs work correctly without an input.
sk_sp<GrDrawContext> drawContext(context->makeDrawContext(SkBackingFit::kExact, sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
kRenderTargetWidth, SkBackingFit::kExact,
kRenderTargetHeight, kRenderTargetWidth,
kRGBA_8888_GrPixelConfig, kRenderTargetHeight,
nullptr)); kRGBA_8888_GrPixelConfig,
if (!drawContext) { nullptr));
SkDebugf("Could not allocate a drawContext"); if (!renderTargetContext) {
SkDebugf("Could not allocate a renderTargetContext");
return false; return false;
} }
@ -361,7 +365,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
SkASSERT(batch); SkASSERT(batch);
GrProcessorTestData ptd(&random, context, context->caps(), GrProcessorTestData ptd(&random, context, context->caps(),
drawContext.get(), dummyTextures); renderTargetContext.get(), dummyTextures);
GrPaint grPaint; GrPaint grPaint;
grPaint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); grPaint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode));
@ -371,7 +375,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
BlockInputFragmentProcessor::Make(std::move(fp))); BlockInputFragmentProcessor::Make(std::move(fp)));
grPaint.addColorFragmentProcessor(std::move(blockFP)); grPaint.addColorFragmentProcessor(std::move(blockFP));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint, batch);
drawingManager->flush(); drawingManager->flush();
} }
} }

View File

@ -12,8 +12,8 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrBatchFlushState.h" #include "GrBatchFlushState.h"
#include "GrDrawContext.h" #include "GrRenderTargetContext.h"
#include "GrDrawContextPriv.h" #include "GrRenderTargetContextPriv.h"
#include "GrContext.h" #include "GrContext.h"
#include "GrGeometryProcessor.h" #include "GrGeometryProcessor.h"
#include "GrGpu.h" #include "GrGpu.h"
@ -104,11 +104,12 @@ private:
DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext(); GrContext* context = ctxInfo.grContext();
sk_sp<GrDrawContext> drawContext(context->makeDrawContext(SkBackingFit::kApprox, sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
1, 1, kRGBA_8888_GrPixelConfig, SkBackingFit::kApprox,
nullptr)); 1, 1, kRGBA_8888_GrPixelConfig,
if (!drawContext) { nullptr));
ERRORF(reporter, "Could not create draw context."); if (!renderTargetContext) {
ERRORF(reporter, "Could not create render target context.");
return; return;
} }
int attribCnt = context->caps()->maxVertexAttributes(); int attribCnt = context->caps()->maxVertexAttributes();
@ -126,7 +127,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) {
GrPaint grPaint; GrPaint grPaint;
// This one should succeed. // This one should succeed.
batch.reset(new Batch(attribCnt)); batch.reset(new Batch(attribCnt));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint, batch);
context->flush(); context->flush();
#if GR_GPU_STATS #if GR_GPU_STATS
REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 1); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 1);
@ -135,7 +136,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) {
context->resetGpuStats(); context->resetGpuStats();
// This one should fail. // This one should fail.
batch.reset(new Batch(attribCnt+1)); batch.reset(new Batch(attribCnt+1));
drawContext->drawContextPriv().testingOnly_drawBatch(grPaint, batch); renderTargetContext->renderTargetContextPriv().testingOnly_drawBatch(grPaint, batch);
context->flush(); context->flush();
#if GR_GPU_STATS #if GR_GPU_STATS
REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0); REPORTER_ASSERT(reporter, context->getGpu()->stats()->numDraws() == 0);

Some files were not shown because too many files have changed in this diff Show More