First cut at cleaning up Sergio's example code and moving some common code to SkWindow.

Eventually, this will be moved to be a peer of SampleApp so it is compiled by the bots to avoid future bit rot.

Also ignore XCode auto-generated flag in CommandLineFlags, and remove the unused multiple-example part.

Review URL: https://codereview.chromium.org/890873003
diff --git a/experimental/SkiaExamples/HelloSkiaExample.cpp b/experimental/SkiaExamples/HelloSkiaExample.cpp
deleted file mode 100644
index 6fd2624..0000000
--- a/experimental/SkiaExamples/HelloSkiaExample.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- */
-
-#include "SkExample.h"
-
-#include "SkApplication.h"
-#include "SkDraw.h"
-#include "SkGradientShader.h"
-#include "SkGraphics.h"
-
-class HelloSkia : public SkExample {
-public:
-    HelloSkia(SkExampleWindow* window) : SkExample(window) {
-        fName = "HelloSkia";
-        fBGColor = SK_ColorWHITE;
-        fRotationAngle = SkIntToScalar(0);
-
-        fWindow->setupBackend(SkExampleWindow::kGPU_DeviceType);
-        // Another option is software rendering:
-        // fWindow->setupBackend(SkExampleWindow::kRaster_DeviceType);
-    }
-
-protected:
-    void draw(SkCanvas* canvas) {
-        // Clear background
-        canvas->drawColor(fBGColor);
-
-        SkPaint paint;
-        paint.setColor(SK_ColorRED);
-
-        // Draw a rectangle with blue paint
-        SkRect rect = {
-                SkIntToScalar(10), SkIntToScalar(10),
-                SkIntToScalar(128), SkIntToScalar(128)
-        };
-        canvas->drawRect(rect, paint);
-
-        // Set up a linear gradient and draw a circle
-        {
-            SkPoint linearPoints[] = {
-                    {SkIntToScalar(0), SkIntToScalar(0)},
-                    {SkIntToScalar(300), SkIntToScalar(300)}
-            };
-            SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK};
-
-            SkShader* shader = SkGradientShader::CreateLinear(
-                    linearPoints, linearColors, NULL, 2,
-                    SkShader::kMirror_TileMode);
-            SkAutoUnref shader_deleter(shader);
-
-            paint.setShader(shader);
-            paint.setFlags(SkPaint::kAntiAlias_Flag);
-
-            canvas->drawCircle(SkIntToScalar(200), SkIntToScalar(200),
-                    SkIntToScalar(64), paint);
-
-            // Detach shader
-            paint.setShader(NULL);
-        }
-
-        // Draw a message with a nice black paint.
-        paint.setFlags(
-                SkPaint::kAntiAlias_Flag |
-                SkPaint::kSubpixelText_Flag |  // ... avoid waggly text when rotating.
-                SkPaint::kUnderlineText_Flag);
-        paint.setColor(SK_ColorBLACK);
-        paint.setTextSize(SkIntToScalar(20));
-
-        canvas->save();
-
-        static const char message[] = "Hello Skia!!!";
-
-        // Translate and rotate
-        canvas->translate(SkIntToScalar(300), SkIntToScalar(300));
-        fRotationAngle += SkDoubleToScalar(0.2);
-        if (fRotationAngle > SkDoubleToScalar(360.0)) {
-            fRotationAngle -= SkDoubleToScalar(360.0);
-        }
-        canvas->rotate(fRotationAngle);
-
-        // Draw the text:
-        canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntToScalar(0), paint);
-
-        canvas->restore();
-
-        // Invalidate the window to force a redraw. Poor man's animation mechanism.
-        this->fWindow->inval(NULL);
-    }
-
-private:
-    SkScalar fRotationAngle;
-    SkColor fBGColor;
-};
-
-static SkExample* MyFactory(SkExampleWindow* window) {
-    return new HelloSkia(window);
-}
-
-// Register this class as a Skia Example.
-SkExample::Registry registry(MyFactory);
diff --git a/experimental/SkiaExamples/SkExample.cpp b/experimental/SkiaExamples/SkExample.cpp
index 637ec9d..849c14b 100644
--- a/experimental/SkiaExamples/SkExample.cpp
+++ b/experimental/SkiaExamples/SkExample.cpp
@@ -9,22 +9,12 @@
 
 #include "SkExample.h"
 
