Change SkCanvas to *not* inherit from SkRefCnt

Definitely tricky for classes like SkNWayCanvas, where the caller (today)
need not pay attention to ownership of the canvases it gave the NWay
(after this CL, the caller *must* managed ownership)

BUG=skia:

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

DOCS_PREVIEW= https://skia.org/?cl=4441

Change-Id: Ib1ac07a3cdf0686d78e7aaa4735d45cc90bea081
Reviewed-on: https://skia-review.googlesource.com/4441
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Mike Reed 2016-11-09 13:59:58 -05:00 committed by Skia Commit-Bot
parent c78eff9754
commit 8240750718
33 changed files with 125 additions and 98 deletions

View File

@ -1192,8 +1192,7 @@ Name MSKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const {
std::unique_ptr<SkCanvas> canvas(SkCreateNullCanvas());
return src.draw(canvas.get());
return src.draw(SkMakeNullCanvas().get());
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@ -1356,7 +1355,7 @@ Error DebugSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) cons
if (!err.isEmpty()) {
return err;
}
sk_sp<SkCanvas> nullCanvas(SkCreateNullCanvas());
std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
UrlDataManager dataManager(SkString("data"));
Json::Value json = debugCanvas.toJSON(
dataManager, debugCanvas.getSize(), nullCanvas.get());
@ -1371,10 +1370,9 @@ SVGSink::SVGSink() {}
Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
#if defined(SK_XML)
std::unique_ptr<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(dst));
sk_sp<SkCanvas> canvas(SkSVGCanvas::Create(
SkRect::MakeWH(SkIntToScalar(src.size().width()), SkIntToScalar(src.size().height())),
xmlWriter.get()));
return src.draw(canvas.get());
return src.draw(SkSVGCanvas::Make(SkRect::MakeWH(SkIntToScalar(src.size().width()),
SkIntToScalar(src.size().height())),
xmlWriter.get()).get());
#else
return Error("SVG sink is disabled.");
#endif // SK_XML

View File

