Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / utils / debugger / SkDrawCommand.cpp
index 26d2a85..0da8f98 100644 (file)
@@ -10,6 +10,8 @@
 #include "SkDrawCommand.h"
 #include "SkObjectParser.h"
 
+#include "SkTextBlob.h"
+
 // TODO(chudy): Refactor into non subclass model.
 
 SkDrawCommand::SkDrawCommand(DrawType type)
@@ -52,6 +54,7 @@ const char* SkDrawCommand::GetCommandString(DrawType type) {
         case DRAW_RRECT: return "Draw RRect";
         case DRAW_SPRITE: return "Draw Sprite";
         case DRAW_TEXT: return "Draw Text";
+        case DRAW_TEXT_BLOB: return "Draw Text Blob";
         case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
         case DRAW_VERTICES: return "Draw Vertices";
         case RESTORE: return "Restore";
@@ -145,7 +148,7 @@ void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRec
     canvas->clear(0xFFFFFFFF);
     canvas->drawBitmapRect(input, NULL, dst);
 
-    if (NULL != srcRect) {
+    if (srcRect) {
         SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
                                     srcRect->fTop * yScale + SK_Scalar1,
                                     srcRect->fRight * xScale + SK_Scalar1,
@@ -278,7 +281,7 @@ SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left,
     fBitmap = bitmap;
     fLeft = left;
     fTop = top;
-    if (NULL != paint) {
+    if (paint) {
         fPaint = *paint;
         fPaintPtr = &fPaint;
     } else {
@@ -288,7 +291,7 @@ SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left,
     fInfo.push(SkObjectParser::BitmapToString(bitmap));
     fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
     fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
-    if (NULL != paint) {
+    if (paint) {
         fInfo.push(SkObjectParser::PaintToString(*paint));
     }
 }
@@ -308,7 +311,7 @@ SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
     : INHERITED(DRAW_BITMAP_MATRIX) {
     fBitmap = bitmap;
     fMatrix = matrix;
-    if (NULL != paint) {
+    if (paint) {
         fPaint = *paint;
         fPaintPtr = &fPaint;
     } else {
@@ -317,7 +320,7 @@ SkDrawBitmapMatrixCommand::SkDrawBitmapMatrixCommand(const SkBitmap& bitmap,
 
     fInfo.push(SkObjectParser::BitmapToString(bitmap));
     fInfo.push(SkObjectParser::MatrixToString(matrix));
-    if (NULL != paint) {
+    if (paint) {
         fInfo.push(SkObjectParser::PaintToString(*paint));
     }
 }
@@ -337,7 +340,7 @@ SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S
     fBitmap = bitmap;
     fCenter = center;
     fDst = dst;
-    if (NULL != paint) {
+    if (paint) {
         fPaint = *paint;
         fPaintPtr = &fPaint;
     } else {
@@ -347,7 +350,7 @@ SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S
     fInfo.push(SkObjectParser::BitmapToString(bitmap));
     fInfo.push(SkObjectParser::IRectToString(center));
     fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
-    if (NULL != paint) {
+    if (paint) {
         fInfo.push(SkObjectParser::PaintToString(*paint));
     }
 }
@@ -366,14 +369,14 @@ SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const S
                                                  SkCanvas::DrawBitmapRectFlags flags)
     : INHERITED(DRAW_BITMAP_RECT_TO_RECT) {
     fBitmap = bitmap;
-    if (NULL != src) {
+    if (src) {
         fSrc = *src;
     } else {
         fSrc.setEmpty();
     }
     fDst = dst;
 
-    if (NULL != paint) {
+    if (paint) {
         fPaint = *paint;
         fPaintPtr = &fPaint;
     } else {
@@ -382,11 +385,11 @@ SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const S
     fFlags = flags;
 
     fInfo.push(SkObjectParser::BitmapToString(bitmap));
-    if (NULL != src) {
+    if (src) {
         fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
     }
     fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
-    if (NULL != paint) {
+    if (paint) {
         fInfo.push(SkObjectParser::PaintToString(*paint));
     }
     fInfo.push(SkObjectParser::IntToString(fFlags, "Flags: "));
@@ -510,22 +513,24 @@ SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
     , fMatrixPtr(NULL)
     , fPaintPtr(NULL) {
 
-    if (NULL != matrix) {
+    if (matrix) {
         fMatrix = *matrix;
         fMatrixPtr = &fMatrix;
     }
-    if (NULL != paint) {
+    if (paint) {
         fPaint = *paint;
         fPaintPtr = &fPaint;
     }
 
     SkString* temp = new SkString;
-    temp->appendf("SkPicture: W: %d H: %d", picture->width(), picture->height());
+    temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
+                  picture->cullRect().fLeft, picture->cullRect().fTop,
+                  picture->cullRect().fRight, picture->cullRect().fBottom);
     fInfo.push(temp);
-    if (NULL != matrix) {
+    if (matrix) {
         fInfo.push(SkObjectParser::MatrixToString(*matrix));
     }
-    if (NULL != paint) {
+    if (paint) {
         fInfo.push(SkObjectParser::PaintToString(*paint));
     }
 }
@@ -538,9 +543,7 @@ bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
     canvas->clear(0xFFFFFFFF);
     canvas->save();
 
-    SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()),
-                                   SkIntToScalar(fPicture->height()));
-    xlate_and_scale_to_bounds(canvas, bounds);
+    xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
 
     canvas->drawPicture(fPicture.get());
 
@@ -643,6 +646,40 @@ void SkDrawPosTextHCommand::execute(SkCanvas* canvas) {
     canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
 }
 
+SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
+                                             const SkPaint& paint)
+    : INHERITED(DRAW_TEXT_BLOB)
+    , fBlob(blob)
+    , fXPos(x)
+    , fYPos(y)
+    , fPaint(paint) {
+
+    blob->ref();
+
+    // FIXME: push blob info
+    fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
+    fInfo.push(SkObjectParser::ScalarToString(x, "YPOS: "));
+    fInfo.push(SkObjectParser::PaintToString(paint));
+}
+
+void SkDrawTextBlobCommand::execute(SkCanvas* canvas) {
+    canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
+}
+
+bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
+    canvas->clear(SK_ColorWHITE);
+    canvas->save();
+
+    SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
+    xlate_and_scale_to_bounds(canvas, bounds);
+
+    canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
+
+    canvas->restore();
+
+    return true;
+}
+
 SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
     : INHERITED(DRAW_RECT) {
     fRect = rect;
@@ -702,7 +739,7 @@ SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int t
     fBitmap = bitmap;
     fLeft = left;
     fTop = top;
-    if (NULL != paint) {
+    if (paint) {
         fPaint = *paint;
         fPaintPtr = &fPaint;
     } else {
@@ -712,7 +749,7 @@ SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int t
     fInfo.push(SkObjectParser::BitmapToString(bitmap));
     fInfo.push(SkObjectParser::IntToString(left, "Left: "));
     fInfo.push(SkObjectParser::IntToString(top, "Top: "));
-    if (NULL != paint) {
+    if (paint) {
         fInfo.push(SkObjectParser::PaintToString(*paint));
     }
 }
@@ -754,7 +791,7 @@ SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLe
     memcpy(fText, text, byteLength);
     fByteLength = byteLength;
     fPath = path;
-    if (NULL != matrix) {
+    if (matrix) {
         fMatrix = *matrix;
     } else {
         fMatrix.setIdentity();
@@ -763,7 +800,7 @@ SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLe
 
     fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
     fInfo.push(SkObjectParser::PathToString(path));
-    if (NULL != matrix) {
+    if (matrix) {
         fInfo.push(SkObjectParser::MatrixToString(*matrix));
     }
     fInfo.push(SkObjectParser::PaintToString(paint));
@@ -788,14 +825,14 @@ SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver
     fVertices = new SkPoint[vertexCount];
     memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
 
-    if (NULL != texs) {
+    if (texs) {
         fTexs = new SkPoint[vertexCount];
         memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
     } else {
         fTexs = NULL;
     }
 
-    if (NULL != colors) {
+    if (colors) {
         fColors = new SkColor[vertexCount];
         memcpy(fColors, colors, vertexCount * sizeof(SkColor));
     } else {
@@ -803,7 +840,7 @@ SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver
     }
 
     fXfermode = xfermode;
-    if (NULL != fXfermode) {
+    if (fXfermode) {
         fXfermode->ref();
     }
 
@@ -875,13 +912,13 @@ void SkSaveCommand::trackSaveState(int* state) {
 SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
                                        SkCanvas::SaveFlags flags)
     : INHERITED(SAVE_LAYER) {
-    if (NULL != bounds) {
+    if (bounds) {
         fBounds = *bounds;
     } else {
         fBounds.setEmpty();
     }
 
-    if (NULL != paint) {
+    if (paint) {
         fPaint = *paint;
         fPaintPtr = &fPaint;
     } else {
@@ -889,10 +926,10 @@ SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* pain
     }
     fFlags = flags;
 
-    if (NULL != bounds) {
+    if (bounds) {
         fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
     }
-    if (NULL != paint) {
+    if (paint) {
         fInfo.push(SkObjectParser::PaintToString(*paint));
     }
     fInfo.push(SkObjectParser::SaveFlagsToString(flags));