| Index: gm/xfermodes3.cpp
|
| diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp
|
| index 4466b1ce0472f3212bd1442f20aa16ecb82869d5..f59e80f757ca72c14dee8834e5e0e455d45fa38f 100644
|
| --- a/gm/xfermodes3.cpp
|
| +++ b/gm/xfermodes3.cpp
|
| @@ -1,13 +1,14 @@
|
| -
|
| /*
|
| * Copyright 2013 Google Inc.
|
| *
|
| * Use of this source code is governed by a BSD-style license that can be
|
| * found in the LICENSE file.
|
| */
|
| +
|
| #include "gm.h"
|
| #include "SkBitmap.h"
|
| #include "SkGradientShader.h"
|
| +#include "SkSurface.h"
|
| #include "SkXfermode.h"
|
| #include "SkColorPriv.h"
|
|
|
| @@ -59,7 +60,7 @@ protected:
|
| 0x80,
|
| };
|
|
|
| - SkAutoTUnref<SkCanvas> tempCanvas(this->possiblyCreateTempCanvas(canvas, kSize, kSize));
|
| + SkAutoTUnref<SkSurface> tempSurface(this->possiblyCreateTempSurface(canvas, kSize, kSize));
|
|
|
| int test = 0;
|
| int x = 0, y = 0;
|
| @@ -82,7 +83,7 @@ protected:
|
| modePaint.setStyle(kStrokes[s].fStyle);
|
| modePaint.setStrokeWidth(kStrokes[s].fWidth);
|
|
|
| - this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempCanvas.get());
|
| + this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSurface);
|
|
|
| ++test;
|
| x += kSize + 10;
|
| @@ -99,7 +100,7 @@ protected:
|
| modePaint.setStyle(kStrokes[s].fStyle);
|
| modePaint.setStrokeWidth(kStrokes[s].fWidth);
|
|
|
| - this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempCanvas.get());
|
| + this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSurface);
|
|
|
| ++test;
|
| x += kSize + 10;
|
| @@ -121,37 +122,32 @@ private:
|
| * So when running on a GPU canvas we explicitly create a temporary canvas using a texture with
|
| * dimensions exactly matching the layer size.
|
| */
|
| - SkCanvas* possiblyCreateTempCanvas(SkCanvas* baseCanvas, int w, int h) {
|
| - SkCanvas* tempCanvas = nullptr;
|
| + SkSurface* possiblyCreateTempSurface(SkCanvas* baseCanvas, int w, int h) {
|
| #if SK_SUPPORT_GPU
|
| GrContext* context = baseCanvas->getGrContext();
|
| SkImageInfo baseInfo = baseCanvas->imageInfo();
|
| SkImageInfo info = SkImageInfo::Make(w, h, baseInfo.colorType(), baseInfo.alphaType(),
|
| baseInfo.profileType());
|
| - SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted,
|
| - info, 0, nullptr));
|
| - if (surface) {
|
| - tempCanvas = SkRef(surface->getCanvas());
|
| - }
|
| + return SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr);
|
| +#else
|
| + return nullptr;
|
| #endif
|
| - return tempCanvas;
|
| }
|
|
|
| void drawMode(SkCanvas* canvas,
|
| int x, int y, int w, int h,
|
| - const SkPaint& modePaint, SkCanvas* layerCanvas) {
|
| + const SkPaint& modePaint, SkSurface* surface) {
|
| canvas->save();
|
| -
|
| canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
| SkRect r = SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h));
|
|
|
| SkCanvas* modeCanvas;
|
| - if (nullptr == layerCanvas) {
|
| + if (nullptr == surface) {
|
| canvas->saveLayer(&r, nullptr);
|
| modeCanvas = canvas;
|
| } else {
|
| - modeCanvas = layerCanvas;
|
| + modeCanvas = surface->getCanvas();
|
| }
|
|
|
| SkPaint bgPaint;
|
| @@ -161,14 +157,10 @@ private:
|
| modeCanvas->drawRect(r, modePaint);
|
| modeCanvas = nullptr;
|
|
|
| - if (nullptr == layerCanvas) {
|
| + if (nullptr == surface) {
|
| canvas->restore();
|
| } else {
|
| - SkAutoROCanvasPixels ropixels(layerCanvas);
|
| - SkBitmap bitmap;
|
| - if (ropixels.asROBitmap(&bitmap)) {
|
| - canvas->drawBitmap(bitmap, 0, 0);
|
| - }
|
| + surface->draw(canvas, 0, 0, nullptr);
|
| }
|
|
|
| r.inset(-SK_ScalarHalf, -SK_ScalarHalf);
|
|
|