aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--samplecode/SampleApp.cpp2
-rw-r--r--samplecode/SampleApp.h2
-rw-r--r--site/user/api/canvas.md35
-rw-r--r--site/user/sample/pdf.md29
-rw-r--r--src/utils/SkLua.cpp4
-rw-r--r--tools/fiddle/fiddle_main.cpp2
-rw-r--r--tools/skhello.cpp2
7 files changed, 40 insertions, 36 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index ba2e6ccad1..6500612a52 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -1379,7 +1379,7 @@ SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
#ifdef SK_BUILD_FOR_ANDROID
name.prepend("/sdcard/");
#endif
- fPDFDocument.reset(SkDocument::CreatePDF(name.c_str()));
+ fPDFDocument = SkDocument::MakePDF(name.c_str());
canvas = fPDFDocument->beginPage(this->width(), this->height());
} else if (fSaveToSKP) {
canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0);
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index c56bcd4488..18e75640d7 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -181,7 +181,7 @@ private:
bool fSaveToPdf;
bool fSaveToSKP;
- SkAutoTUnref<SkDocument> fPDFDocument;
+ sk_sp<SkDocument> fPDFDocument;
bool fUseClip;
bool fUsePicture;
diff --git a/site/user/api/canvas.md b/site/user/api/canvas.md
index cf9992d348..afeb68514f 100644
--- a/site/user/api/canvas.md
+++ b/site/user/api/canvas.md
@@ -37,13 +37,13 @@ the memory into which the canvas commands are drawn.
void raster(int width, int height,
void(*draw)(SkCanvas*),
const char* path) {
- SkAutoTUnref<SkSurface> rasterSurface(
- SkSurface::NewRasterN32Premul(width, height));
+ sk_sp<SkSurface> rasterSurface(
+ SkSurface::MakeRasterN32Premul(width, height));
SkCanvas* rasterCanvas = rasterSurface->getCanvas();
draw(rasterCanvas);
- SkAutoTUnref<SkImage> img(s->newImageSnapshot());
+ sk_sp<SkImage> img(s->newImageSnapshot());
if (!img) { return; }
- SkAutoTUnref<SkData> png(img->encode());
+ sk_sp<SkData> png(img->encode());
if (!png) { return; }
SkFILEWStream out(path);
(void)out.write(png->data(), png->size());
@@ -60,8 +60,8 @@ explicitly, instead of asking Skia to manage it.
size_t rowBytes = info.minRowBytes();
size_t size = info.getSafeSize(rowBytes);
std::vector<char> pixelMemory(size); // allocate memory
- SkAutoTUnref<SkSurface> surface(
- SkSurface::NewRasterDirect(
+ sk_sp<SkSurface> surface(
+ SkSurface::MakeRasterDirect(
info, &pixelMemory[0], rowBytes));
SkCanvas* canvas = surface.getCanvas();
draw(canvas);
@@ -89,17 +89,17 @@ example, we use a `GrContextFactory` to create a context.
GrContextFactory grFactory;
GrContext* context = grFactory.get(GrContextFactory::kNative_GLContextType);
SkImageInfo info = SkImageInfo:: MakeN32Premul(width, height);
- SkAutoTUnref<SkSurface> gpuSurface(
- SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info));
+ sk_sp<SkSurface> gpuSurface(
+ SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
if (!gpuSurface) {
- SkDebugf("SkSurface::NewRenderTarget returned null\n");
+ SkDebugf("SkSurface::MakeRenderTarget returned null\n");
return;
}
SkCanvas* gpuCanvas = gpuSurface->getCanvas();
draw(gpuCanvas);
- SkAutoTUnref<SkImage> img(s->newImageSnapshot());
+ sk_sp<SkImage> img(s->newImageSnapshot());
if (!img) { return; }
- SkAutoTUnref<SkData> png(img->encode());
+ sk_sp<SkData> png(img->encode());
if (!png) { return; }
SkFILEWStream out(path);
(void)out.write(png->data(), png->size());
@@ -120,7 +120,7 @@ a document must include multiple pages.
void(*draw)(SkCanvas*),
const char* path) {
SkFILEWStream pdfStream(path);
- SkAutoTUnref<SkDocument> pdfDoc(SkDocument::CreatePDF(&pdfStream));
+ sk_sp<SkDocument> pdfDoc(SkDocument::MakePDF(&pdfStream));
SkCanvas* pdfCanvas = pdfDoc->beginPage(SkIntToScalar(width),
SkIntToScalar(height));
draw(pdfCanvas);
@@ -145,7 +145,7 @@ The SkPicture backend uses SkPictureRecorder instead of SkSurface.
SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
SkIntToScalar(height));
draw(recordingCanvas);
- SkAutoTUnref<SkPicture> picture(recorder.endRecordingAsPicture());
+ sk_sp<SkPicture> picture(recorder.endRecordingAsPicture());
SkFILEWStream skpStream(path);
// Open SKP files with `SampleApp --picture SKP_FILE`
picture->serialize(&skpStream);
@@ -162,7 +162,7 @@ nothing.
#include "SkNullCanvas.h"
void picture(int, int, void(*draw)(SkCanvas*), const char*) {
- SkAutoTDelete<SkCanvas> nullCanvas(SkCreateNullCanvas());
+ sk_sp<SkCanvas> nullCanvas(SkCreateNullCanvas());
draw(nullCanvas); // NoOp
}
@@ -180,7 +180,7 @@ The (*still experimental*) SkXPS canvas writes into an XPS document.
void(*draw)(SkCanvas*),
const char* path) {
SkFILEWStream xpsStream(path);
- SkAutoTUnref<SkDocument> xpsDoc(SkDocument::CreateXPS(&pdfStream));
+ sk_sp<SkDocument> xpsDoc(SkDocument::MakeXPS(&pdfStream));
SkCanvas* xpsCanvas = xpsDoc->beginPage(SkIntToScalar(width),
SkIntToScalar(height));
draw(xpsCanvas);
@@ -202,8 +202,9 @@ The (*still experimental*) SkSVG canvas writes into an SVG document.
void(*draw)(SkCanvas*),
const char* path) {
SkFILEWStream svgStream(path);
- SkAutoTDelete<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(&svgStream));
- SkAutoTUnref<SkCanvas> svgCanvas(SkSVGCanvas::Create(
+ std::unique_ptr<SkXMLWriter> xmlWriter(
+ new SkXMLStreamWriter(&svgStream));
+ sk_sp<SkCanvas> svgCanvas(SkSVGCanvas::Create(
SkRect::MakeWH(SkIntToScalar(src.size().width()),
SkIntToScalar(src.size().height())),
xmlWriter));
diff --git a/site/user/sample/pdf.md b/site/user/sample/pdf.md
index 360fb4d023..1668f3939a 100644
--- a/site/user/sample/pdf.md
+++ b/site/user/sample/pdf.md
@@ -9,19 +9,22 @@ via the SkDocument and SkCanvas APIs.
#include "SkDocument.h"
bool WritePDF(SkWStream* outputStream) {
- sk_sp<SkDocument> pdfDocument(SkDocument::CreatePDF(outputStream));
- typedef SkDocument::Attribute Attr;
- Attr info[] = {
- Attr(SkString("Title"), SkString("....")),
- Attr(SkString("Author"), SkString("....")),
- Attr(SkString("Subject"), SkString("....")),
- Attr(SkString("Keywords"), SkString("....")),
- Attr(SkString("Creator"), SkString("....")),
- };
- int infoCount = sizeof(info) / sizeof(info[0]);
- SkTime::DateTime now;
- SkTime::GetDateTime(&now);
- pdfDocument->setMetadata(info, infoCount, &now, &now);
+ SkDocument::PDFMetadata metadata;
+ metadata.fCreator = "creator....";
+ metadata.fTitle = "title...";
+ metadata.fAuthor = "author...";
+ metadata.fSubject = "subject...";
+ metadata.fKeywords = "keywords...";
+ metadata.fCreator = "creator...";
+ SkTime::DateTime now = get_current_date_and_time();
+ metadata.fCreation.fEnabled = true;
+ metadata.fCreation.fDateTime = now;
+ metadata.fModified.fEnabled = true;
+ metadata.fModified.fDateTime = now;
+ sk_sp<SkDocument> pdfDocument(SkDocument::MakePDF(
+ outputStream, SK_ScalarDefaultRasterDPI, metadata,
+ nullptr, true);
+ assert(pdfDocument);
int numberOfPages = ....;
for (int page = 0; page < numberOfPages; ++page) {
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 9369a6bd9d..886f3d4ffd 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -1950,12 +1950,12 @@ static int lsk_newDocumentPDF(lua_State* L) {
file = lua_tolstring(L, 1, nullptr);
}
- SkDocument* doc = SkDocument::CreatePDF(file);
+ sk_sp<SkDocument> doc = SkDocument::MakePDF(file);
if (nullptr == doc) {
// do I need to push a nil on the stack and return 1?
return 0;
} else {
- push_ref(L, doc)->unref();
+ push_ref(L, std::move(doc));
return 1;
}
}
diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp
index 3e1570813d..bf7a032b44 100644
--- a/tools/fiddle/fiddle_main.cpp
+++ b/tools/fiddle/fiddle_main.cpp
@@ -137,7 +137,7 @@ int main() {
}
if (options.pdf) {
SkDynamicMemoryWStream pdfStream;
- sk_sp<SkDocument> document(SkDocument::CreatePDF(&pdfStream));
+ sk_sp<SkDocument> document(SkDocument::MakePDF(&pdfStream));
draw(document->beginPage(options.size.width(), options.size.height()));
document->close();
pdfData.reset(pdfStream.copyToData());
diff --git a/tools/skhello.cpp b/tools/skhello.cpp
index d033641bf1..f7d5b9a00e 100644
--- a/tools/skhello.cpp
+++ b/tools/skhello.cpp
@@ -48,7 +48,7 @@ static bool do_surface(int w, int h, const char path[], const char text[],
static bool do_document(int w, int h, const char path[], const char text[],
const SkPaint& paint) {
- SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path));
+ sk_sp<SkDocument> doc(SkDocument::MakePDF(path));
if (doc.get()) {
SkScalar width = SkIntToScalar(w);
SkScalar height = SkIntToScalar(h);