-#include "gl/GrGLUtil.h"
-#include "gl/GrGLDefines.h"
 #include "gl/GrGLInterface.h"
 #include "SkApplication.h"
-#include "SkCommandLineFlags.h"
-#include "SkGpuDevice.h"
+#include "SkCanvas.h"
+#include "SkGradientShader.h"
 #include "SkGraphics.h"
-
-DEFINE_string2(match, m, NULL, "[~][^]substring[$] [...] of test name to run.\n" \
-                               "Multiple matches may be separated by spaces.\n" \
-                               "~ causes a matching test to always be skipped\n" \
-                               "^ requires the start of the test to match\n" \
-                               "$ requires the end of the test to match\n" \
-                               "^ and $ requires an exact match\n" \
-                               "If a test does not match any list entry,\n" \
-                               "it is skipped unless some list entry starts with ~");
+#include "SkGr.h"
 
 void application_init() {
     SkGraphics::Init();
@@ -38,36 +28,37 @@
 
 SkExampleWindow::SkExampleWindow(void* hwnd)
     : INHERITED(hwnd) {
-    fRegistry = SkExample::Registry::Head();
-    fCurrExample = fRegistry->factory()(this);
+    fType = SkExampleWindow::kGPU_DeviceType;
+    fRenderTarget = NULL;
+    fRotationAngle = 0;
+    this->setTitle();
+    this->setUpBackend();
+}
 
-    if (FLAGS_match.count()) {
-        // Start with the a matching sample if possible.
-        bool found = this->findNextMatch();
-        if (!found) {
-            SkDebugf("No matching SkExample found.\n");
-        }
-    }
+SkExampleWindow::~SkExampleWindow() {
+    tearDownBackend();
 }
 
 void SkExampleWindow::tearDownBackend() {
-  if (kGPU_DeviceType == fType) {
-        SkSafeUnref(fContext);
-        fContext = NULL;
+    SkSafeUnref(fContext);
+    fContext = NULL;
 
-        SkSafeUnref(fInterface);
-        fInterface = NULL;
+    SkSafeUnref(fInterface);
+    fInterface = NULL;
 
-        SkSafeUnref(fRenderTarget);
-        fRenderTarget = NULL;
+    SkSafeUnref(fRenderTarget);
+    fRenderTarget = NULL;
 
-        detach();
-    }
+    INHERITED::detach();
 }
 
-bool SkExampleWindow::setupBackend(DeviceType type) {
-    fType = type;
+void SkExampleWindow::setTitle() {
+    SkString title("SkiaExample ");
+    title.appendf(fType == kRaster_DeviceType ? "raster" : "opengl");
+    INHERITED::setTitle(title.c_str());
+}
 
+bool SkExampleWindow::setUpBackend() {
     this->setColorType(kRGBA_8888_SkColorType);
     this->setVisibleP(true);
     this->setClipToBounds(false);
@@ -86,109 +77,117 @@
     fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInterface);
     SkASSERT(NULL != fContext);
 
-    setupRenderTarget();
-
+    this->setUpRenderTarget();
     return true;
 }
 
-void SkExampleWindow::setupRenderTarget() {
-    GrBackendRenderTargetDesc desc;
-    desc.fWidth = SkScalarRoundToInt(width());
-    desc.fHeight = SkScalarRoundToInt(height());
-    desc.fConfig = kSkia8888_GrPixelConfig;
-    desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
-    desc.fSampleCnt = fAttachmentInfo.fSampleCount;
-    desc.fStencilBits = fAttachmentInfo.fStencilBits;
-
-    GrGLint buffer;
-    GR_GL_GetIntegerv(fInterface, GR_GL_FRAMEBUFFER_BINDING, &buffer);
-    desc.fRenderTargetHandle = buffer;
-
-    fRenderTarget = fContext->wrapBackendRenderTarget(desc);
-
-    fContext->setRenderTarget(fRenderTarget);
+void SkExampleWindow::setUpRenderTarget() {
+    SkSafeUnref(fRenderTarget);
+    fRenderTarget = this->renderTarget(fAttachmentInfo, fInterface, fContext);
 }
 
-SkCanvas* SkExampleWindow::createCanvas() {
-    if (fType == kGPU_DeviceType) {
-        if (NULL != fContext && NULL != fRenderTarget) {
-            SkAutoTUnref<SkBaseDevice> device(new SkGpuDevice(fContext, fRenderTarget));
-            return new SkCanvas(device);
-        }
-        tearDownBackend();
-        setupBackend(kRaster_DeviceType);
+void SkExampleWindow::drawContents(SkCanvas* canvas) {
+    // Clear background
+    canvas->drawColor(SK_ColorWHITE);
+
+    SkPaint paint;
+    paint.setColor(SK_ColorRED);
+
+    // Draw a rectangle with red paint
+    SkRect rect = {
+            10, 10,
+            128, 128
+    };
+    canvas->drawRect(rect, paint);
+
+    // Set up a linear gradient and draw a circle
+    {
+        SkPoint linearPoints[] = {
+                {0, 0},
+                {300, 300}
+        };
+        SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK};
+
+        SkShader* shader = SkGradientShader::CreateLinear(
+                linearPoints, linearColors, NULL, 2,
+                SkShader::kMirror_TileMode);
+        SkAutoUnref shader_deleter(shader);
+
+        paint.setShader(shader);
+        paint.setFlags(SkPaint::kAntiAlias_Flag);
+
+        canvas->drawCircle(200, 200, 64, paint);
+
+        // Detach shader
+        paint.setShader(NULL);
     }
-    return INHERITED::createCanvas();
+
+    // Draw a message with a nice black paint.
+    paint.setFlags(
+            SkPaint::kAntiAlias_Flag |
+            SkPaint::kSubpixelText_Flag |  // ... avoid waggly text when rotating.
+            SkPaint::kUnderlineText_Flag);
+    paint.setColor(SK_ColorBLACK);
+    paint.setTextSize(20);
+
+    canvas->save();
+
+    static const char message[] = "Hello Skia!!!";
+
+    // Translate and rotate
+    canvas->translate(300, 300);
+    fRotationAngle += 0.2f;
+    if (fRotationAngle > 360) {
+        fRotationAngle -= 360;
+    }
+    canvas->rotate(fRotationAngle);
+
+    // Draw the text:
+    canvas->drawText(message, strlen(message), 0, 0, paint);
+
+    canvas->restore();
 }
 
 void SkExampleWindow::draw(SkCanvas* canvas) {
-    if (NULL != fCurrExample) {
-        fCurrExample->draw(canvas);
-    }
-    if (fType == kGPU_DeviceType) {
+    drawContents(canvas);
+    // in case we have queued drawing calls
+    fContext->flush();
+    // Invalidate the window to force a redraw. Poor man's animation mechanism.
+    this->inval(NULL);
 
-        SkASSERT(NULL != fContext);
-        fContext->flush();
-    }
-    if (fType == kRaster_DeviceType) {
+    if (kRaster_DeviceType == fType) {
         // need to send the raster bits to the (gpu) window
-        fContext->setRenderTarget(fRenderTarget);
-        const SkBitmap& bm = getBitmap();
-        fRenderTarget->writePixels(0, 0, bm.width(), bm.height(),
-                                      kSkia8888_GrPixelConfig,
-                                      bm.getPixels(),
-                                      bm.rowBytes());
+        SkImage* snap = fSurface->newImageSnapshot();
+        size_t rowBytes;
+        SkImageInfo info;
+        const void* pixels = snap->peekPixels(&info, &rowBytes);
+        fRenderTarget->writePixels(0, 0, snap->width(), snap->height(),
+                                        SkImageInfo2GrPixelConfig(info.colorType(),
+                                                                info.alphaType(),
+                                                                info.profileType()),
+                                        pixels,
+                                        rowBytes,
+                                        GrContext::kFlushWrites_PixelOp);
+        SkSafeUnref(snap);
     }
     INHERITED::present();
 }
 
 void SkExampleWindow::onSizeChange() {
-    setupRenderTarget();
-}
-
-#ifdef SK_BUILD_FOR_WIN
-void SkExampleWindow::onHandleInval(const SkIRect& rect) {
-    RECT winRect;
-    winRect.top = rect.top();
-    winRect.bottom = rect.bottom();
-    winRect.right = rect.right();
-    winRect.left = rect.left();
-    InvalidateRect((HWND)this->getHWND(), &winRect, false);
-}
-#endif
-
-bool SkExampleWindow::findNextMatch() {
-    bool found = false;
-    // Avoid infinite loop by knowing where we started.
-    const SkExample::Registry* begin = fRegistry;
-    while (!found) {
-        fRegistry = fRegistry->next();
-        if (NULL == fRegistry) {  // Reached the end of the registered samples. GOTO head.
-            fRegistry = SkExample::Registry::Head();
-        }
-        SkExample* next = fRegistry->factory()(this);
-        if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, next->getName().c_str())) {
-            fCurrExample = next;
-            found = true;
-        }
-        if (begin == fRegistry) {  // We looped through every sample without finding anything.
-            break;
-        }
-    }
-    return found;
+    setUpRenderTarget();
 }
 
 bool SkExampleWindow::onHandleChar(SkUnichar unichar) {
-    if ('n' == unichar) {
-        bool found = findNextMatch();
-        if (!found) {
-            SkDebugf("No SkExample that matches your query\n");
-        }
+    if (' ' == unichar) {
+        fType = fType == kRaster_DeviceType ? kGPU_DeviceType: kRaster_DeviceType;
+        tearDownBackend();
+        setUpBackend();
+        this->setTitle();
+        this->inval(NULL);
     }
     return true;
 }
 
-SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
-    SkCommandLineFlags::Parse(argc, argv);
+SkOSWindow* create_sk_window(void* hwnd, int , char** ) {
     return new SkExampleWindow(hwnd);
 }
diff --git a/experimental/SkiaExamples/SkExample.h b/experimental/SkiaExamples/SkExample.h
index ee9e36e..4f4b10b 100644
--- a/experimental/SkiaExamples/SkExample.h
+++ b/experimental/SkiaExamples/SkExample.h
@@ -10,6 +10,7 @@
 #ifndef SkExample_DEFINED
 #define SkExample_DEFINED
 
+#include "SkSurface.h"
 #include "SkWindow.h"
 #include "SkTRegistry.h"
 
@@ -44,33 +45,42 @@
         kGPU_DeviceType,
     };
     SkExampleWindow(void* hwnd);
+    virtual ~SkExampleWindow() SK_OVERRIDE;
 
     // Changes the device type of the object.
-    bool setupBackend(DeviceType type);
-    void tearDownBackend();
+    bool setUpBackend();
 
     DeviceType getDeviceType() const { return fType; }
 
 protected:
+    SkSurface* createSurface() SK_OVERRIDE {
+        if (kGPU_DeviceType == fType) {
+            SkSurfaceProps props(INHERITED::getSurfaceProps());
+            return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
+        }
+        static const SkImageInfo info = SkImageInfo::MakeN32Premul(
+                SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this->height()));
+        return fSurface = SkSurface::NewRaster(info);
+   }
+
     void draw(SkCanvas* canvas) SK_OVERRIDE;
+    void drawContents(SkCanvas* canvas);
 
     void onSizeChange() SK_OVERRIDE;
 
-#ifdef SK_BUILD_FOR_WIN
-    void onHandleInval(const SkIRect&) SK_OVERRIDE;
-#endif
-
-    SkCanvas* createCanvas() SK_OVERRIDE;
-
 private:
     bool findNextMatch();  // Set example to the first one that matches FLAGS_match.
-    void setupRenderTarget();
+    void setTitle();
+    void setUpRenderTarget();
     bool onHandleChar(SkUnichar unichar) SK_OVERRIDE;
+    void tearDownBackend();
 
+    // draw contents
+    SkScalar fRotationAngle;
+
+    // support framework
     DeviceType fType;
-
-    SkExample* fCurrExample;
-    const SkExample::Registry* fRegistry;
+    SkSurface* fSurface;
     GrContext* fContext;
     GrRenderTarget* fRenderTarget;
     AttachmentInfo fAttachmentInfo;
diff --git a/gyp/experimental.gyp b/gyp/experimental.gyp
index ffc1753..ff7e144 100644
--- a/gyp/experimental.gyp
+++ b/gyp/experimental.gyp
@@ -26,7 +26,6 @@
       'sources': [
         '../experimental/SkiaExamples/SkExample.h',
         '../experimental/SkiaExamples/SkExample.cpp',
-        '../experimental/SkiaExamples/HelloSkiaExample.cpp',
       ],
       'dependencies': [
         'flags.gyp:flags',
@@ -36,7 +35,7 @@
       'conditions' : [
         [ 'skia_gpu == 1', {
           'include_dirs' : [
-            '../src/gpu',
+            '../include/gpu',
           ],
         }],
         [ 'skia_os == "win"', {
diff --git a/gyp/views.gyp b/gyp/views.gyp
index 55fb6da..381e125 100644
--- a/gyp/views.gyp
+++ b/gyp/views.gyp
@@ -77,6 +77,11 @@
         '../src/views/SDL/SkOSWindow_SDL.cpp',
       ],
       'conditions': [
+        [ 'skia_gpu == 1', {
+          'include_dirs' : [
+            '../src/gpu',
+          ],
+        }],
         [ 'skia_os == "mac"', {
           'link_settings': {
             'libraries': [
diff --git a/include/views/SkOSWindow_Android.h b/include/views/SkOSWindow_Android.h
index 9b0dcb2..3b23d29 100644
--- a/include/views/SkOSWindow_Android.h
+++ b/include/views/SkOSWindow_Android.h
@@ -20,11 +20,6 @@
         kNativeGL_BackEndType,
     };
 
-    struct AttachmentInfo {
-        int fSampleCount;
-        int fStencilBits;
-    };
-
     bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo* info);
     void detach() {}
     void present() {}
diff --git a/include/views/SkOSWindow_Mac.h b/include/views/SkOSWindow_Mac.h
index 5dea2fc..2a15bf5 100644
--- a/include/views/SkOSWindow_Mac.h
+++ b/include/views/SkOSWindow_Mac.h
@@ -26,11 +26,6 @@
 #endif
     };
 
-    struct AttachmentInfo {
-        int fSampleCount;
-        int fStencilBits;
-    };
-
     void    detach();
     bool    attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*);
     void    present();
diff --git a/include/views/SkOSWindow_NaCl.h b/include/views/SkOSWindow_NaCl.h
index 317ef9f..2626337 100644
--- a/include/views/SkOSWindow_NaCl.h
+++ b/include/views/SkOSWindow_NaCl.h
@@ -20,11 +20,6 @@
         kNativeGL_BackEndType,
     };
 
-    struct AttachmentInfo {
-        int fSampleCount;
-        int fStencilBits;
-    };
-
     bool attach(SkBackEndTypes /* attachType */, int /* msaaSampleCount */, AttachmentInfo* info) {
         info->fSampleCount = 0;
         info->fStencilBits = 0;
diff --git a/include/views/SkOSWindow_Unix.h b/include/views/SkOSWindow_Unix.h
index 525123c..8c4d819 100644
--- a/include/views/SkOSWindow_Unix.h
+++ b/include/views/SkOSWindow_Unix.h
@@ -38,11 +38,6 @@
         kNativeGL_BackEndType,
     };
 
-    struct AttachmentInfo {
-        int fSampleCount;
-        int fStencilBits;
-    };
-
     bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*);
     void detach();
     void present();
diff --git a/include/views/SkOSWindow_Win.h b/include/views/SkOSWindow_Win.h
index 6b5977c..fe65459 100644
--- a/include/views/SkOSWindow_Win.h
+++ b/include/views/SkOSWindow_Win.h
@@ -37,11 +37,6 @@
 #endif // SK_SUPPORT_GPU
     };
 
-    struct AttachmentInfo {
-        int fSampleCount;
-        int fStencilBits;
-    };
-
     bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*);
     void detach();
     void present();
diff --git a/include/views/SkOSWindow_iOS.h b/include/views/SkOSWindow_iOS.h
index 1984900..f386c73 100644
--- a/include/views/SkOSWindow_iOS.h
+++ b/include/views/SkOSWindow_iOS.h
@@ -21,11 +21,6 @@
         kNativeGL_BackEndType,
     };
 
