| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| 11 #include "SkBitmapHeap.h" | 11 #include "SkBitmapHeap.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
| 14 #include "SkData.h" | 14 #include "SkData.h" |
| 15 #include "SkDrawLooper.h" | 15 #include "SkDrawLooper.h" |
| 16 #include "SkGPipe.h" | 16 #include "SkGPipe.h" |
| 17 #include "SkGPipePriv.h" | 17 #include "SkGPipePriv.h" |
| 18 #include "SkImageFilter.h" | 18 #include "SkImageFilter.h" |
| 19 #include "SkMaskFilter.h" | 19 #include "SkMaskFilter.h" |
| 20 #include "SkWriteBuffer.h" | 20 #include "SkWriteBuffer.h" |
| 21 #include "SkPaint.h" | 21 #include "SkPaint.h" |
| 22 #include "SkPatchUtils.h" |
| 22 #include "SkPathEffect.h" | 23 #include "SkPathEffect.h" |
| 23 #include "SkPictureFlat.h" | 24 #include "SkPictureFlat.h" |
| 24 #include "SkRasterizer.h" | 25 #include "SkRasterizer.h" |
| 25 #include "SkRRect.h" | 26 #include "SkRRect.h" |
| 26 #include "SkShader.h" | 27 #include "SkShader.h" |
| 27 #include "SkStream.h" | 28 #include "SkStream.h" |
| 28 #include "SkTSearch.h" | 29 #include "SkTSearch.h" |
| 29 #include "SkTypeface.h" | 30 #include "SkTypeface.h" |
| 30 #include "SkWriter32.h" | 31 #include "SkWriter32.h" |
| 31 | 32 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 const SkPaint*) SK_OVERRIDE; | 248 const SkPaint*) SK_OVERRIDE; |
| 248 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, | 249 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 249 const SkRect& dst, const SkPaint* paint = NULL)
SK_OVERRIDE; | 250 const SkRect& dst, const SkPaint* paint = NULL)
SK_OVERRIDE; |
| 250 virtual void drawSprite(const SkBitmap&, int left, int top, | 251 virtual void drawSprite(const SkBitmap&, int left, int top, |
| 251 const SkPaint*) SK_OVERRIDE; | 252 const SkPaint*) SK_OVERRIDE; |
| 252 virtual void drawVertices(VertexMode, int vertexCount, | 253 virtual void drawVertices(VertexMode, int vertexCount, |
| 253 const SkPoint vertices[], const SkPoint texs[], | 254 const SkPoint vertices[], const SkPoint texs[], |
| 254 const SkColor colors[], SkXfermode*, | 255 const SkColor colors[], SkXfermode*, |
| 255 const uint16_t indices[], int indexCount, | 256 const uint16_t indices[], int indexCount, |
| 256 const SkPaint&) SK_OVERRIDE; | 257 const SkPaint&) SK_OVERRIDE; |
| 257 virtual void drawPatch(const SkPatch& patch, const SkPaint& paint) SK_OVERRI
DE; | |
| 258 virtual void drawData(const void*, size_t) SK_OVERRIDE; | 258 virtual void drawData(const void*, size_t) SK_OVERRIDE; |
| 259 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; | 259 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
| 260 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; | 260 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
| 261 virtual void endCommentGroup() SK_OVERRIDE; | 261 virtual void endCommentGroup() SK_OVERRIDE; |
| 262 | 262 |
| 263 /** | 263 /** |
| 264 * Flatten an SkBitmap to send to the reader, where it will be referenced | 264 * Flatten an SkBitmap to send to the reader, where it will be referenced |
| 265 * according to slot. | 265 * according to slot. |
| 266 */ | 266 */ |
| 267 bool shuttleBitmap(const SkBitmap&, int32_t slot); | 267 bool shuttleBitmap(const SkBitmap&, int32_t slot); |
| 268 | 268 |
| 269 protected: | 269 protected: |
| 270 virtual void willSave() SK_OVERRIDE; | 270 virtual void willSave() SK_OVERRIDE; |
| 271 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF
lags) SK_OVERRIDE; | 271 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF
lags) SK_OVERRIDE; |
| 272 virtual void willRestore() SK_OVERRIDE; | 272 virtual void willRestore() SK_OVERRIDE; |
| 273 | 273 |
| 274 virtual void didConcat(const SkMatrix&) SK_OVERRIDE; | 274 virtual void didConcat(const SkMatrix&) SK_OVERRIDE; |
| 275 virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; | 275 virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; |
| 276 | 276 |
| 277 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK
_OVERRIDE; | 277 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK
_OVERRIDE; |
| 278 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkS
calar y, | 278 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkS
calar y, |
| 279 const SkPaint&) SK_OVERRIDE; | 279 const SkPaint&) SK_OVERRIDE; |
| 280 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoin
t pos[], | 280 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoin
t pos[], |
| 281 const SkPaint&) SK_OVERRIDE; | 281 const SkPaint&) SK_OVERRIDE; |
| 282 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkSca
lar xpos[], | 282 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkSca
lar xpos[], |
| 283 SkScalar constY, const SkPaint&) SK_OVERRIDE; | 283 SkScalar constY, const SkPaint&) SK_OVERRIDE; |
| 284 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkP
ath& path, | 284 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkP
ath& path, |
| 285 const SkMatrix* matrix, const SkPaint&) SK_OVE
RRIDE; | 285 const SkMatrix* matrix, const SkPaint&) SK_OVE
RRIDE; |
| 286 | 286 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 287 const SkPoint texCoords[4], SkXfermode* xmode, |
| 288 const SkPaint& paint) SK_OVERRIDE; |
| 287 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; | 289 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; |
| 288 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVE
RRIDE; | 290 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVE
RRIDE; |
| 289 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; | 291 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; |
| 290 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; | 292 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; |
| 291 | 293 |
| 292 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
) SK_OVERRIDE; | 294 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
) SK_OVERRIDE; |
| 293 | 295 |
| 294 private: | 296 private: |
| 295 void recordTranslate(const SkMatrix&); | 297 void recordTranslate(const SkMatrix&); |
| 296 void recordScale(const SkMatrix&); | 298 void recordScale(const SkMatrix&); |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 SkAssertResult(xfer->asMode(&mode)); | 998 SkAssertResult(xfer->asMode(&mode)); |
| 997 fWriter.write32(mode); | 999 fWriter.write32(mode); |
| 998 } | 1000 } |
| 999 if (flags & kDrawVertices_HasIndices_DrawOpFlag) { | 1001 if (flags & kDrawVertices_HasIndices_DrawOpFlag) { |
| 1000 fWriter.write32(indexCount); | 1002 fWriter.write32(indexCount); |
| 1001 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); | 1003 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
| 1002 } | 1004 } |
| 1003 } | 1005 } |
| 1004 } | 1006 } |
| 1005 | 1007 |
| 1006 void SkGPipeCanvas::drawPatch(const SkPatch& patch, const SkPaint& paint) { | 1008 void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4
], |
| 1009 const SkPoint texCoords[4], SkXfermode* xmode, |
| 1010 const SkPaint& paint) { |
| 1007 NOTIFY_SETUP(this); | 1011 NOTIFY_SETUP(this); |
| 1012 |
| 1013 size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint); |
| 1014 unsigned flags = 0; |
| 1015 if (NULL != colors) { |
| 1016 flags |= kDrawVertices_HasColors_DrawOpFlag; |
| 1017 size += SkPatchUtils::kNumCorners * sizeof(SkColor); |
| 1018 } |
| 1019 if (NULL != texCoords) { |
| 1020 flags |= kDrawVertices_HasTexs_DrawOpFlag; |
| 1021 size += SkPatchUtils::kNumCorners * sizeof(SkPoint); |
| 1022 } |
| 1023 if (NULL != xmode) { |
| 1024 SkXfermode::Mode mode; |
| 1025 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { |
| 1026 flags |= kDrawVertices_HasXfermode_DrawOpFlag; |
| 1027 size += sizeof(int32_t); |
| 1028 } |
| 1029 } |
| 1030 |
| 1008 this->writePaint(paint); | 1031 this->writePaint(paint); |
| 1009 if (this->needOpBytes(patch.writeToMemory(NULL))) { | 1032 if (this->needOpBytes(size)) { |
| 1010 this->writeOp(kDrawPatch_DrawOp); | 1033 this->writeOp(kDrawPatch_DrawOp, flags, 0); |
| 1011 fWriter.writePatch(patch); | 1034 |
| 1035 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); |
| 1036 |
| 1037 if (NULL != colors) { |
| 1038 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); |
| 1039 } |
| 1040 |
| 1041 if (NULL != texCoords) { |
| 1042 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)
); |
| 1043 } |
| 1044 |
| 1045 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { |
| 1046 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
| 1047 SkAssertResult(xmode->asMode(&mode)); |
| 1048 fWriter.write32(mode); |
| 1049 } |
| 1012 } | 1050 } |
| 1013 } | 1051 } |
| 1014 | 1052 |
| 1015 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { | 1053 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { |
| 1016 if (size && ptr) { | 1054 if (size && ptr) { |
| 1017 NOTIFY_SETUP(this); | 1055 NOTIFY_SETUP(this); |
| 1018 unsigned data = 0; | 1056 unsigned data = 0; |
| 1019 if (size < (1 << DRAWOPS_DATA_BITS)) { | 1057 if (size < (1 << DRAWOPS_DATA_BITS)) { |
| 1020 data = (unsigned)size; | 1058 data = (unsigned)size; |
| 1021 } | 1059 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 return fCanvas->shuttleBitmap(bitmap, slot); | 1313 return fCanvas->shuttleBitmap(bitmap, slot); |
| 1276 } | 1314 } |
| 1277 | 1315 |
| 1278 void BitmapShuttle::removeCanvas() { | 1316 void BitmapShuttle::removeCanvas() { |
| 1279 if (NULL == fCanvas) { | 1317 if (NULL == fCanvas) { |
| 1280 return; | 1318 return; |
| 1281 } | 1319 } |
| 1282 fCanvas->unref(); | 1320 fCanvas->unref(); |
| 1283 fCanvas = NULL; | 1321 fCanvas = NULL; |
| 1284 } | 1322 } |
| OLD | NEW |