aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-01-03 09:23:34 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-03 15:30:29 +0000
commit7c9c9e4239b6e9dfec3469326312e4c9a2c164f9 (patch)
tree90ce9f6812c6b1c0565b74f578bbab77d922baae
parent2823f9f06c15fd581e7518dc4e674ad56917dcdb (diff)
update pipe for lattice and shadowrec
- move some lattice routines into shared helper (SkCanvasPriv) Bug: skia: Change-Id: Ibbb80dd7461c7fd3082a0220604ab42cbb8815be Reviewed-on: https://skia-review.googlesource.com/90540 Reviewed-by: Florin Malita <fmalita@chromium.org> Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Mike Reed <reed@google.com>
-rw-r--r--gn/core.gni1
-rw-r--r--src/core/SkCanvas.cpp30
-rw-r--r--src/core/SkCanvasPriv.cpp85
-rw-r--r--src/core/SkCanvasPriv.h15
-rw-r--r--src/core/SkPicturePlayback.cpp20
-rw-r--r--src/core/SkPictureRecord.cpp20
-rw-r--r--src/pipe/SkPipeCanvas.cpp42
-rw-r--r--src/pipe/SkPipeCanvas.h1
-rw-r--r--src/pipe/SkPipeFormat.h3
-rw-r--r--src/pipe/SkPipeReader.cpp33
10 files changed, 139 insertions, 111 deletions
diff --git a/gn/core.gni b/gn/core.gni
index 939c0599a7..3a059fe730 100644
--- a/gn/core.gni
+++ b/gn/core.gni
@@ -59,6 +59,7 @@ skia_core_sources = [
"$_src/core/SkBuffer.cpp",
"$_src/core/SkCachedData.cpp",
"$_src/core/SkCanvas.cpp",
+ "$_src/core/SkCanvasPriv.cpp",
"$_src/core/SkCanvasPriv.h",
"$_src/core/SkCoverageDelta.h",
"$_src/core/SkCoverageDelta.cpp",
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 7643c5164b..2429f5600f 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2909,32 +2909,6 @@ std::unique_ptr<SkCanvas> SkCanvas::MakeRasterDirect(const SkImageInfo& info, vo
///////////////////////////////////////////////////////////////////////////////
-SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatrix* matrix,
- const SkPaint* paint, const SkRect& bounds)
- : fCanvas(canvas)
- , fSaveCount(canvas->getSaveCount())
-{
- if (paint) {
- SkRect newBounds = bounds;
- if (matrix) {
- matrix->mapRect(&newBounds);
- }
- canvas->saveLayer(&newBounds, paint);
- } else if (matrix) {
- canvas->save();
- }
-
- if (matrix) {
- canvas->concat(*matrix);
- }
-}
-
-SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
- fCanvas->restoreToCount(fSaveCount);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
SkNoDrawCanvas::SkNoDrawCanvas(int width, int height)
: INHERITED(SkIRect::MakeWH(width, height), kConservativeRasterClip_InitFlag) {}
@@ -3008,3 +2982,7 @@ SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<SkRasterHandleAllocator> all
}
return hndl ? std::unique_ptr<SkCanvas>(new SkCanvas(bm, std::move(alloc), hndl)) : nullptr;
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/core/SkCanvasPriv.cpp b/src/core/SkCanvasPriv.cpp
new file mode 100644
index 0000000000..35c9866398
--- /dev/null
+++ b/src/core/SkCanvasPriv.cpp
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkAutoMalloc.h"
+#include "SkCanvasPriv.h"
+#include "SkReadBuffer.h"
+#include "SkWriter32.h"
+
+SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatrix* matrix,
+ const SkPaint* paint, const SkRect& bounds)
+: fCanvas(canvas)
+, fSaveCount(canvas->getSaveCount())
+{
+ if (paint) {
+ SkRect newBounds = bounds;
+ if (matrix) {
+ matrix->mapRect(&newBounds);
+ }
+ canvas->saveLayer(&newBounds, paint);
+ } else if (matrix) {
+ canvas->save();
+ }
+
+ if (matrix) {
+ canvas->concat(*matrix);
+ }
+}
+
+SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
+ fCanvas->restoreToCount(fSaveCount);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+bool SkCanvasPriv::ReadLattice(SkReadBuffer& buffer, SkCanvas::Lattice* lattice) {
+ lattice->fXCount = buffer.readInt();
+ lattice->fXDivs = buffer.skipT<int32_t>(lattice->fXCount);
+ lattice->fYCount = buffer.readInt();
+ lattice->fYDivs = buffer.skipT<int32_t>(lattice->fYCount);
+ int flagCount = buffer.readInt();
+ lattice->fRectTypes = nullptr;
+ lattice->fColors = nullptr;
+ if (flagCount) {
+ lattice->fRectTypes = buffer.skipT<SkCanvas::Lattice::RectType>(flagCount);
+ lattice->fColors = buffer.skipT<SkColor>(flagCount);
+ }
+ lattice->fBounds = buffer.skipT<SkIRect>();
+ return buffer.isValid();
+}
+
+size_t SkCanvasPriv::WriteLattice(void* buffer, const SkCanvas::Lattice& lattice) {
+ int flagCount = lattice.fRectTypes ? (lattice.fXCount + 1) * (lattice.fYCount + 1) : 0;
+
+ const size_t size = (1 + lattice.fXCount + 1 + lattice.fYCount + 1) * sizeof(int32_t) +
+ SkAlign4(flagCount * sizeof(SkCanvas::Lattice::RectType)) +
+ SkAlign4(flagCount * sizeof(SkColor)) +
+ sizeof(SkIRect);
+
+ if (buffer) {
+ SkWriter32 writer(buffer, size);
+ writer.write32(lattice.fXCount);
+ writer.write(lattice.fXDivs, lattice.fXCount * sizeof(uint32_t));
+ writer.write32(lattice.fYCount);
+ writer.write(lattice.fYDivs, lattice.fYCount * sizeof(uint32_t));
+ writer.write32(flagCount);
+ writer.writePad(lattice.fRectTypes, flagCount * sizeof(uint8_t));
+ writer.write(lattice.fColors, flagCount * sizeof(SkColor));
+ SkASSERT(lattice.fBounds);
+ writer.write(lattice.fBounds, sizeof(SkIRect));
+ SkASSERT(writer.bytesWritten() == size);
+ }
+ return size;
+};
+
+void SkCanvasPriv::WriteLattice(SkWriteBuffer& buffer, const SkCanvas::Lattice& lattice) {
+ const size_t size = WriteLattice(nullptr, lattice);
+ SkAutoSMalloc<1024> storage(size);
+ WriteLattice(storage.get(), lattice);
+ buffer.writePad32(storage.get(), size);
+}
+
diff --git a/src/core/SkCanvasPriv.h b/src/core/SkCanvasPriv.h
index dfae154ecb..12d9fce027 100644
--- a/src/core/SkCanvasPriv.h
+++ b/src/core/SkCanvasPriv.h
@@ -10,6 +10,9 @@
#include "SkCanvas.h"
+class SkReadBuffer;
+class SkWriteBuffer;
+
class SkAutoCanvasMatrixPaint : SkNoncopyable {
public:
SkAutoCanvasMatrixPaint(SkCanvas*, const SkMatrix*, const SkPaint*, const SkRect& bounds);
@@ -20,4 +23,16 @@ private:
int fSaveCount;
};
+class SkCanvasPriv {
+public:
+ // The lattice has pointers directly into the readbuffer
+ static bool ReadLattice(SkReadBuffer&, SkCanvas::Lattice*);
+
+ static void WriteLattice(SkWriteBuffer&, const SkCanvas::Lattice&);
+
+ // return the byte-size of the lattice, even if the buffer is null
+ // storage must be 4-byte aligned
+ static size_t WriteLattice(void* storage, const SkCanvas::Lattice&);
+};
+
#endif
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index c5aebe3602..4b9e080264 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -6,6 +6,7 @@
*/
#include "SkCanvas.h"
+#include "SkCanvasPriv.h"
#include "SkDrawShadowInfo.h"
#include "SkPaintPriv.h"
#include "SkPatchUtils.h"
@@ -360,24 +361,11 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getImage(reader);
SkCanvas::Lattice lattice;
- lattice.fXCount = reader->readInt();
- lattice.fXDivs = (const int*) reader->skip(lattice.fXCount, sizeof(int32_t));
- lattice.fYCount = reader->readInt();
- lattice.fYDivs = (const int*) reader->skip(lattice.fYCount, sizeof(int32_t));
- int flagCount = reader->readInt();
- lattice.fRectTypes = (0 == flagCount) ? nullptr :
- (const SkCanvas::Lattice::RectType*)
- reader->skip(SkAlign4(flagCount * sizeof(SkCanvas::Lattice::RectType)));
- lattice.fColors = (0 == flagCount) ? nullptr : (const SkColor*)
- reader->skip(SkAlign4(flagCount * sizeof(SkColor)));
- SkIRect src;
- reader->readIRect(&src);
- lattice.fBounds = &src;
- SkRect dst;
- reader->readRect(&dst);
+ (void)SkCanvasPriv::ReadLattice(*reader, &lattice);
+ const SkRect* dst = reader->skipT<SkRect>();
BREAK_ON_READ_ERROR(reader);
- canvas->drawImageLattice(image, lattice, dst, paint);
+ canvas->drawImageLattice(image, lattice, *dst, paint);
} break;
case DRAW_IMAGE_NINE: {
const SkPaint* paint = fPictureData->getPaint(reader);
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 8a7b5cfa50..5a3e8be2dd 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -6,6 +6,7 @@
*/
#include "SkPictureRecord.h"
+#include "SkCanvasPriv.h"
#include "SkDrawShadowInfo.h"
#include "SkImage_Base.h"
#include "SkMatrixPriv.h"
@@ -549,28 +550,13 @@ void SkPictureRecord::onDrawImageNine(const SkImage* img, const SkIRect& center,
void SkPictureRecord::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
const SkRect& dst, const SkPaint* paint) {
- // xCount + xDivs + yCount+ yDivs
- int flagCount = (nullptr == lattice.fRectTypes) ? 0 :
- (lattice.fXCount + 1) * (lattice.fYCount + 1);
- size_t latticeSize = (1 + lattice.fXCount + 1 + lattice.fYCount + 1) * kUInt32Size +
- SkAlign4(flagCount * sizeof(SkCanvas::Lattice::RectType)) +
- SkAlign4(flagCount * sizeof(SkColor)) +
- sizeof(SkIRect);
-
+ size_t latticeSize = SkCanvasPriv::WriteLattice(nullptr, lattice);
// op + paint index + image index + lattice + dst rect
size_t size = 3 * kUInt32Size + latticeSize + sizeof(dst);
size_t initialOffset = this->addDraw(DRAW_IMAGE_LATTICE, &size);
this->addPaintPtr(paint);
this->addImage(image);
- this->addInt(lattice.fXCount);
- fWriter.writePad(lattice.fXDivs, lattice.fXCount * kUInt32Size);
- this->addInt(lattice.fYCount);
- fWriter.writePad(lattice.fYDivs, lattice.fYCount * kUInt32Size);
- this->addInt(flagCount);
- fWriter.writePad(lattice.fRectTypes, flagCount * sizeof(SkCanvas::Lattice::RectType));
- fWriter.writePad(lattice.fColors, flagCount * sizeof(SkColor));
- SkASSERT(lattice.fBounds);
- this->addIRect(*lattice.fBounds);
+ (void)SkCanvasPriv::WriteLattice(fWriter.reservePad(latticeSize), lattice);
this->addRect(dst);
this->validate(initialOffset, size);
}
diff --git a/src/pipe/SkPipeCanvas.cpp b/src/pipe/SkPipeCanvas.cpp
index ee1e77167c..3d0e69569c 100644
--- a/src/pipe/SkPipeCanvas.cpp
+++ b/src/pipe/SkPipeCanvas.cpp
@@ -6,8 +6,10 @@
*/
#include "SkAutoMalloc.h"
+#include "SkCanvasPriv.h"
#include "SkColorFilter.h"
#include "SkDrawLooper.h"
+#include "SkDrawShadowInfo.h"
#include "SkImageFilter.h"
#include "SkMaskFilter.h"
#include "SkPathEffect.h"
@@ -448,6 +450,13 @@ void SkPipeCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
write_paint(writer, paint, kGeometry_PaintUsage);
}
+void SkPipeCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
+ SkPipeWriter writer(this);
+ writer.write32(pack_verb(SkPipeVerb::kDrawShadowRec));
+ writer.writePath(path);
+ writer.write(&rec, sizeof(rec));
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
static sk_sp<SkImage> make_from_bitmap(const SkBitmap& bitmap) {
@@ -555,41 +564,10 @@ void SkPipeCanvas::onDrawImageLattice(const SkImage* image, const Lattice& latti
if (paint) {
extra |= kHasPaint_DrawImageLatticeMask;
}
- if (lattice.fRectTypes) {
- extra |= kHasFlags_DrawImageLatticeMask;
- }
- if (lattice.fXCount >= kCount_DrawImageLatticeMask) {
- extra |= kCount_DrawImageLatticeMask << kXCount_DrawImageLatticeShift;
- } else {
- extra |= lattice.fXCount << kXCount_DrawImageLatticeShift;
- }
- if (lattice.fYCount >= kCount_DrawImageLatticeMask) {
- extra |= kCount_DrawImageLatticeMask << kYCount_DrawImageLatticeShift;
- } else {
- extra |= lattice.fYCount << kYCount_DrawImageLatticeShift;
- }
-
SkPipeWriter writer(this);
writer.write32(pack_verb(SkPipeVerb::kDrawImageLattice, extra));
writer.writeImage(image);
- if (lattice.fXCount >= kCount_DrawImageLatticeMask) {
- writer.write32(lattice.fXCount);
- }
- if (lattice.fYCount >= kCount_DrawImageLatticeMask) {
- writer.write32(lattice.fYCount);
- }
- // Often these divs will be small (8 or 16 bits). Consider sniffing that and writing a flag
- // so we can store them smaller.
- writer.write(lattice.fXDivs, lattice.fXCount * sizeof(int32_t));
- writer.write(lattice.fYDivs, lattice.fYCount * sizeof(int32_t));
- if (lattice.fRectTypes) {
- int32_t count = (lattice.fXCount + 1) * (lattice.fYCount + 1);
- SkASSERT(count > 0);
- write_pad(&writer, lattice.fRectTypes, count);
- write_pad(&writer, lattice.fColors, count*sizeof(SkColor));
- }
- SkASSERT(lattice.fBounds);
- writer.write(&lattice.fBounds, sizeof(*lattice.fBounds));
+ SkCanvasPriv::WriteLattice(writer, lattice);
writer.write(&dst, sizeof(dst));
if (paint) {
write_paint(writer, *paint, kImage_PaintUsage);
diff --git a/src/pipe/SkPipeCanvas.h b/src/pipe/SkPipeCanvas.h
index f48974a9a1..b45a0a598f 100644
--- a/src/pipe/SkPipeCanvas.h
+++ b/src/pipe/SkPipeCanvas.h
@@ -125,6 +125,7 @@ protected:
void onDrawRegion(const SkRegion&, const SkPaint&) override;
void onDrawRRect(const SkRRect&, const SkPaint&) override;
void onDrawPath(const SkPath&, const SkPaint&) override;
+ void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
diff --git a/src/pipe/SkPipeFormat.h b/src/pipe/SkPipeFormat.h
index 3d4904f0d2..13fdca5012 100644
--- a/src/pipe/SkPipeFormat.h
+++ b/src/pipe/SkPipeFormat.h
@@ -38,13 +38,14 @@ enum class SkPipeVerb : uint8_t {
kDrawPoints, // extra == PointMode
kDrawRect, // extra == 0
kDrawPath, // extra == 0
+ kDrawShadowRec, // extra == 0
kDrawOval, // extra == 0
kDrawRRect, // extra == 0
kDrawImage, // extra == has_paint:1
kDrawImageRect, // extra == constraint | has_src_rect | has_paint
kDrawImageNine, // extra == has_paint:1
- kDrawImageLattice, // extra == x_count:8 | y_count:8 | has_paint:1
+ kDrawImageLattice, // extra == has_paint:1
kDrawVertices,
diff --git a/src/pipe/SkPipeReader.cpp b/src/pipe/SkPipeReader.cpp
index 846368e66d..f8dc23885d 100644
--- a/src/pipe/SkPipeReader.cpp
+++ b/src/pipe/SkPipeReader.cpp
@@ -6,7 +6,9 @@
*/
#include "SkCanvas.h"
+#include "SkCanvasPriv.h"
#include "SkDeduper.h"
+#include "SkDrawShadowInfo.h"
#include "SkPicture.h"
#include "SkPictureRecorder.h"
#include "SkPipe.h"
@@ -480,6 +482,15 @@ static void drawPath_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas
canvas->drawPath(path, read_paint(reader));
}
+static void drawShadowRec_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) {
+ SkASSERT(SkPipeVerb::kDrawShadowRec == unpack_verb(packedVerb));
+ SkPath path;
+ reader.readPath(&path);
+ SkDrawShadowRec rec;
+ reader.readPad32(&rec, sizeof(rec));
+ canvas->private_draw_shadow_rec(path, rec);
+}
+
static void drawPoints_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) {
SkASSERT(SkPipeVerb::kDrawPoints == unpack_verb(packedVerb));
SkCanvas::PointMode mode = (SkCanvas::PointMode)unpack_verb_extra(packedVerb);
@@ -539,26 +550,9 @@ static void drawImageLattice_handler(SkPipeReader& reader, uint32_t packedVerb,
sk_sp<SkImage> image(reader.readImage());
SkCanvas::Lattice lattice;
- lattice.fXCount = (packedVerb >> kXCount_DrawImageLatticeShift) & kCount_DrawImageLatticeMask;
- if (lattice.fXCount == kCount_DrawImageLatticeMask) {
- lattice.fXCount = reader.read32();
- }
- lattice.fYCount = (packedVerb >> kXCount_DrawImageLatticeShift) & kCount_DrawImageLatticeMask;
- if (lattice.fYCount == kCount_DrawImageLatticeMask) {
- lattice.fYCount = reader.read32();
- }
- lattice.fXDivs = skip<int32_t>(reader, lattice.fXCount);
- lattice.fYDivs = skip<int32_t>(reader, lattice.fYCount);
- if (packedVerb & kHasFlags_DrawImageLatticeMask) {
- int32_t count = (lattice.fXCount + 1) * (lattice.fYCount + 1);
- SkASSERT(count > 0);
- lattice.fRectTypes = skip<SkCanvas::Lattice::RectType>(reader, count);
- lattice.fColors = skip<SkColor>(reader, count);
- } else {
- lattice.fRectTypes = nullptr;
- lattice.fColors = nullptr;
+ if (!SkCanvasPriv::ReadLattice(reader, &lattice)) {
+ return;
}
- lattice.fBounds = skip<SkIRect>(reader);
const SkRect* dst = skip<SkRect>(reader);
SkPaint paintStorage, *paint = nullptr;
@@ -749,6 +743,7 @@ const HandlerRec gPipeHandlers[] = {
HANDLER(drawPoints),
HANDLER(drawRect),
HANDLER(drawPath),
+ HANDLER(drawShadowRec),
HANDLER(drawOval),
HANDLER(drawRRect),