@ -8,6 +8,7 @@
#include "gm.h"
#include "SkCanvas.h"
#include "SkPath.h"
#include "SkMakeUnique.h"
static void do_draw(SkCanvas* canvas, const SkRect& r) {
SkPaint paint;
@ -166,14 +167,14 @@ DEF_GM(return new AAClipGM;)
#ifdef SK_BUILD_FOR_MAC
static SkCanvas* make_canvas(const SkBitmap& bm) {
static std::unique_ptr<SkCanvas> make_canvas(const SkBitmap& bm) {
const SkImageInfo& info = bm.info();
if (info.bytesPerPixel() == 4) {
return SkCanvas::NewRasterDirectN32(info.width(), info.height(),
(SkPMColor*)bm.getPixels(),
bm.rowBytes());
return SkCanvas::MakeRasterDirectN32(info.width(), info.height(),
(SkPMColor*)bm.getPixels(),
bm.rowBytes());
} else {
return new SkCanvas(bm);
return skstd::make_unique<SkCanvas>(bm);
}
}
@ -182,7 +183,6 @@ static void test_image(SkCanvas* canvas, const SkImageInfo& info) {
SkBitmap bm;
bm.allocPixels(info);
sk_sp<SkCanvas> newc(make_canvas(bm));
if (info.isOpaque()) {
bm.eraseColor(SK_ColorGREEN);
} else {
@ -192,7 +192,7 @@ static void test_image(SkCanvas* canvas, const SkImageInfo& info) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorBLUE);
newc->drawCircle(50, 50, 49, paint);
make_canvas(bm)->drawCircle(50, 50, 49, paint);
canvas->drawBitmap(bm, 10, 10);
CGImageRef image = SkCreateCGImageRefWithColorspace(bm, nullptr);

View File

@ -12,6 +12,7 @@ android_framework_defines = [
"SK_SUPPORT_LEGACY_GRADIENT_DITHERING",
"SK_SUPPORT_LEGACY_DRAWFILTER",
"SK_IGNORE_GPU_DITHER",
"SK_SUPPORT_LEGACY_CANVAS_IS_REFCNT",
"SK_SUPPORT_LEGACY_CLIP_REGIONOPS",
"SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
]

View File

@ -60,7 +60,13 @@ class SkTextBlob;
color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
etc.
*/
class SK_API SkCanvas : public SkRefCnt {
class SK_API SkCanvas
#ifdef SK_SUPPORT_LEGACY_CANVAS_IS_REFCNT
: public SkRefCnt
#else
: SkNoncopyable
#endif
{
enum PrivateSaveLayerFlags {
kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31,
};
@ -100,11 +106,22 @@ public:
* Note: it is valid to request a supported ImageInfo, but with zero
* dimensions.
*/
static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t);
static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo&, void*, size_t);
static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
size_t rowBytes) {
return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
}
#ifdef SK_SUPPORT_LEGACY_CANVAS_IS_REFCNT
static SkCanvas* NewRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes) {
return MakeRasterDirect(info, pixels, rowBytes).release();
}
static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) {
return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
return MakeRasterDirectN32(width, height, pixels, rowBytes).release();
}
#endif
/**
* Creates an empty canvas with no backing device/pixels, and zero

View File

@ -57,7 +57,7 @@ public:
private:
struct DrawData {
SkCanvas* fCanvas; // reffed
SkCanvas* fCanvas;
const SkPicture* fPicture; // reffed
SkMatrix fMatrix;
SkPaint* fPaint; // owned

View File

@ -111,13 +111,13 @@ private:
friend class SkPictureRecorderReplayTester; // for unit testing
void partialReplay(SkCanvas* canvas) const;
bool fActivelyRecording;
uint32_t fFlags;
SkRect fCullRect;
sk_sp<SkBBoxHierarchy> fBBH;
sk_sp<SkRecorder> fRecorder;
sk_sp<SkRecord> fRecord;
SkMiniRecorder fMiniRecorder;
bool fActivelyRecording;
uint32_t fFlags;
SkRect fCullRect;
sk_sp<SkBBoxHierarchy> fBBH;
std::unique_ptr<SkRecorder> fRecorder;
sk_sp<SkRecord> fRecord;
SkMiniRecorder fMiniRecorder;
typedef SkNoncopyable INHERITED;
};

View File

@ -25,7 +25,13 @@ public:
* The 'bounds' parameter defines an initial SVG viewport (viewBox attribute on the root
* SVG element).
*/
static SkCanvas* Create(const SkRect& bounds, SkXMLWriter*);
static std::unique_ptr<SkCanvas> Make(const SkRect& bounds, SkXMLWriter*);
#ifdef SK_SUPPORT_LEGACY_CANVAS_IS_REFCNT
static SkCanvas* Create(const SkRect& bounds, SkXMLWriter* writer) {
return Make(bounds, writer).release();
}
#endif
};
#endif

View File

@ -62,7 +62,12 @@ public:
* identical to the captured canvas. The caller is responsible for
* calling unref on the SkCanvas.
*/
static SkCanvas* CreateFromCanvasState(const SkCanvasState* state);
static std::unique_ptr<SkCanvas> MakeFromCanvasState(const SkCanvasState* state);
#ifdef SK_SUPPORT_LEGACY_CANVAS_IS_REFCNT
static SkCanvas* CreateFromCanvasState(const SkCanvasState* state) {
return MakeFromCanvasState(state).release();
}
#endif
/**
* Free the memory associated with the captured canvas state. The state

View File

@ -15,6 +15,12 @@ class SkCanvas;
/**
* Creates a canvas that draws nothing. This is useful for performance testing.
*/
SK_API SkCanvas* SkCreateNullCanvas();
SK_API std::unique_ptr<SkCanvas> SkMakeNullCanvas();
#ifdef SK_SUPPORT_LEGACY_CANVAS_IS_REFCNT
static inline SkCanvas* SkCreateNullCanvas() {
return SkMakeNullCanvas().release();
}
#endif
#endif

View File

@ -600,6 +600,7 @@ DEFINES_ALL = [
"GOOGLE3",
# Staging flags for API changes
"SK_SUPPORT_LEGACY_ACCESSBITMAP",
"SK_SUPPORT_LEGACY_CANVAS_IS_REFCNT",
"SK_SUPPORT_LEGACY_CLIP_REGIONOPS",
]

