aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pipe
diff options
context:
space:
mode:
authorGravatar dandov <dandov@google.com>2014-08-12 08:34:29 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-12 08:34:29 -0700
commitb3c9d1c33caf325aada244204215eb790c228c12 (patch)
tree067c0017914891d0aff2b6d6163f2de1c2b20c54 /src/pipe
parent9c7695b0b59b97da933cd11014c922344a8d7654 (diff)
SkCanvas::drawPatch param SkPoint[12]
drawPatch now receives as parameter const SkPoint cubics[12] Adjusted derived classes and serialization. Ajusted GM's and benches that take into account combinations of optional parameters, the scale of the patch and 4 different types of patches. Planning on adding the extra functionality of SkPatch in another CL. BUG=skia: R=egdaniel@google.com, reed@google.com Author: dandov@google.com Review URL: https://codereview.chromium.org/463493002
Diffstat (limited to 'src/pipe')
-rw-r--r--src/pipe/SkGPipeRead.cpp26
-rw-r--r--src/pipe/SkGPipeWrite.cpp50
2 files changed, 67 insertions, 9 deletions
diff --git a/src/pipe/SkGPipeRead.cpp b/src/pipe/SkGPipeRead.cpp
index 35b0a94570..35de638e05 100644
--- a/src/pipe/SkGPipeRead.cpp
+++ b/src/pipe/SkGPipeRead.cpp
@@ -21,6 +21,7 @@
#include "SkImageFilter.h"
#include "SkMaskFilter.h"
#include "SkReadBuffer.h"
+#include "SkPatchUtils.h"
#include "SkPathEffect.h"
#include "SkRasterizer.h"
#include "SkRRect.h"
@@ -406,10 +407,29 @@ static void drawDRRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
static void drawPatch_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
- SkPatch patch;
- reader->readPatch(&patch);
+
+ unsigned flags = DrawOp_unpackFlags(op32);
+
+ const SkPoint* cubics = skip<SkPoint>(reader, SkPatchUtils::kNumCtrlPts);
+
+ const SkColor* colors = NULL;
+ if (flags & kDrawVertices_HasColors_DrawOpFlag) {
+ colors = skip<SkColor>(reader, SkPatchUtils::kNumCorners);
+ }
+ const SkPoint* texCoords = NULL;
+ if (flags & kDrawVertices_HasTexs_DrawOpFlag) {
+ texCoords = skip<SkPoint>(reader, SkPatchUtils::kNumCorners);
+ }
+ SkAutoTUnref<SkXfermode> xfer;
+ if (flags & kDrawVertices_HasXfermode_DrawOpFlag) {
+ int mode = reader->readInt();
+ if (mode < 0 || mode > SkXfermode::kLastMode) {
+ mode = SkXfermode::kModulate_Mode;
+ }
+ xfer.reset(SkXfermode::Create((SkXfermode::Mode)mode));
+ }
if (state->shouldDraw()) {
- canvas->drawPatch(patch, state->paint());
+ canvas->drawPatch(cubics, colors, texCoords, xfer, state->paint());
}
}
diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp
index d796e8a99b..94a30a34e2 100644
--- a/src/pipe/SkGPipeWrite.cpp
+++ b/src/pipe/SkGPipeWrite.cpp
@@ -19,6 +19,7 @@
#include "SkMaskFilter.h"
#include "SkWriteBuffer.h"
#include "SkPaint.h"
+#include "SkPatchUtils.h"
#include "SkPathEffect.h"
#include "SkPictureFlat.h"
#include "SkRasterizer.h"
@@ -254,7 +255,6 @@ public:
const SkColor colors[], SkXfermode*,
const uint16_t indices[], int indexCount,
const SkPaint&) SK_OVERRIDE;
- virtual void drawPatch(const SkPatch& patch, const SkPaint& paint) SK_OVERRIDE;
virtual void drawData(const void*, size_t) SK_OVERRIDE;
virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
@@ -283,7 +283,9 @@ protected:
SkScalar constY, const SkPaint&) SK_OVERRIDE;
virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
-
+ virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
+ const SkPoint texCoords[4], SkXfermode* xmode,
+ const SkPaint& paint) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
@@ -1003,12 +1005,48 @@ void SkGPipeCanvas::drawVertices(VertexMode vmode, int vertexCount,
}
}
-void SkGPipeCanvas::drawPatch(const SkPatch& patch, const SkPaint& paint) {
+void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
+ const SkPoint texCoords[4], SkXfermode* xmode,
+ const SkPaint& paint) {
NOTIFY_SETUP(this);
+
+ size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint);
+ unsigned flags = 0;
+ if (NULL != colors) {
+ flags |= kDrawVertices_HasColors_DrawOpFlag;
+ size += SkPatchUtils::kNumCorners * sizeof(SkColor);
+ }
+ if (NULL != texCoords) {
+ flags |= kDrawVertices_HasTexs_DrawOpFlag;
+ size += SkPatchUtils::kNumCorners * sizeof(SkPoint);
+ }
+ if (NULL != xmode) {
+ SkXfermode::Mode mode;
+ if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) {
+ flags |= kDrawVertices_HasXfermode_DrawOpFlag;
+ size += sizeof(int32_t);
+ }
+ }
+
this->writePaint(paint);
- if (this->needOpBytes(patch.writeToMemory(NULL))) {
- this->writeOp(kDrawPatch_DrawOp);
- fWriter.writePatch(patch);
+ if (this->needOpBytes(size)) {
+ this->writeOp(kDrawPatch_DrawOp, flags, 0);
+
+ fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
+
+ if (NULL != colors) {
+ fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor));
+ }
+
+ if (NULL != texCoords) {
+ fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint));
+ }
+
+ if (flags & kDrawVertices_HasXfermode_DrawOpFlag) {
+ SkXfermode::Mode mode = SkXfermode::kModulate_Mode;
+ SkAssertResult(xmode->asMode(&mode));
+ fWriter.write32(mode);
+ }
}
}