W3C home > Mailing lists > Public > whatwg@whatwg.org > December 2012

Re: [whatwg] I believe source rectangles for HTML5 Canvas drawImage are specified incorrectly

From: Justin Novosad <junov@chromium.org>
Date: Tue, 18 Dec 2012 11:30:58 -0500
Message-ID: <CABpaAqTt9NMriO1Hxa9dmr+Yn7iZQVOhyXj2-yoCsAekE8tu8g@mail.gmail.com>
To: Kevin Gadd <kevin.gadd@gmail.com>
Cc: Vladimir Vukicevic <vladimir@pobox.com>, Rik Cabanier <cabanier@gmail.com>, whatwg@lists.whatwg.org, Jeff Muizelaar <jmuizelaar@mozilla.com>, Ian Hickson <ian@hixie.ch>, robert@ocallahan.org
On Tue, Dec 18, 2012 at 11:03 AM, Kevin Gadd <kevin.gadd@gmail.com> wrote:

> How do you wait synchronously for a callback from inside
> requestAnimationFrame?


If you are inside a rAF callback, you exit the callback, and resume drawing
in the createBitmapImage callback.


> I'm not aware of a way to do this in the spec.
> Furthermore, wouldn't that mean returning once to the event loop for
> each individual drawImage call you wish to make using a source
> rectangle - so for a single scene containing lots of dynamic source
> rectangles you could end up having to wait for dozens of callbacks.
>

You make all the createBitmapImage calls you need, then exit (return to
event loop). In the createBitmapImage callback you track completion of all
the createBitmapImage calls. This can be done using a common callback
function and a counter. If not all bitmaps are ready, the callback exits
immediately. Once you know all the bitmaps are ready, draw.  This way, all
the createBitmapImage calls run concurrently. This can a big performance
win when the source images are remote and network latency is a factor.


> Each time you wait for that callback, won't any pending drawing
> operations to your canvas get flushed, resulting in the scene slowly
> rendering onscreen?
>

Another great reason to batch the calls, as described above.


>
> -kg
>
> On Tue, Dec 18, 2012 at 7:39 AM, Justin Novosad <junov@chromium.org>
> wrote:
> > On Tue, Dec 18, 2012 at 10:17 AM, Kevin Gadd <kevin.gadd@gmail.com>
> wrote:
> >>
> >> Sorry, upon reading over the ImageBitmap part of the spec again I'm
> >> confused: Why is constructing an ImageBitmap asynchronous? I thought
> >> any decoding isn't supposed to happen until drawImage, so I don't
> >> really understand why this operation involves a callback and a delay.
> >
> >
> > The image may have to be downloaded, which is a good reason for being
> async.
> >
> >>
> >> Making ImageBitmap creation async means that you *cannot* use this as
> >> a replacement for drawImage source rectangles unless you know all
> >> possible source rectangles in advance. This is not possible for many,
> >> many use cases (scrolling through a bitmap would be one trivial
> >> example).
> >
> >
> > I am not sure I understand the problem. If you need synchronous behavior,
> > you can just make the app wait for the callback to be called.
> >
> >     -Justin
> >
> >>
> >> On Tue, Dec 18, 2012 at 7:12 AM, Kevin Gadd <kevin.gadd@gmail.com>
> wrote:
> >> > Is it possible to expose the width/height of an ImageBitmap, or even
> >> > expose all the rectangle coordinates? Exposing width/height would be
> >> > nice for parity with Image and Canvas when writing functions that
> >> > accept any drawable image source.
> >> >
> >> > Thanks for the prompt action here, this looks like a straightforward
> >> > solution.
> >> >
> >> > -kg
> >> >
> >> > On Tue, Dec 18, 2012 at 7:03 AM, Justin Novosad <junov@chromium.org>
> >> > wrote:
> >> >> Thanks Ian.
> >> >> http://html5.org/tools/web-apps-tracker?from=7588&to=7589
> >> >>
> >> >> On Tue, Dec 18, 2012 at 1:04 AM, Robert O'Callahan
> >> >> <robert@ocallahan.org>
> >> >> wrote:
> >> >>>
> >> >>> On Tue, Dec 18, 2012 at 6:57 PM, Rik Cabanier <cabanier@gmail.com>
> >> >>> wrote:
> >> >>>>
> >> >>>> Does it matter that this solution is in the image world and not 2d
> >> >>>> canvas? It seems that this will have a bigger impact on the
> browser's
> >> >>>> codebase since it spans images and canvas.
> >> >>>
> >> >>>
> >> >>> I think that's a good thing --- it's more generally useful.
> >> >>>
> >> >>> Note that Ian has adopted this approach (via an ImageBitmap
> >> >>> constructor).
> >> >>>
> >> >>>
> >> >>> Rob
> >> >>> --
> >> >>> Jesus called them together and said, “You know that the rulers of
> the
> >> >>> Gentiles lord it over them, and their high officials exercise
> >> >>> authority over
> >> >>> them. Not so with you. Instead, whoever wants to become great among
> >> >>> you must
> >> >>> be your servant, and whoever wants to be first must be your slave —
> >> >>> just as
> >> >>> the Son of Man did not come to be served, but to serve, and to give
> >> >>> his life
> >> >>> as a ransom for many.” [Matthew 20:25-28]
> >> >>>
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > -kg
> >>
> >>
> >>
> >> --
> >> -kg
> >
> >
>
>
>
> --
> -kg
>
Received on Tuesday, 18 December 2012 16:31:25 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:50 UTC