In bench_pictures, use a pool of tiles for multicore drawing.

Also includes some code cleanup and code sharing.

Allow setting the number of threads on the command line.

Rename ThreadSafePipeController::playback to ::draw, to be the same
as SkPicture so DrawTileToCanvas can take a template parameter.

Disallow multithreading with GPU turned on.

Display help information with improper tiled arguments.

BUG=https://code.google.com/p/skia/issues/detail?id=871

Review URL: https://codereview.appspot.com/6536050

git-svn-id: http://skia.googlecode.com/svn/trunk@5602 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h
index 5ae3f29..845aa9f 100644
--- a/tools/PictureRenderer.h
+++ b/tools/PictureRenderer.h
@@ -23,6 +23,7 @@
 class SkBitmap;
 class SkCanvas;
 class SkGLContext;
+class ThreadSafePipeController;
 
 namespace sk_tools {
 
@@ -98,7 +99,7 @@
 
 protected:
     SkCanvas* setupCanvas();
-    SkCanvas* setupCanvas(int width, int height);
+    virtual SkCanvas* setupCanvas(int width, int height);
 
     SkAutoTUnref<SkCanvas> fCanvas;
     SkPicture* fPicture;
@@ -146,6 +147,7 @@
     TiledPictureRenderer();
 
     virtual void init(SkPicture* pict) SK_OVERRIDE;
+    virtual void setup() SK_OVERRIDE;
     virtual void render(bool doExtraWorkToDrawToBaseCanvas) SK_OVERRIDE;
     virtual void end() SK_OVERRIDE;
 
@@ -194,8 +196,11 @@
         return fTileMinPowerOf2Width;
     }
 
-    void setMultiThreaded(bool multi) {
-        fMultiThreaded = multi;
+    /**
+     * Set the number of threads to use for drawing. Non-positive numbers will set it to 1.
+     */
+    void setNumberOfThreads(int num) {
+        fNumThreads = SkMax32(num, 1);
     }
 
     void setUsePipe(bool usePipe) {
@@ -205,19 +210,25 @@
     ~TiledPictureRenderer();
 
 private:
-    bool fMultiThreaded;
-    bool fUsePipe;
-    int fTileWidth;
-    int fTileHeight;
-    double fTileWidthPercentage;
-    double fTileHeightPercentage;
-    int fTileMinPowerOf2Width;
-
+    bool              fUsePipe;
+    int               fTileWidth;
+    int               fTileHeight;
+    double            fTileWidthPercentage;
+    double            fTileHeightPercentage;
+    int               fTileMinPowerOf2Width;
     SkTDArray<SkRect> fTileRects;
 
+    // These are only used for multithreaded rendering
+    int32_t                   fTileCounter;
+    int                       fNumThreads;
+    SkTDArray<SkCanvas*>      fCanvasPool;
+    SkPicture*                fPictureClones;
+    ThreadSafePipeController* fPipeController;
+
     void setupTiles();
     void setupPowerOf2Tiles();
-    void deleteTiles();
+    virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
+    bool multiThreaded() { return fNumThreads > 1; }
 
     typedef PictureRenderer INHERITED;
 };