-    struct AttachmentInfo {
-        int fSampleCount;
-        int fStencilBits;
-    };
-
     void    detach();
     bool    attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*);
     void    present();
diff --git a/include/views/SkWindow.h b/include/views/SkWindow.h
index e18aff3..76a1aa5 100644
--- a/include/views/SkWindow.h
+++ b/include/views/SkWindow.h
@@ -25,11 +25,22 @@
 class SkSurface;
 class SkOSMenu;
 
+#if SK_SUPPORT_GPU
+struct GrGLInterface;
+class GrContext;
+class GrRenderTarget;
+#endif
+
 class SkWindow : public SkView {
 public:
             SkWindow();
     virtual ~SkWindow();
 
+    struct AttachmentInfo {
+        int fSampleCount;
+        int fStencilBits;
+    };
+
     SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
     void setSurfaceProps(const SkSurfaceProps& props) {
         fSurfaceProps = props;
@@ -85,6 +96,11 @@
     virtual bool onGetFocusView(SkView** focus) const;
     virtual bool onSetFocusView(SkView* focus);
 
+#if SK_SUPPORT_GPU
+    GrRenderTarget* renderTarget(const AttachmentInfo& attachmentInfo,
+                                 const GrGLInterface* , GrContext* grContext);
+#endif
+
 private:
     SkSurfaceProps  fSurfaceProps;
     SkColorType fColorType;
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index aa2130e..dd771ce 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -315,20 +315,8 @@
         if (fCurContext) {
             AttachmentInfo attachmentInfo;
             win->attach(fBackend, fMSAASampleCount, &attachmentInfo);
-
-            GrBackendRenderTargetDesc desc;
-            desc.fWidth = SkScalarRoundToInt(win->width());
-            desc.fHeight = SkScalarRoundToInt(win->height());
-            desc.fConfig = kSkia8888_GrPixelConfig;
-            desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
-            desc.fSampleCnt = attachmentInfo.fSampleCount;
-            desc.fStencilBits = attachmentInfo.fStencilBits;
-            GrGLint buffer;
-            GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer);
-            desc.fRenderTargetHandle = buffer;
-
             SkSafeUnref(fCurRenderTarget);
-            fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
+            fCurRenderTarget = win->renderTarget(attachmentInfo, fCurIntf, fCurContext);
         }
 #endif
     }
diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp
index 7870d06..61eaa97 100644
--- a/src/views/SkWindow.cpp
+++ b/src/views/SkWindow.cpp
@@ -341,3 +341,26 @@
     }
     return handled;
 }
+
+#if SK_SUPPORT_GPU
+
+#include "gl/GrGLInterface.h"
+#include "gl/GrGLUtil.h"
+#include "SkGr.h"
+
+GrRenderTarget* SkWindow::renderTarget(const AttachmentInfo& attachmentInfo,
+        const GrGLInterface* interface, GrContext* grContext) {
+    GrBackendRenderTargetDesc desc;
+    desc.fWidth = SkScalarRoundToInt(this->width());
+    desc.fHeight = SkScalarRoundToInt(this->height());
+    desc.fConfig = kSkia8888_GrPixelConfig;
+    desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
+    desc.fSampleCnt = attachmentInfo.fSampleCount;
+    desc.fStencilBits = attachmentInfo.fStencilBits;
+    GrGLint buffer;
+    GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer);
+    desc.fRenderTargetHandle = buffer;
+    return grContext->wrapBackendRenderTarget(desc);
+}
+
+#endif
diff --git a/tools/flags/SkCommandLineFlags.cpp b/tools/flags/SkCommandLineFlags.cpp
index dc99fec..50c193f 100644
--- a/tools/flags/SkCommandLineFlags.cpp
+++ b/tools/flags/SkCommandLineFlags.cpp
@@ -303,6 +303,11 @@
                 flag = flag->next();
             }
             if (!flagMatched) {
+#if SK_BUILD_FOR_MAC
+                if (SkStrStartsWith(argv[i], "NSDocumentRevisions")) {
+                        i++;  // skip YES
+                } else
+#endif
                 if (!FLAGS_undefok) {
                     SkDebugf("Got unknown flag \"%s\". Exiting.\n", argv[i]);
                     exit(-1);