Using Skia in Windows

2,271 views
Skip to first unread message

nrc

unread,
Jul 25, 2012, 7:16:13 AM7/25/12
to skia-d...@googlegroups.com
Hi, what is the best way to use Skia in a toy native Windows application? I've built Skia using Visual Studio and can use it as a lib, but I don't know how to get from an SkCanvas to the screen. The only advice from the web was to use an SkPlatformCanvas (or SkPlatformCanvasPaint) instead of an SkCanvas, but these classes seem to have disappeared.

Put another way, what is the Skia equivalent to something like

            cairo_surface_t* surface = cairo_win32_surface_create(hdc);
            cairo_t* ctxt = cairo_create(surface);

in Cairo?

Thanks, Nick

Chandramouli Sanchi

unread,
Jul 25, 2012, 7:32:03 AM7/25/12
to skia-d...@googlegroups.com
Hi,
 
Plz try as below:
 

#include "SkBitmap.h"

#include "SkDevice.h"

#include "SkPaint.h"

#include "SkRect.h"

#include <cairo.h>  

int main()

 {

SkBitmap bitmap;

bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);

bitmap.allocPixels();

SkDevice device(bitmap);

SkCanvas canvas(&device);

SkPaint paint;

SkRect r;  

paint.setARGB(255, 255, 255, 255);

r.set(10, 10, 20, 20);

canvas.drawRect(r, paint);  

 {

 SkAutoLockPixels image_lock(bitmap);

 cairo_surface_t* surface = cairo_image_surface_create_for_data( (unsigned char*)bitmap.getPixels(), CAIRO_FORMAT_ARGB32, bitmap.width(), bitmap.height(), bitmap.rowBytes());

 cairo_surface_write_to_png(surface, "snapshot.png");

 cairo_surface_destroy(surface);

 }

  return 0;

}

 

 



--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/skia-discuss/-/ok1G3zPNeJkJ.
To post to this group, send email to skia-d...@googlegroups.com.
To unsubscribe from this group, send email to skia-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/skia-discuss?hl=en.

Mike Reed

unread,
Jul 25, 2012, 8:24:45 AM7/25/12
to skia-d...@googlegroups.com
SkOSWindow_win.cpp does this, either with SetDIBitsToDevice() or using opengl.

BITMAPINFO bmi;
memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = bitmap.width();
bmi.bmiHeader.biHeight = -bitmap.height(); // top-down image
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 0;

//
// Do the SetDIBitsToDevice.
//
// TODO(wjmaclean):
// Fix this call to handle SkBitmaps that have rowBytes != width,
// i.e. may have padding at the end of lines. The SkASSERT below
// may be ignored by builds, and the only obviously safe option
// seems to be to copy the bitmap to a temporary (contiguous)
// buffer before passing to SetDIBitsToDevice().
SkASSERT(bitmap.width() * bitmap.bytesPerPixel() == bitmap.rowBytes());
bitmap.lockPixels();
int iRet = SetDIBitsToDevice(hdc,
0, 0,
bitmap.width(), bitmap.height(),
0, 0,
0, bitmap.height(),
bitmap.getPixels(),
&bmi,
DIB_RGB_COLORS);
bitmap.unlockPixels();

Edvardas Ščerbavičius

unread,
Jul 26, 2012, 4:03:04 AM7/26/12
to skia-d...@googlegroups.com
Hi,

I am using code from Chromium(PlatformCanvasPaint) to build native Windows application.
Here you can find instructions how to build Skia .dll and sample app:
Sample application:

Edvardas

nrc

unread,
Jul 31, 2012, 5:08:13 AM7/31/12
to skia-d...@googlegroups.com
Thanks Mike, that is exactly what I was after!

nrc

unread,
Jul 31, 2012, 5:09:40 AM7/31/12
to skia-d...@googlegroups.com
Thanks Edvardas! I prefer to use the Skia library as a stand alone, without the Chromium stuff, but you instructions were useful to help get everything built :-)

Reply all
Reply to author
Forward
0 new messages