SkCanvas resize

581 views
Skip to first unread message

Anthony Catel

unread,
Jan 17, 2013, 12:40:09 PM1/17/13
to skia-d...@googlegroups.com
Hey,

What's an easy way to resize a SkCanvas?
I was using SkCanvas::setDevice with a new sized canvas but this method was deprecated.

For the moment I'm doing something like this : http://pastebin.com/vFSTedgy
The problem is that the new SkCanvas lost its "context" (i.e. current matrix, clip, saved stack, etc...).

Any advice?

Thanks ;-)

Tom Hudson

unread,
Jan 17, 2013, 1:04:50 PM1/17/13
to skia-d...@googlegroups.com
To back up a step, what is it that you're trying to do that you want to solve by resizing the canvas?

My first thought was to look at what SampleApp does when the window gets resized, but it's not obvious how the canvas changes (if at all) in that case; there are several layers of indirection through the Views hierarchy and virtual function overrides.



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

Anthony Catel

unread,
Jan 17, 2013, 1:34:41 PM1/17/13
to skia-d...@googlegroups.com
My application is using skia (backed by a GL device) to draw its UI.
Every element of my UI is a SkCanvas (internally a FBO handled by skia).
I have a case where I have something like a "UIWindow" which is resizable by the user. When it's resized I just have to resize the SkCanvas (and thus avoiding to redraw everything behind). I know it's an heavy process (create a new FBO, copy the old one, etc...) but it's still faster than having to redraw everything behind the UIWindow.

Do you see any better solution?

Thanks

Mike Reed

unread,
Jan 17, 2013, 1:52:23 PM1/17/13
to skia-d...@googlegroups.com
Resizing the backing pixels (cpu or gpu) is fine, though up to you. From Skia's perspective, a new device size requires a new canvas(+device). SkCanvas is just a drawing statemachine on top of your pixels, so it should not be too expensive to create a brand new canvas that points at your (old or new) pixels.


To view this discussion on the web visit https://groups.google.com/d/msg/skia-discuss/-/wYCTqWpVUQAJ.

Brian Salomon

unread,
Jan 17, 2013, 1:59:23 PM1/17/13
to skia-d...@googlegroups.com
I think the problem Anthony is running up against is copying the state from the old canvas to the new canvas. 

Anthony Catel

unread,
Jan 17, 2013, 2:25:53 PM1/17/13
to skia-d...@googlegroups.com
Mike, That's what I already do, and it works just fine.
Brian is right, what I'm looking for is a replacement for SkCanvas::setDevice(). That is, copy the old SkCanvas state.

Mike Reed

unread,
Jan 17, 2013, 2:48:43 PM1/17/13
to skia-d...@googlegroups.com
Gotcha.

No perfect way to replicate canvas state today.

new.clipRegion(old.getTotalClip())
new.setMatrix(old.getTotalMatrix())

These might get you close, but they don't 
- handle aa clips
- preserve save/restore information
- don't play friendly w/ GPU backend on non-rectangular clips



To view this discussion on the web visit https://groups.google.com/d/msg/skia-discuss/-/lEmB5ynyP80J.

Anthony Catel

unread,
Jan 17, 2013, 3:41:01 PM1/17/13
to skia-d...@googlegroups.com
Ok thanks, that's what I thought. Will try to work on a SkCanvas replication solution then. 

Btw, what was the reason for having marked SkCanvas::setDevice as deprecated?

A.

Mike Reed

unread,
Jan 17, 2013, 4:17:46 PM1/17/13
to skia-d...@googlegroups.com
Pretty much for this reason: changing the device (subclass and/or dimensions) can be hard/impossible for the canvas to update its state perfectly. We are moving towards making SkDevice itself an implementation-only class hierarchy, and not visible to the client. Look at SkSurface.h and SkImage.h to see a glimpse of the future!

Janez Zemva

unread,
Jan 17, 2013, 4:19:24 PM1/17/13
to skia-d...@googlegroups.com
Will writing a custom SkDevice still be possible?

2013/1/17 Mike Reed <re...@google.com>:

Mike Reed

unread,
Jan 17, 2013, 4:24:26 PM1/17/13
to skia-d...@googlegroups.com
... probably. Certainly the SkCanvas constructor that takes a device will last a long time. Part of the value of hiding SkDevice is to make it easier for us to modify its interface for performance reasons, as we continue to work on raster/gpu/pdf/picture/etc. backends.

a.c...@weelya.com

unread,
Jan 17, 2013, 4:36:15 PM1/17/13
to skia-d...@googlegroups.com
It makes sense.
Thanks for the insight.
>> >>>>>>>> http://pastebin.com/vFSTedgy [1]
>> >>>>>>>> The problem is that the new SkCanvas lost its "context"
>> (i.e.
>> >>>>>>>> current matrix, clip, saved stack, etc...).
>> >>>>>>>>
>> >>>>>>>> Any advice?
>> >>>>>>>>
>> >>>>>>>> Thanks ;-)
>> >>>>>>>>
>> >>>>>>>> --
>> >>>>>>>> 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/-/hsQ_gWfbU90J
>> [2].
>> >>>>>>>> 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 [3].
>> >>>>>>>
>> >>>>>>>
>> >>>>>> --
>> >>>>>> 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/-/wYCTqWpVUQAJ
>> [4].
>> >>>>>>
>> >>>>>> 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 [3].
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> You received this message because you are subscribed to the
>> Google
>> >>>>> Groups "skia-discuss" group.
>> >>>>> 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 [3].
>> >>>>
>> >>>>
>> >>> --
>> >>> 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/-/lEmB5ynyP80J [5].
>> >>>
>> >>> 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 [3].
>> >>
>> >>
>> >> --
>> >> You received this message because you are subscribed to the
>> Google Groups
>> >> "skia-discuss" group.
>> >> 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 [3].
>> >>
>> >> --
>> >> You received this message because you are subscribed to the
>> Google Groups
>> >> "skia-discuss" group.
>> >> 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 [3].
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "skia-discuss" group.
>> > 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 [3].
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "skia-discuss" group.
>> 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 [3].
>
> --
> You received this message because you are subscribed to the Google
> Groups "skia-discuss" group.
> 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.
>
>
> Links:
> ------
> [1] http://pastebin.com/vFSTedgy
> [2] https://groups.google.com/d/msg/skia-discuss/-/hsQ_gWfbU90J
> [3] http://groups.google.com/group/skia-discuss?hl=en
> [4] https://groups.google.com/d/msg/skia-discuss/-/wYCTqWpVUQAJ
> [5] https://groups.google.com/d/msg/skia-discuss/-/lEmB5ynyP80J

Reply all
Reply to author
Forward
0 new messages