Add NOOP "command" to picture format
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 15 Feb 2013 17:19:15 +0000 (17:19 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 15 Feb 2013 17:19:15 +0000 (17:19 +0000)
https://codereview.appspot.com/7343044/

git-svn-id: http://skia.googlecode.com/svn/trunk@7752 2bbb7eff-a529-9590-31e7-b0007b416f81

debugger/SkDrawCommand.cpp
src/core/SkPicture.cpp
src/core/SkPictureFlat.h
src/core/SkPicturePlayback.cpp
src/core/SkPictureRecord.cpp

index b1855955308a5cded3e91b737503d475d88c7830..89c338d8c1e688bf7263a62eb07b78b49424fbd2 100644 (file)
@@ -55,6 +55,7 @@ const char* SkDrawCommand::GetCommandString(DrawType type) {
         case SET_MATRIX: return "Set Matrix";
         case SKEW: return "Skew";
         case TRANSLATE: return "Translate";
+        case NOOP: return "NoOp";
         default:
             SkDebugf("DrawType error 0x%08x\n", type);
             SkASSERT(0);
index 3e464e0eb79f7bed03497978ff712299814d85b5..58fc0c33abc3ce3f7de362cacd93f874f48480d6 100644 (file)
@@ -52,28 +52,39 @@ const char* DrawTypeToString(DrawType drawType) {
         case CLIP_PATH: return "CLIP_PATH";
         case CLIP_REGION: return "CLIP_REGION";
         case CLIP_RECT: return "CLIP_RECT";
+        case CLIP_RRECT: return "CLIP_RRECT";
         case CONCAT: return "CONCAT";
         case DRAW_BITMAP: return "DRAW_BITMAP";
         case DRAW_BITMAP_MATRIX: return "DRAW_BITMAP_MATRIX";
-        case DRAW_BITMAP_RECT: return "DRAW_BITMAP_RECT";
+        case DRAW_BITMAP_NINE: return "DRAW_BITMAP_NINE";
+        case DRAW_BITMAP_RECT_TO_RECT: return "DRAW_BITMAP_RECT_TO_RECT";
+        case DRAW_CLEAR: return "DRAW_CLEAR";
+        case DRAW_DATA: return "DRAW_DATA";
+        case DRAW_OVAL: return "DRAW_OVAL";
         case DRAW_PAINT: return "DRAW_PAINT";
         case DRAW_PATH: return "DRAW_PATH";
         case DRAW_PICTURE: return "DRAW_PICTURE";
         case DRAW_POINTS: return "DRAW_POINTS";
         case DRAW_POS_TEXT: return "DRAW_POS_TEXT";
+        case DRAW_POS_TEXT_TOP_BOTTOM: return "DRAW_POS_TEXT_TOP_BOTTOM";
         case DRAW_POS_TEXT_H: return "DRAW_POS_TEXT_H";
-        case DRAW_RECT_GENERAL: return "DRAW_RECT_GENERAL";
-        case DRAW_RECT_SIMPLE: return "DRAW_RECT_SIMPLE";
+        case DRAW_POS_TEXT_H_TOP_BOTTOM: return "DRAW_POS_TEXT_H_TOP_BOTTOM";
+        case DRAW_RECT: return "DRAW_RECT";
+        case DRAW_RRECT: return "DRAW_RRECT";
         case DRAW_SPRITE: return "DRAW_SPRITE";
         case DRAW_TEXT: return "DRAW_TEXT";
         case DRAW_TEXT_ON_PATH: return "DRAW_TEXT_ON_PATH";
+        case DRAW_TEXT_TOP_BOTTOM: return "DRAW_TEXT_TOP_BOTTOM";
+        case DRAW_VERTICES: return "DRAW_VERTICES";
         case RESTORE: return "RESTORE";
         case ROTATE: return "ROTATE";
         case SAVE: return "SAVE";
         case SAVE_LAYER: return "SAVE_LAYER";
         case SCALE: return "SCALE";
+        case SET_MATRIX: return "SET_MATRIX";
         case SKEW: return "SKEW";
         case TRANSLATE: return "TRANSLATE";
+        case NOOP: return "NOOP";
         default:
             SkDebugf("DrawType error 0x%08x\n", drawType);
             SkASSERT(0);
index e577f79348a1dfb44e8dac387868cddf666d9b08..a9db48d96ce1eeab967ee96a67443bffc4da9ebe 100644 (file)
@@ -61,8 +61,9 @@ enum DrawType {
     SET_MATRIX,
     SKEW,
     TRANSLATE,
+    NOOP,
 
-    LAST_DRAWTYPE_ENUM = TRANSLATE
+    LAST_DRAWTYPE_ENUM = NOOP
 };
 
 enum DrawVertexFlags {
index 3b76ab2101baa339daf2f27f4d7c9954ff68a712..c6c26ff3ae3e7ae08f8d2ad926f1bbe660da3c8b 100644 (file)
@@ -630,7 +630,11 @@ void SkPicturePlayback::postDraw(size_t offset) {
 #endif
 
 /*
- * Read the next op code and chunk size from 'reader'
+ * Read the next op code and chunk size from 'reader'. The returned size
+ * is the entire size of the chunk (including the opcode). Thus, the 
+ * offset just prior to calling read_op_and_size + 'size' is the offset
+ * to the next chunk's op code. This also means that the size of a chunk 
+ * with no arguments (just an opcode) will be 4.
  */
 static DrawType read_op_and_size(SkReader32* reader, uint32_t* size) {
     uint32_t temp = reader->readInt();
@@ -715,6 +719,12 @@ void SkPicturePlayback::draw(SkCanvas& canvas) {
 #endif
         uint32_t size;
         DrawType op = read_op_and_size(&reader, &size);
+        if (NOOP == op) {
+            // NOOPs are to be ignored - do not propagate them any further
+            reader.setOffset(curOffset+size);
+            continue;
+        }
+
 #ifdef SK_DEVELOPER
         // TODO: once chunk sizes are in all .skps just use "curOffset + size"
         size_t skipTo = this->preDraw(curOffset, op);
index 5180e5ed6cb2ab008ce527c8facb4733668e0e87..762c1e76bc985b1ef167d24e27794cbe1cd9a7e0 100644 (file)
@@ -190,6 +190,39 @@ static bool collapseSaveClipRestore(SkWriter32* writer, int32_t offset) {
     return true;
 }
 
+// This function is just a toy example and will not be delivered with this
+// CL
+static bool noClips(SkWriter32* writer, int32_t offset) {
+
+    int32_t restoreOffset = (int32_t)writer->size();
+
+    // back up to the save block
+    while (offset > 0) {
+        offset = *writer->peek32(offset);
+    }
+
+    // now offset points to a save
+    offset = -offset;
+    uint32_t opSize;
+    DrawType op = peek_op_and_size(writer, offset, &opSize);
+    SkASSERT(SAVE == op || SAVE_LAYER == op);
+
+    // Walk forward until until we hit our restore, nuking all clips
+    // along the way
+    offset += opSize;
+    while (offset < restoreOffset) {
+        op = peek_op_and_size(writer, offset, &opSize);
+
+        if (CLIP_RECT == op || CLIP_RRECT == op) {
+            uint32_t* ptr = writer->peek32(offset);
+            *ptr = (*ptr & MASK_24) | (NOOP << 24);
+        }
+        offset += opSize;
+    }
+
+    return true;
+}
+
 void SkPictureRecord::restore() {
     // FIXME: SkDeferredCanvas needs to be refactored to respect
     // save/restore balancing so that the following test can be
@@ -207,6 +240,9 @@ void SkPictureRecord::restore() {
         fFirstSavedLayerIndex = kNoSavedLayerIndex;
     }
 
+    // This call will not be delivered either
+    noClips(&fWriter, fRestoreOffsetStack.top());
+
     uint32_t initialOffset, size;
     if (!collapseSaveClipRestore(&fWriter, fRestoreOffsetStack.top())) {
         fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.size());