Regarding deprecated APIs and their alternatives

104 views
Skip to first unread message

Vivek Kumar

unread,
Apr 21, 2015, 9:53:24 AM4/21/15
to skia-d...@googlegroups.com
I just updated the version of skia that I was using, but it seems a lot of APIs have changed.
For creating a Canvas I used to proceed like this : 
      SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 100);
bitmap.setPixels(address);
SkCanvas canvas(bitmap);
canvas.drawText(text, length, x, y, paint);

But now it seems setConfig has been deprecated and replaced with SkImageInfo, but I couldn't find an alternative for kARGB_8888_Config.

Also SkCanvas::getClipBounds doesn't take EdgeType as an argument anymore and I couldn't find any alternative for it.

What other APIs are available for these?

Documentation for skia has also been not updated at https://code.google.com/p/skia/wiki/SkCanvas.

Thanks
Vivek 


Hal Canary

unread,
Apr 21, 2015, 10:23:30 AM4/21/15
to skia-d...@googlegroups.com
Regarding the SkBitmap API, kARGB_8888_Config has become kN32_SkColorType.  Try this:

    SkImageInfo info = SkImageInfo::MakeN32(200, 100);
    SkAutoTUnref<SkSurface> surface(
            SkSurface::NewRasterDirect(
                    info, address, info.minRowBytes()));
    SkCanvas* canvas= surface.getCanvas();
    canvas->drawText(text, length, x, y, paint);

or this:

    SkImageInfo info = SkImageInfo::MakeN32(200, 100);
    SkBitmap bitmap;
    bitmap.installPixels(info, address, info.minRowBytes());
    SkCanvas canvas(bitmap);
    canvas.drawText(text, length, x, y, paint);

Vivek Kumar

unread,
Apr 23, 2015, 2:28:30 AM4/23/15
to skia-d...@googlegroups.com
Actually I was also doing the same for creating the canvas, but it turned out the issue was that I'm copying bitmap data from another bitmap (not SkBitmap) and the value of rowBytes that I'm passing to bitmap.installPixels is less than info.minRowBytes() (calc as width*bytes/pixel) causing the bitmap to be reset. 

Isn't it possible for a bitmap to have rowBytes < (bitmap.width * bytes/pixel) ? This used to work with earlier versions of skia.

Cary Clark

unread,
Apr 23, 2015, 7:46:34 AM4/23/15
to skia-d...@googlegroups.com
No, it is not possible for rowBytes to be less than the width. Could you illustrate how you expect this to work?

For instance, suppose that your bitmap has 1 byte / pixel and each byte is represented by a letter. The bitmap stream looks like:

ABCDEFGHIJKLM

If the row bytes is 3 and the width and height is 4, then what do you expect to draw? This?

ABCD
DEFG
GHIJ
JKLM

Thanks
Cary


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages