diff options
author | reed <reed@google.com> | 2015-06-24 10:29:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-24 10:29:18 -0700 |
commit | 71c3c760a83123ee0b3127b8c65c6394ce541c50 (patch) | |
tree | d0a2492c668d2263874cdc0409056747f0a2fa5e /src/pipe | |
parent | 52d4deb1288633551ad275be748d8b0f73d7b2aa (diff) |
add SkCanvas::drawAtlas
BUG=skia:
Review URL: https://codereview.chromium.org/1181913003
Diffstat (limited to 'src/pipe')
-rw-r--r-- | src/pipe/SkGPipePriv.h | 6 | ||||
-rw-r--r-- | src/pipe/SkGPipeRead.cpp | 31 | ||||
-rw-r--r-- | src/pipe/SkGPipeWrite.cpp | 45 |
3 files changed, 81 insertions, 1 deletions
diff --git a/src/pipe/SkGPipePriv.h b/src/pipe/SkGPipePriv.h index 5f6e45b158..2f246e452c 100644 --- a/src/pipe/SkGPipePriv.h +++ b/src/pipe/SkGPipePriv.h @@ -39,6 +39,7 @@ enum DrawOps { kClipRect_DrawOp, kClipRRect_DrawOp, kConcat_DrawOp, + kDrawAtlas_DrawOp, kDrawBitmap_DrawOp, kDrawBitmapNine_DrawOp, kDrawBitmapRectToRect_DrawOp, @@ -144,6 +145,11 @@ enum { kDrawVertices_HasIndices_DrawOpFlag = 1 << 2, kDrawVertices_HasXfermode_DrawOpFlag = 1 << 3, }; +enum { + kDrawAtlas_HasPaint_DrawOpFlag = 1 << 0, + kDrawAtlas_HasColors_DrawOpFlag = 1 << 1, + kDrawAtlas_HasCull_DrawOpFlag = 1 << 2, +}; // These are shared between drawbitmap and drawimage enum { kDrawBitmap_HasPaint_DrawOpFlag = 1 << 0, diff --git a/src/pipe/SkGPipeRead.cpp b/src/pipe/SkGPipeRead.cpp index 917bb50976..8d3048d76f 100644 --- a/src/pipe/SkGPipeRead.cpp +++ b/src/pipe/SkGPipeRead.cpp @@ -20,11 +20,12 @@ #include "SkDrawLooper.h" #include "SkImageFilter.h" #include "SkMaskFilter.h" -#include "SkReadBuffer.h" #include "SkPatchUtils.h" #include "SkPathEffect.h" #include "SkRasterizer.h" +#include "SkReadBuffer.h" #include "SkRRect.h" +#include "SkRSXform.h" #include "SkShader.h" #include "SkTextBlob.h" #include "SkTypeface.h" @@ -479,6 +480,33 @@ static void drawVertices_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, } } +static void drawAtlas_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, SkGPipeState* state) { + unsigned flags = DrawOp_unpackFlags(op32); + + const SkPaint* paint = NULL; + if (flags & kDrawAtlas_HasPaint_DrawOpFlag) { + paint = &state->paint(); + } + const int slot = reader->readU32(); + const SkImage* atlas = state->getImage(slot); + const int count = reader->readU32(); + SkXfermode::Mode mode = (SkXfermode::Mode)reader->readU32(); + const SkRSXform* xform = skip<SkRSXform>(reader, count); + const SkRect* tex = skip<SkRect>(reader, count); + const SkColor* colors = NULL; + if (flags & kDrawAtlas_HasColors_DrawOpFlag) { + colors = skip<SkColor>(reader, count); + } + const SkRect* cull = NULL; + if (flags & kDrawAtlas_HasCull_DrawOpFlag) { + cull = skip<SkRect>(reader, 1); + } + + if (state->shouldDraw()) { + canvas->drawAtlas(atlas, xform, tex, colors, count, mode, cull, paint); + } +} + /////////////////////////////////////////////////////////////////////////////// static void drawText_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, @@ -831,6 +859,7 @@ static const ReadProc gReadTable[] = { clipRect_rp, clipRRect_rp, concat_rp, + drawAtlas_rp, drawBitmap_rp, drawBitmapNine_rp, drawBitmapRect_rp, diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp index 2c11c41444..f2aaaae216 100644 --- a/src/pipe/SkGPipeWrite.cpp +++ b/src/pipe/SkGPipeWrite.cpp @@ -16,6 +16,7 @@ #include "SkGPipePriv.h" #include "SkImageFilter.h" #include "SkMaskFilter.h" +#include "SkRSXform.h" #include "SkWriteBuffer.h" #include "SkPaint.h" #include "SkPatchUtils.h" @@ -287,6 +288,8 @@ protected: const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint&) override; + void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], + int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*) override; void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override; void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override; void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override; @@ -1096,6 +1099,48 @@ void SkGPipeCanvas::onDrawVertices(VertexMode vmode, int vertexCount, } } +void SkGPipeCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], + const SkColor colors[], int count, SkXfermode::Mode mode, + const SkRect* cull, const SkPaint* paint) { + NOTIFY_SETUP(this); + unsigned flags = 0; // packs with the op, so needs no extra space + + if (paint) { + flags |= kDrawAtlas_HasPaint_DrawOpFlag; + this->writePaint(*paint); + } + + size_t size = 4; // image-slot + size += 4; // count + size += 4; // mode + size += count * sizeof(SkRSXform); // xform + size += count * sizeof(SkRect); // tex + if (colors) { + flags |= kDrawAtlas_HasColors_DrawOpFlag; + size += count * sizeof(SkColor); // colors + } + if (cull) { + flags |= kDrawAtlas_HasCull_DrawOpFlag; + size += sizeof(SkRect); // cull + } + + if (this->needOpBytes(size)) { + this->writeOp(kDrawAtlas_DrawOp, flags, 0); + int32_t slot = fImageHeap->insert(atlas); + fWriter.write32(slot); + fWriter.write32(count); + fWriter.write32(mode); + fWriter.write(xform, count * sizeof(SkRSXform)); + fWriter.write(tex, count * sizeof(SkRect)); + if (colors) { + fWriter.write(colors, count * sizeof(SkColor)); + } + if (cull) { + fWriter.writeRect(*cull); + } + } +} + void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) { |