| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 | 9 |
| 10 #include "SkDrawCommand.h" | 10 #include "SkDrawCommand.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 case kRestore_OpType: return "Restore"; | 56 case kRestore_OpType: return "Restore"; |
| 57 case kSave_OpType: return "Save"; | 57 case kSave_OpType: return "Save"; |
| 58 case kSaveLayer_OpType: return "SaveLayer"; | 58 case kSaveLayer_OpType: return "SaveLayer"; |
| 59 case kSetMatrix_OpType: return "SetMatrix"; | 59 case kSetMatrix_OpType: return "SetMatrix"; |
| 60 default: | 60 default: |
| 61 SkDebugf("OpType error 0x%08x\n", type); | 61 SkDebugf("OpType error 0x%08x\n", type); |
| 62 SkASSERT(0); | 62 SkASSERT(0); |
| 63 break; | 63 break; |
| 64 } | 64 } |
| 65 SkDEBUGFAIL("DrawType UNUSED\n"); | 65 SkDEBUGFAIL("DrawType UNUSED\n"); |
| 66 return NULL; | 66 return nullptr; |
| 67 } | 67 } |
| 68 | 68 |
| 69 SkString SkDrawCommand::toString() const { | 69 SkString SkDrawCommand::toString() const { |
| 70 return SkString(GetCommandString(fOpType)); | 70 return SkString(GetCommandString(fOpType)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) { | 73 SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) { |
| 74 fColor = color; | 74 fColor = color; |
| 75 fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); | 75 fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
| 76 } | 76 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 107 xlate_and_scale_to_bounds(canvas, bounds); | 107 xlate_and_scale_to_bounds(canvas, bounds); |
| 108 | 108 |
| 109 SkPaint p; | 109 SkPaint p; |
| 110 p.setColor(SK_ColorBLACK); | 110 p.setColor(SK_ColorBLACK); |
| 111 p.setStyle(SkPaint::kStroke_Style); | 111 p.setStyle(SkPaint::kStroke_Style); |
| 112 | 112 |
| 113 canvas->drawPath(path, p); | 113 canvas->drawPath(path, p); |
| 114 canvas->restore(); | 114 canvas->restore(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRec
t = NULL) { | 117 void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRec
t = nullptr) { |
| 118 const SkISize& size = canvas->getDeviceSize(); | 118 const SkISize& size = canvas->getDeviceSize(); |
| 119 | 119 |
| 120 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width(); | 120 SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width(); |
| 121 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height(); | 121 SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height(); |
| 122 | 122 |
| 123 if (input.width() > input.height()) { | 123 if (input.width() > input.height()) { |
| 124 yScale *= input.height() / (float) input.width(); | 124 yScale *= input.height() / (float) input.width(); |
| 125 } else { | 125 } else { |
| 126 xScale *= input.width() / (float) input.height(); | 126 xScale *= input.width() / (float) input.height(); |
| 127 } | 127 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left,
SkScalar top, | 263 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left,
SkScalar top, |
| 264 const SkPaint* paint) | 264 const SkPaint* paint) |
| 265 : INHERITED(kDrawBitmap_OpType) { | 265 : INHERITED(kDrawBitmap_OpType) { |
| 266 fBitmap = bitmap; | 266 fBitmap = bitmap; |
| 267 fLeft = left; | 267 fLeft = left; |
| 268 fTop = top; | 268 fTop = top; |
| 269 if (paint) { | 269 if (paint) { |
| 270 fPaint = *paint; | 270 fPaint = *paint; |
| 271 fPaintPtr = &fPaint; | 271 fPaintPtr = &fPaint; |
| 272 } else { | 272 } else { |
| 273 fPaintPtr = NULL; | 273 fPaintPtr = nullptr; |
| 274 } | 274 } |
| 275 | 275 |
| 276 fInfo.push(SkObjectParser::BitmapToString(bitmap)); | 276 fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 277 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: ")); | 277 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: ")); |
| 278 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: ")); | 278 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: ")); |
| 279 if (paint) { | 279 if (paint) { |
| 280 fInfo.push(SkObjectParser::PaintToString(*paint)); | 280 fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 void SkDrawBitmapCommand::execute(SkCanvas* canvas) const { | 284 void SkDrawBitmapCommand::execute(SkCanvas* canvas) const { |
| 285 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr); | 285 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr); |
| 286 } | 286 } |
| 287 | 287 |
| 288 bool SkDrawBitmapCommand::render(SkCanvas* canvas) const { | 288 bool SkDrawBitmapCommand::render(SkCanvas* canvas) const { |
| 289 render_bitmap(canvas, fBitmap); | 289 render_bitmap(canvas, fBitmap); |
| 290 return true; | 290 return true; |
| 291 } | 291 } |
| 292 | 292 |
| 293 SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S
kIRect& center, | 293 SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S
kIRect& center, |
| 294 const SkRect& dst, const SkPain
t* paint) | 294 const SkRect& dst, const SkPain
t* paint) |
| 295 : INHERITED(kDrawBitmapNine_OpType) { | 295 : INHERITED(kDrawBitmapNine_OpType) { |
| 296 fBitmap = bitmap; | 296 fBitmap = bitmap; |
| 297 fCenter = center; | 297 fCenter = center; |
| 298 fDst = dst; | 298 fDst = dst; |
| 299 if (paint) { | 299 if (paint) { |
| 300 fPaint = *paint; | 300 fPaint = *paint; |
| 301 fPaintPtr = &fPaint; | 301 fPaintPtr = &fPaint; |
| 302 } else { | 302 } else { |
| 303 fPaintPtr = NULL; | 303 fPaintPtr = nullptr; |
| 304 } | 304 } |
| 305 | 305 |
| 306 fInfo.push(SkObjectParser::BitmapToString(bitmap)); | 306 fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 307 fInfo.push(SkObjectParser::IRectToString(center)); | 307 fInfo.push(SkObjectParser::IRectToString(center)); |
| 308 fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); | 308 fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
| 309 if (paint) { | 309 if (paint) { |
| 310 fInfo.push(SkObjectParser::PaintToString(*paint)); | 310 fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 329 fSrc = *src; | 329 fSrc = *src; |
| 330 } else { | 330 } else { |
| 331 fSrc.setEmpty(); | 331 fSrc.setEmpty(); |
| 332 } | 332 } |
| 333 fDst = dst; | 333 fDst = dst; |
| 334 | 334 |
| 335 if (paint) { | 335 if (paint) { |
| 336 fPaint = *paint; | 336 fPaint = *paint; |
| 337 fPaintPtr = &fPaint; | 337 fPaintPtr = &fPaint; |
| 338 } else { | 338 } else { |
| 339 fPaintPtr = NULL; | 339 fPaintPtr = nullptr; |
| 340 } | 340 } |
| 341 fConstraint = constraint; | 341 fConstraint = constraint; |
| 342 | 342 |
| 343 fInfo.push(SkObjectParser::BitmapToString(bitmap)); | 343 fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 344 if (src) { | 344 if (src) { |
| 345 fInfo.push(SkObjectParser::RectToString(*src, "Src: ")); | 345 fInfo.push(SkObjectParser::RectToString(*src, "Src: ")); |
| 346 } | 346 } |
| 347 fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); | 347 fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
| 348 if (paint) { | 348 if (paint) { |
| 349 fInfo.push(SkObjectParser::PaintToString(*paint)); | 349 fInfo.push(SkObjectParser::PaintToString(*paint)); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int t
op, | 757 SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int t
op, |
| 758 const SkPaint* paint) | 758 const SkPaint* paint) |
| 759 : INHERITED(kDrawSprite_OpType) { | 759 : INHERITED(kDrawSprite_OpType) { |
| 760 fBitmap = bitmap; | 760 fBitmap = bitmap; |
| 761 fLeft = left; | 761 fLeft = left; |
| 762 fTop = top; | 762 fTop = top; |
| 763 if (paint) { | 763 if (paint) { |
| 764 fPaint = *paint; | 764 fPaint = *paint; |
| 765 fPaintPtr = &fPaint; | 765 fPaintPtr = &fPaint; |
| 766 } else { | 766 } else { |
| 767 fPaintPtr = NULL; | 767 fPaintPtr = nullptr; |
| 768 } | 768 } |
| 769 | 769 |
| 770 fInfo.push(SkObjectParser::BitmapToString(bitmap)); | 770 fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 771 fInfo.push(SkObjectParser::IntToString(left, "Left: ")); | 771 fInfo.push(SkObjectParser::IntToString(left, "Left: ")); |
| 772 fInfo.push(SkObjectParser::IntToString(top, "Top: ")); | 772 fInfo.push(SkObjectParser::IntToString(top, "Top: ")); |
| 773 if (paint) { | 773 if (paint) { |
| 774 fInfo.push(SkObjectParser::PaintToString(*paint)); | 774 fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 775 } | 775 } |
| 776 } | 776 } |
| 777 | 777 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod
ing())); | 822 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod
ing())); |
| 823 fInfo.push(SkObjectParser::PathToString(path)); | 823 fInfo.push(SkObjectParser::PathToString(path)); |
| 824 if (matrix) { | 824 if (matrix) { |
| 825 fInfo.push(SkObjectParser::MatrixToString(*matrix)); | 825 fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
| 826 } | 826 } |
| 827 fInfo.push(SkObjectParser::PaintToString(paint)); | 827 fInfo.push(SkObjectParser::PaintToString(paint)); |
| 828 } | 828 } |
| 829 | 829 |
| 830 void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const { | 830 void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const { |
| 831 canvas->drawTextOnPath(fText, fByteLength, fPath, | 831 canvas->drawTextOnPath(fText, fByteLength, fPath, |
| 832 fMatrix.isIdentity() ? NULL : &fMatrix, | 832 fMatrix.isIdentity() ? nullptr : &fMatrix, |
| 833 fPaint); | 833 fPaint); |
| 834 } | 834 } |
| 835 | 835 |
| 836 SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver
texCount, | 836 SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver
texCount, |
| 837 const SkPoint vertices[], const SkP
oint texs[], | 837 const SkPoint vertices[], const SkP
oint texs[], |
| 838 const SkColor colors[], SkXfermode*
xfermode, | 838 const SkColor colors[], SkXfermode*
xfermode, |
| 839 const uint16_t indices[], int index
Count, | 839 const uint16_t indices[], int index
Count, |
| 840 const SkPaint& paint) | 840 const SkPaint& paint) |
| 841 : INHERITED(kDrawVertices_OpType) { | 841 : INHERITED(kDrawVertices_OpType) { |
| 842 fVmode = vmode; | 842 fVmode = vmode; |
| 843 | 843 |
| 844 fVertexCount = vertexCount; | 844 fVertexCount = vertexCount; |
| 845 | 845 |
| 846 fVertices = new SkPoint[vertexCount]; | 846 fVertices = new SkPoint[vertexCount]; |
| 847 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint)); | 847 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint)); |
| 848 | 848 |
| 849 if (texs) { | 849 if (texs) { |
| 850 fTexs = new SkPoint[vertexCount]; | 850 fTexs = new SkPoint[vertexCount]; |
| 851 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint)); | 851 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint)); |
| 852 } else { | 852 } else { |
| 853 fTexs = NULL; | 853 fTexs = nullptr; |
| 854 } | 854 } |
| 855 | 855 |
| 856 if (colors) { | 856 if (colors) { |
| 857 fColors = new SkColor[vertexCount]; | 857 fColors = new SkColor[vertexCount]; |
| 858 memcpy(fColors, colors, vertexCount * sizeof(SkColor)); | 858 memcpy(fColors, colors, vertexCount * sizeof(SkColor)); |
| 859 } else { | 859 } else { |
| 860 fColors = NULL; | 860 fColors = nullptr; |
| 861 } | 861 } |
| 862 | 862 |
| 863 fXfermode = xfermode; | 863 fXfermode = xfermode; |
| 864 if (fXfermode) { | 864 if (fXfermode) { |
| 865 fXfermode->ref(); | 865 fXfermode->ref(); |
| 866 } | 866 } |
| 867 | 867 |
| 868 if (indexCount > 0) { | 868 if (indexCount > 0) { |
| 869 fIndices = new uint16_t[indexCount]; | 869 fIndices = new uint16_t[indexCount]; |
| 870 memcpy(fIndices, indices, indexCount * sizeof(uint16_t)); | 870 memcpy(fIndices, indices, indexCount * sizeof(uint16_t)); |
| 871 } else { | 871 } else { |
| 872 fIndices = NULL; | 872 fIndices = nullptr; |
| 873 } | 873 } |
| 874 | 874 |
| 875 fIndexCount = indexCount; | 875 fIndexCount = indexCount; |
| 876 fPaint = paint; | 876 fPaint = paint; |
| 877 | 877 |
| 878 // TODO(chudy) | 878 // TODO(chudy) |
| 879 fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); | 879 fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
| 880 fInfo.push(SkObjectParser::PaintToString(paint)); | 880 fInfo.push(SkObjectParser::PaintToString(paint)); |
| 881 } | 881 } |
| 882 | 882 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 if (bounds) { | 917 if (bounds) { |
| 918 fBounds = *bounds; | 918 fBounds = *bounds; |
| 919 } else { | 919 } else { |
| 920 fBounds.setEmpty(); | 920 fBounds.setEmpty(); |
| 921 } | 921 } |
| 922 | 922 |
| 923 if (paint) { | 923 if (paint) { |
| 924 fPaint = *paint; | 924 fPaint = *paint; |
| 925 fPaintPtr = &fPaint; | 925 fPaintPtr = &fPaint; |
| 926 } else { | 926 } else { |
| 927 fPaintPtr = NULL; | 927 fPaintPtr = nullptr; |
| 928 } | 928 } |
| 929 fFlags = flags; | 929 fFlags = flags; |
| 930 | 930 |
| 931 if (bounds) { | 931 if (bounds) { |
| 932 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: ")); | 932 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: ")); |
| 933 } | 933 } |
| 934 if (paint) { | 934 if (paint) { |
| 935 fInfo.push(SkObjectParser::PaintToString(*paint)); | 935 fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 936 } | 936 } |
| 937 fInfo.push(SkObjectParser::SaveFlagsToString(flags)); | 937 fInfo.push(SkObjectParser::SaveFlagsToString(flags)); |
| 938 } | 938 } |
| 939 | 939 |
| 940 void SkSaveLayerCommand::execute(SkCanvas* canvas) const { | 940 void SkSaveLayerCommand::execute(SkCanvas* canvas) const { |
| 941 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds, | 941 canvas->saveLayer(fBounds.isEmpty() ? nullptr : &fBounds, |
| 942 fPaintPtr, | 942 fPaintPtr, |
| 943 fFlags); | 943 fFlags); |
| 944 } | 944 } |
| 945 | 945 |
| 946 void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const { | 946 void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const { |
| 947 canvas->save(); | 947 canvas->save(); |
| 948 } | 948 } |
| 949 | 949 |
| 950 SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) | 950 SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) |
| 951 : INHERITED(kSetMatrix_OpType) { | 951 : INHERITED(kSetMatrix_OpType) { |
| 952 fUserMatrix.reset(); | 952 fUserMatrix.reset(); |
| 953 fMatrix = matrix; | 953 fMatrix = matrix; |
| 954 | 954 |
| 955 fInfo.push(SkObjectParser::MatrixToString(matrix)); | 955 fInfo.push(SkObjectParser::MatrixToString(matrix)); |
| 956 } | 956 } |
| 957 | 957 |
| 958 void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) { | 958 void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) { |
| 959 fUserMatrix = userMatrix; | 959 fUserMatrix = userMatrix; |
| 960 } | 960 } |
| 961 | 961 |
| 962 void SkSetMatrixCommand::execute(SkCanvas* canvas) const { | 962 void SkSetMatrixCommand::execute(SkCanvas* canvas) const { |
| 963 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix); | 963 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix); |
| 964 canvas->setMatrix(temp); | 964 canvas->setMatrix(temp); |
| 965 } | 965 } |
| 966 | 966 |
| OLD | NEW |