View File

@ -629,8 +629,8 @@ static void path_fuzz_stroker(SkBitmap* bitmap, int seed) {
const SkPath& path = fuzzPath.getPath();
const SkPaint& paint = fuzzPath.getPaint();
const SkImageInfo& info = bitmap->info();
SkCanvas* canvas(
SkCanvas::NewRasterDirect(info, bitmap->getPixels(), bitmap->rowBytes()));
std::unique_ptr<SkCanvas> canvas(
SkCanvas::MakeRasterDirect(info, bitmap->getPixels(), bitmap->rowBytes()));
int w = info.width() / 4;
int h = info.height() / 4;
int x = localSeed / 4 % 4;

View File

@ -19,6 +19,7 @@
#include "SkImageFilter.h"
#include "SkImageFilterCache.h"
#include "SkLatticeIter.h"
#include "SkMakeUnique.h"
#include "SkMatrixUtils.h"
#include "SkMetaData.h"
#include "SkNx.h"
@ -3323,7 +3324,8 @@ static bool supported_for_raster_canvas(const SkImageInfo& info) {
return true;
}
SkCanvas* SkCanvas::NewRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes) {
std::unique_ptr<SkCanvas> SkCanvas::MakeRasterDirect(const SkImageInfo& info, void* pixels,
size_t rowBytes) {
if (!supported_for_raster_canvas(info)) {
return nullptr;
}
@ -3332,7 +3334,7 @@ SkCanvas* SkCanvas::NewRasterDirect(const SkImageInfo& info, void* pixels, size_
if (!bitmap.installPixels(info, pixels, rowBytes)) {
return nullptr;
}
return new SkCanvas(bitmap);
return skstd::make_unique<SkCanvas>(bitmap);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -354,8 +354,8 @@ bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t
if (!bm.installPixels(srcInfo, const_cast<void*>(srcPixels), srcRB, ctable, nullptr, nullptr)) {
return false;
}
sk_sp<SkCanvas> canvas(SkCanvas::NewRasterDirect(dstInfo, dstPixels, dstRB));
if (nullptr == canvas.get()) {
std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(dstInfo, dstPixels, dstRB);
if (!canvas) {
return false;
}

View File

@ -18,7 +18,7 @@ void SkMultiPictureDraw::DrawData::draw() {
void SkMultiPictureDraw::DrawData::init(SkCanvas* canvas, const SkPicture* picture,
const SkMatrix* matrix, const SkPaint* paint) {
fPicture = SkRef(picture);
fCanvas = SkRef(canvas);
fCanvas = canvas;
if (matrix) {
fMatrix = *matrix;
} else {
@ -34,7 +34,6 @@ void SkMultiPictureDraw::DrawData::init(SkCanvas* canvas, const SkPicture* pictu
void SkMultiPictureDraw::DrawData::Reset(SkTDArray<DrawData>& data) {
for (int i = 0; i < data.count(); ++i) {
data[i].fPicture->unref();
data[i].fCanvas->unref();
delete data[i].fPaint;
}
data.rewind();

View File

@ -29,7 +29,7 @@ public:
virtual sk_sp<SkSpecialImage> onMakeImageSnapshot() = 0;
protected:
sk_sp<SkCanvas> fCanvas; // initialized by derived classes in ctors
std::unique_ptr<SkCanvas> fCanvas; // initialized by derived classes in ctors
private:
typedef SkSpecialSurface INHERITED;

View File

@ -58,14 +58,12 @@ SkSurfaceProps::SkSurfaceProps(const SkSurfaceProps& other)
SkSurface_Base::SkSurface_Base(int width, int height, const SkSurfaceProps* props)
: INHERITED(width, height, props)
{
fCachedCanvas = nullptr;
fCachedImage = nullptr;
}
SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const SkSurfaceProps* props)
: INHERITED(info, props)
{
fCachedCanvas = nullptr;
fCachedImage = nullptr;
}
@ -76,7 +74,6 @@ SkSurface_Base::~SkSurface_Base() {
}
SkSafeUnref(fCachedImage);
SkSafeUnref(fCachedCanvas);
}
void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {

View File

@ -89,8 +89,8 @@ public:
uint32_t newGenerationID();
private:
SkCanvas* fCachedCanvas;
SkImage* fCachedImage;
std::unique_ptr<SkCanvas> fCachedCanvas;
SkImage* fCachedImage;
void aboutToDraw(ContentChangeMode mode);
@ -106,12 +106,12 @@ private:
SkCanvas* SkSurface_Base::getCachedCanvas() {
if (nullptr == fCachedCanvas) {
fCachedCanvas = this->onNewCanvas();
fCachedCanvas = std::unique_ptr<SkCanvas>(this->onNewCanvas());
if (fCachedCanvas) {
fCachedCanvas->setSurfaceBase(this);
}
}
return fCachedCanvas;
return fCachedCanvas.get();
}
sk_sp<SkImage> SkSurface_Base::refCachedImage(SkBudgeted budgeted, ForceUnique unique) {

View File

@ -217,7 +217,7 @@ SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height,
SkScalarRoundToInt(width), SkScalarRoundToInt(height));
fPageDevice.reset(
SkPDFDevice::Create(pageSize, fRasterDpi, this));
fCanvas = sk_make_sp<SkPDFCanvas>(fPageDevice);
fCanvas.reset(new SkPDFCanvas(fPageDevice));
fCanvas->clipRect(trimBox);
fCanvas->translate(trimBox.x(), trimBox.y());
return fCanvas.get();

View File

@ -76,7 +76,7 @@ private:
SkTHashSet<SkPDFFont*> fFonts;
sk_sp<SkPDFDict> fDests;
sk_sp<SkPDFDevice> fPageDevice;
sk_sp<SkCanvas> fCanvas;
std::unique_ptr<SkCanvas> fCanvas;
sk_sp<SkPDFObject> fID;
sk_sp<SkPDFObject> fXMP;
SkScalar fRasterDpi;

View File

@ -7,11 +7,12 @@
#include "SkSVGCanvas.h"
#include "SkSVGDevice.h"
#include "SkMakeUnique.h"
SkCanvas* SkSVGCanvas::Create(const SkRect& bounds, SkXMLWriter* writer) {
std::unique_ptr<SkCanvas> SkSVGCanvas::Make(const SkRect& bounds, SkXMLWriter* writer) {
// TODO: pass full bounds to the device
SkISize size = bounds.roundOut().size();
sk_sp<SkBaseDevice> device(SkSVGDevice::Create(size, writer));
return new SkCanvas(device.get());
return skstd::make_unique<SkCanvas>(device.get());
}

View File

@ -100,14 +100,12 @@ class SkCanvasState_v1 : public SkCanvasState {
public:
static const int32_t kVersion = 1;
SkCanvasState_v1(SkCanvas* canvas)
: INHERITED(kVersion, canvas)
{
SkCanvasState_v1(SkCanvas* canvas) : INHERITED(kVersion, canvas) {
layerCount = 0;
layers = nullptr;
mcState.clipRectCount = 0;
mcState.clipRects = nullptr;
originalCanvas = SkRef(canvas);
originalCanvas = canvas;
}
~SkCanvasState_v1() {
@ -118,10 +116,6 @@ public:
sk_free(mcState.clipRects);
sk_free(layers);
// it is now safe to free the canvas since there should be no remaining
// references to the content that is referenced by this canvas (e.g. pixels)
originalCanvas->unref();
}
SkMCState mcState;
@ -284,7 +278,8 @@ static void setup_canvas_from_MC_state(const SkMCState& state, SkCanvas* canvas)
canvas->clipRegion(clip, SkCanvas::kReplace_Op);
}
static SkCanvas* create_canvas_from_canvas_layer(const SkCanvasLayerState& layerState) {
static std::unique_ptr<SkCanvas>
make_canvas_from_canvas_layer(const SkCanvasLayerState& layerState) {
SkASSERT(kRaster_CanvasBackend == layerState.type);
SkBitmap bitmap;
@ -304,15 +299,15 @@ static SkCanvas* create_canvas_from_canvas_layer(const SkCanvasLayerState& layer
SkASSERT(!bitmap.empty());
SkASSERT(!bitmap.isNull());
sk_sp<SkCanvas> canvas(new SkCanvas(bitmap));
std::unique_ptr<SkCanvas> canvas(new SkCanvas(bitmap));
// setup the matrix and clip
setup_canvas_from_MC_state(layerState.mcState, canvas.get());
return canvas.release();
return canvas;
}
SkCanvas* SkCanvasStateUtils::CreateFromCanvasState(const SkCanvasState* state) {
std::unique_ptr<SkCanvas> SkCanvasStateUtils::MakeFromCanvasState(const SkCanvasState* state) {
SkASSERT(state);
// Currently there is only one possible version.
SkASSERT(SkCanvasState_v1::kVersion == state->version);
@ -323,14 +318,14 @@ SkCanvas* SkCanvasStateUtils::CreateFromCanvasState(const SkCanvasState* state)
return nullptr;
}
sk_sp<SkCanvasStack> canvas(new SkCanvasStack(state->width, state->height));
std::unique_ptr<SkCanvasStack> canvas(new SkCanvasStack(state->width, state->height));
// setup the matrix and clip on the n-way canvas
setup_canvas_from_MC_state(state_v1->mcState, canvas.get());
// Iterate over the layers and add them to the n-way canvas
for (int i = state_v1->layerCount - 1; i >= 0; --i) {
sk_sp<SkCanvas> canvasLayer(create_canvas_from_canvas_layer(state_v1->layers[i]));
std::unique_ptr<SkCanvas> canvasLayer = make_canvas_from_canvas_layer(state_v1->layers[i]);
if (!canvasLayer.get()) {
return nullptr;
}
@ -338,7 +333,7 @@ SkCanvas* SkCanvasStateUtils::CreateFromCanvasState(const SkCanvasState* state)
state_v1->layers[i].y));
}
return canvas.release();
return std::move(canvas);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -73,6 +73,13 @@ template <typename T> void push_obj(lua_State* L, const T& obj) {
lua_setmetatable(L, -2);
}
template <typename T> T* push_ptr(lua_State* L, T* ptr) {
*(T**)lua_newuserdata(L, sizeof(T*)) = ptr;
luaL_getmetatable(L, get_mtname<T>());
lua_setmetatable(L, -2);
return ptr;
}
template <typename T> T* push_ref(lua_State* L, T* ref) {
*(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref);
luaL_getmetatable(L, get_mtname<T>());
@ -333,7 +340,7 @@ void SkLua::pushPath(const SkPath& path, const char key[]) {
}
void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) {
push_ref(fL, canvas);
push_ptr(fL, canvas);
CHECK_SETFIELD(key);
}
@ -715,7 +722,7 @@ static int lcanvas_newSurface(lua_State* L) {
}
static int lcanvas_gc(lua_State* L) {
get_ref<SkCanvas>(L, 1)->unref();
// don't know how to track a ptr...
return 0;
}
@ -757,7 +764,7 @@ const struct luaL_Reg gSkCanvas_Methods[] = {
static int ldocument_beginPage(lua_State* L) {
const SkRect* contentPtr = nullptr;
push_ref(L, get_ref<SkDocument>(L, 1)->beginPage(lua2scalar(L, 2),
push_ptr(L, get_ref<SkDocument>(L, 1)->beginPage(lua2scalar(L, 2),
lua2scalar(L, 3),
contentPtr));
return 1;
@ -1750,7 +1757,7 @@ static int lsurface_getCanvas(lua_State* L) {
if (nullptr == canvas) {
lua_pushnil(L);
} else {
push_ref(L, canvas);
push_ptr(L, canvas);
// note: we don't unref canvas, since getCanvas did not ref it.
// warning: this is weird: now Lua owns a ref on this canvas, but what if they let
// the real owner (the surface) go away, but still hold onto the canvas?
@ -1814,7 +1821,7 @@ static int lpicturerecorder_beginRecording(lua_State* L) {
return 1;
}
push_ref(L, canvas);
push_ptr(L, canvas);
return 1;
}
@ -1824,7 +1831,7 @@ static int lpicturerecorder_getCanvas(lua_State* L) {
lua_pushnil(L);
return 1;
}
push_ref(L, canvas);
push_ptr(L, canvas);
return 1;
}

View File

@ -15,7 +15,6 @@ SkNWayCanvas::~SkNWayCanvas() {
void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
if (canvas) {
canvas->ref();
*fList.append() = canvas;
}
}
@ -23,13 +22,11 @@ void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
int index = fList.find(canvas);
if (index >= 0) {
canvas->unref();
fList.removeShuffle(index);
}
}
void SkNWayCanvas::removeAll() {
fList.unrefAll();
fList.reset();
}

View File

@ -9,10 +9,10 @@
#include "SkCanvas.h"
#include "SkNWayCanvas.h"
#include "SkMakeUnique.h"
SkCanvas* SkCreateNullCanvas() {
std::unique_ptr<SkCanvas> SkMakeNullCanvas() {
// An N-Way canvas forwards calls to N canvas's. When N == 0 it's
// effectively a null canvas.
return new SkNWayCanvas(0, 0);
return std::unique_ptr<SkCanvas>(new SkNWayCanvas(0, 0));
}

View File

@ -58,7 +58,7 @@ protected:
private:
SkXPSDevice fDevice;
sk_sp<SkCanvas> fCanvas;
std::unique_ptr<SkCanvas> fCanvas;
SkVector fUnitsPerMeter;
SkVector fPixelsPerMeter;
};

View File

@ -27,12 +27,11 @@ void complex_layers_draw(SkCanvas* canvas, float left, float top,
extern "C" bool complex_layers_draw_from_canvas_state(SkCanvasState* state,
float left, float top, float right, float bottom, int32_t spacer) {
SkCanvas* canvas = SkCanvasStateUtils::CreateFromCanvasState(state);
std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
if (!canvas) {
return false;
}
complex_layers_draw(canvas, left, top, right, bottom, spacer);
canvas->unref();
complex_layers_draw(canvas.get(), left, top, right, bottom, spacer);
return true;
}
@ -52,7 +51,7 @@ void complex_clips_draw(SkCanvas* canvas, int32_t left, int32_t top,
extern "C" bool complex_clips_draw_from_canvas_state(SkCanvasState* state,
int32_t left, int32_t top, int32_t right, int32_t bottom, int32_t clipOp,
int32_t regionRects, int32_t* rectCoords) {
SkCanvas* canvas = SkCanvasStateUtils::CreateFromCanvasState(state);
std::unique_ptr<SkCanvas> canvas = SkCanvasStateUtils::MakeFromCanvasState(state);
if (!canvas) {
return false;
}
@ -64,8 +63,7 @@ extern "C" bool complex_clips_draw_from_canvas_state(SkCanvasState* state,
rectCoords += 4;
}
complex_clips_draw(canvas, left, top, right, bottom, clipOp, localRegion);
canvas->unref();
complex_clips_draw(canvas.get(), left, top, right, bottom, clipOp, localRegion);
return true;
}
#endif // SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG

View File

@ -278,13 +278,12 @@ DEF_TEST(CanvasState_test_draw_filters, reporter) {
SkCanvasState* state = SkCanvasStateUtils::CaptureCanvasState(&canvas);
REPORTER_ASSERT(reporter, state);
SkCanvas* tmpCanvas = SkCanvasStateUtils::CreateFromCanvasState(state);
std::unique_ptr<SkCanvas> tmpCanvas = SkCanvasStateUtils::MakeFromCanvasState(state);
REPORTER_ASSERT(reporter, tmpCanvas);
REPORTER_ASSERT(reporter, canvas.getDrawFilter());
REPORTER_ASSERT(reporter, nullptr == tmpCanvas->getDrawFilter());
tmpCanvas->unref();
SkCanvasStateUtils::ReleaseCanvasState(state);
}

View File

@ -542,7 +542,7 @@ static void test_newraster(skiatest::Reporter* reporter) {
SkPMColor* baseAddr = storage.get();
sk_bzero(baseAddr, size);
SkCanvas* canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes);
std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes);
REPORTER_ASSERT(reporter, canvas);
SkPixmap pmap;
@ -556,25 +556,23 @@ static void test_newraster(skiatest::Reporter* reporter) {
}
addr = (const SkPMColor*)((const char*)addr + pmap.rowBytes());
}
delete canvas;
// now try a deliberately bad info
info = info.makeWH(-1, info.height());
REPORTER_ASSERT(reporter, nullptr == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
// too big
info = info.makeWH(1 << 30, 1 << 30);
REPORTER_ASSERT(reporter, nullptr == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
// not a valid pixel type
info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType());
REPORTER_ASSERT(reporter, nullptr == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
// We should succeed with a zero-sized valid info
info = SkImageInfo::MakeN32Premul(0, 0);
canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes);
canvas = SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes);
REPORTER_ASSERT(reporter, canvas);
delete canvas;
}
DEF_TEST(Canvas, reporter) {

View File

@ -18,7 +18,7 @@
#include "SkPictureRecorder.h"
static void drain(SkPipeDeserializer* deserial, SkDynamicMemoryWStream* stream) {
std::unique_ptr<SkCanvas> canvas(SkCreateNullCanvas());
std::unique_ptr<SkCanvas> canvas = SkMakeNullCanvas();
sk_sp<SkData> data = stream->detachAsData();
deserial->playback(data->data(), data->size(), canvas.get());
}

View File

@ -91,7 +91,7 @@ void test_whitespace_pos(skiatest::Reporter* reporter,
{
SkXMLParserWriter writer(dom.beginParsing());
sk_sp<SkCanvas> svgCanvas(SkSVGCanvas::Create(SkRect::MakeWH(100, 100), &writer));
std::unique_ptr<SkCanvas> svgCanvas = SkSVGCanvas::Make(SkRect::MakeWH(100, 100), &writer);
svgCanvas->drawText(txt, len, offset.x(), offset.y(), paint);
}
check_text_node(reporter, dom, dom.finishParsing(), offset, 0, expected);
@ -103,7 +103,7 @@ void test_whitespace_pos(skiatest::Reporter* reporter,
}
SkXMLParserWriter writer(dom.beginParsing());
sk_sp<SkCanvas> svgCanvas(SkSVGCanvas::Create(SkRect::MakeWH(100, 100), &writer));
std::unique_ptr<SkCanvas> svgCanvas = SkSVGCanvas::Make(SkRect::MakeWH(100, 100), &writer);
svgCanvas->drawPosTextH(txt, len, xpos, offset.y(), paint);
}
check_text_node(reporter, dom, dom.finishParsing(), offset, 1, expected);
@ -115,7 +115,7 @@ void test_whitespace_pos(skiatest::Reporter* reporter,
}
SkXMLParserWriter writer(dom.beginParsing());
sk_sp<SkCanvas> svgCanvas(SkSVGCanvas::Create(SkRect::MakeWH(100, 100), &writer));
std::unique_ptr<SkCanvas> svgCanvas = SkSVGCanvas::Make(SkRect::MakeWH(100, 100), &writer);
svgCanvas->drawPosText(txt, len, pos, paint);
}
check_text_node(reporter, dom, dom.finishParsing(), offset, 2, expected);

View File

@ -145,7 +145,7 @@ int tool_main(int argc, char** argv) {
auto pic(load_picture(path));
if (pic.get()) {
sk_sp<SkLuaCanvas> canvas(
std::unique_ptr<SkLuaCanvas> canvas(
new SkLuaCanvas(SkScalarCeilToInt(pic->cullRect().width()),
SkScalarCeilToInt(pic->cullRect().height()),
L.get(), gAccumulateFunc));

View File

@ -63,7 +63,7 @@ struct Request {
SkColor getPixel(int x, int y);
UploadContext* fUploadContext;
sk_sp<SkDebugCanvas> fDebugCanvas;
std::unique_ptr<SkDebugCanvas> fDebugCanvas;
UrlDataManager fUrlDataManager;
private:

View File

@ -34,7 +34,7 @@ int main(int argc, char** argv) {
SkISize size = pic->cullRect().roundOut().size();
SkDebugCanvas debugCanvas(size.width(), size.height());
pic->playback(&debugCanvas);
sk_sp<SkCanvas> nullCanvas(SkCreateNullCanvas());
std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
UrlDataManager dataManager(SkString("data"));
Json::Value json = debugCanvas.toJSON(
dataManager, debugCanvas.getSize(), nullCanvas.get());