SkSurface::MakeRasterN32Premul always returns 0 pointer

296 views
Skip to first unread message

扈马克

unread,
Jun 16, 2017, 9:02:41 AM6/16/17
to skia-discuss
Hi all,

I'm a beginner with Skia. Writing my first program, I have the following code to create a SkSurface:

sk_sp<SkSurface> rasterSurface = SkSurface::MakeRasterN32Premul( imageWidth, imageHeight );
SkCanvas* rasterCanvas = rasterSurface->getCanvas();
.....

Unfortunately, rasterSurface always is a 0 pointer. Doing a bit of debugging, I find that in

SkSurfaceValidateRasterInfo(const SkImageInfo& info, size_t rowBytes), SkSurface_Raster.cpp:38, there is a switch depending on SkImageInfo.colorType(). It is  kRGBA_8888_SkColorType and the program goes to the default-switch, returning false.

Is something in my code wrong or could it be that there is something wrong with my compilation (since kN32_SkColorType is assigned to a different value with a preprocessor if in SkImageInfo.h:82)?

If it is the compilation, I'm on kubuntu 17.04 and I'm using the following commands for checkout and compilation:

git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git'
export PATH="${PWD}/depot_tools:${PATH}"
git clone https://skia.googlesource.com/skia.git
cd skia
python tools/git-sync-deps
bin/gn gen out/Shared --args='is_official_build=true is_component_build=true extra_cflags_cc=["-Wno-error"]'
ninja -C out/Shared

Thank you for any help/hints,
Marco

Mike Reed

unread,
Jun 16, 2017, 9:13:04 AM6/16/17
to skia-d...@googlegroups.com
kN32 can be either RGBA or BGRA. If your system is defining it to be BGRA, then surface creation will fail.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

扈马克

unread,
Jun 16, 2017, 10:15:22 AM6/16/17
to skia-discuss
I see. Is this related to big endian vs. little endian or how does the system define it?
If it is endian, I'm using a normal intel 64bit pc (little endian).

Thanks,
Marco


Am Freitag, 16. Juni 2017 15:13:04 UTC+2 schrieb Mike Reed:
kN32 can be either RGBA or BGRA. If your system is defining it to be BGRA, then surface creation will fail.
On Fri, Jun 16, 2017 at 9:02 AM, 扈马克 <geoh...@gmail.com> wrote:
Hi all,

I'm a beginner with Skia. Writing my first program, I have the following code to create a SkSurface:

sk_sp<SkSurface> rasterSurface = SkSurface::MakeRasterN32Premul( imageWidth, imageHeight );
SkCanvas* rasterCanvas = rasterSurface->getCanvas();
.....

Unfortunately, rasterSurface always is a 0 pointer. Doing a bit of debugging, I find that in

SkSurfaceValidateRasterInfo(const SkImageInfo& info, size_t rowBytes), SkSurface_Raster.cpp:38, there is a switch depending on SkImageInfo.colorType(). It is  kRGBA_8888_SkColorType and the program goes to the default-switch, returning false.

Is something in my code wrong or could it be that there is something wrong with my compilation (since kN32_SkColorType is assigned to a different value with a preprocessor if in SkImageInfo.h:82)?

If it is the compilation, I'm on kubuntu 17.04 and I'm using the following commands for checkout and compilation:

git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git'
export PATH="${PWD}/depot_tools:${PATH}"
git clone https://skia.googlesource.com/skia.git
cd skia
python tools/git-sync-deps
bin/gn gen out/Shared --args='is_official_build=true is_component_build=true extra_cflags_cc=["-Wno-error"]'
ninja -C out/Shared

Thank you for any help/hints,
Marco

--
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.

扈马克

unread,
Jun 16, 2017, 10:59:24 AM6/16/17
to skia-discuss

I now edited SkImageInfo such that kN32_SkColorType = kRGBA_8888_SkColorType.
Now it works perfectly! So it seems that the endianness was somehow not correctly detected on my system (and also on my intel notbook with kubuntu 16.10).

Marco

Brian Osman

unread,
Jun 16, 2017, 11:07:52 AM6/16/17
to skia-d...@googlegroups.com
It sounds like something else may be wrong, actually. kN32 can be either RGBA or BGRA, but it needs to be consistently defined for all .cpp files. I see that you're building Skia as a static library (and then trying to use the library like you posted). Can you try adding #include <SkTypes.h> before you include any other Skia headers (in your own code). I suspect that kN32 is defaulting to something different in your code (from what it's set to in Skia).

To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

扈马克

unread,
Jun 26, 2017, 7:51:49 AM6/26/17
to skia-d...@googlegroups.com
I'm building skia as a dynamic library. Unfortunately, including SkTypes before the other headers does not solve the problem

--
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/oEmbjYTeT0k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to skia-discuss+unsubscribe@googlegroups.com.

Hal Canary

unread,
Jun 26, 2017, 8:43:51 AM6/26/17
to skia-discuss
The simplest explanation is that you built Skia with different setting than you have in your headers when compiled your client code..

Try this:

    sk_sp<SkSurface> s;
    SkColorType ct;

    ct = kRGBA_8888_SkColorType;
    s = SkSurface::MakeRaster(SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType));
    if (s) { printf("kRGBA_8888_SkColorType works!\n"); }

    ct = kBGRA_8888_SkColorType;
    s = SkSurface::MakeRaster(SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType));
    if (s) { printf("kBGRA_8888_SkColorType works!\n"); }

扈马克

unread,
Jun 26, 2017, 10:20:20 AM6/26/17
to skia-d...@googlegroups.com
Ah, didn't know about the longer version of SkSurface::MakeRaster. kBGRA_8888_SkColorType works for me, so I'm going to use that instead of modifying SkImageInfo.
Thanks for the help,
Marco


--
Reply all
Reply to author
Forward
0 new messages