Using skia on windows

Skia is an open source 2D graphics library which provides common APIs that work across a variety of hardware and software platforms. It serves as the graphics engine for Google Chrome and Chrome OS, Android, Mozilla Firefox and Firefox OS, and many other products. Skia is an alternative to the Cairo library.

Posting this in case it helps anyone else.

Prerequisites:
Visual Studio 2013 (including the express or community editions, which are free)
Unzipping tool like 7zip, WinRAR

The command prompt lines below should be run in the same session (i.e. it won't work if you close and reopen a new command prompt).

Now, to create an example project that doesn't need Google's gyp system: Then, add a main.cpp to the project, with the following code,
#include <string>
#include <fstream>

#include "SkCanvas.h"
#include "SkData.h"
#include "SkDocument.h"
#include "SkGraphics.h"
#include "SkSurface.h"
#include "SkImage.h"
#include "SkStream.h"
#include "SkString.h"

#include "..\effects\SkGradientShader.h"

void save_ppm(SkBitmap const& bitmap, std::string const& filename)
{
  SkAutoLockPixels l(bitmap);

  std::ofstream ofile(filename.c_str(), std::ios_base::binary | std::ios_base::trunc);
  if (ofile.is_open())
  {
    ofile << "P6 " << bitmap.width() << " " << bitmap.height() << " 255 ";

    for (int i = 0; i != bitmap.height(); i++)
    {
      for (int j = 0; j != bitmap.width(); j++)
      {
        SkColor const* c = bitmap.getAddr32(j, i);
        char buf[3] = { SkColorGetR(*c), SkColorGetG(*c), SkColorGetB(*c) };
        ofile.write(buf, 3);
      }
    }
  }
}

void TestSkia(SkCanvas& canvas)
{
  SkPaint paint;
  paint.setAntiAlias(true);
  paint.setColor(SK_ColorRED);
  SkRect rect = {
    20, 20,
    50, 50
  };
  canvas.drawRect(rect, paint);
}

int main(int argc, char * const argv[])
{
  SkAutoGraphics ag;
  SkBitmap bitmap;
  int width = 800;
  int height = 600;
  bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
  SkCanvas canvas(bitmap);
  canvas.drawColor(SK_ColorWHITE);

  TestSkia(canvas);

  save_ppm(bitmap, "out.ppm");
  return 0;
}

// stub out openGl dependency, which isn't needed in this case.
extern "C"
{
#ifdef _WIN64
  PROC WINAPI __imp_wglGetProcAddress(LPCSTR)
  {
    abort();
    return nullptr;
  }
  
  HGLRC WINAPI  __imp_wglGetCurrentContext()
  {
    abort();
    return nullptr;
  }
#else
  PROC WINAPI _imp__wglGetProcAddress(LPCSTR)
  {
    abort();
    return nullptr;
  }

  HGLRC WINAPI _imp__wglGetCurrentContext()
  {
    abort();
    return nullptr;
  }
#endif
}


Running this little program will create a valid ppm file with a red rectangle!



To build for x64, you can create a new x64 target and update the lib directories from c:\path\to\skia\out86 to c:\path\to\skia\out64.

To add codecs for saving to different image types:

To add OpenGL:

Sources:
Install Depot Tools
Skia Quick Start Guides Windows