RESOLVED FIXED 79395
Add ImageBuffer support for having a hi-res backing store
https://bugs.webkit.org/show_bug.cgi?id=79395
Summary Add ImageBuffer support for having a hi-res backing store
Matthew Delaney
Reported 2012-02-23 13:45:53 PST
Many of the clients of ImageBuffer create oversized versions and then scale up their contexts to have a high-res version of the ImageBuffer. This logic is being duplicated in many locations and should just be moved down into ImageBuffer. This bug tracks building hi-res support directly into ImageBuffer so that the ImageBuffer internals can deal with the scale factor directly. One example of a client whose code would become much cleaner by adopting this would be <canvas>. I'll file a follow up bug to track <canvas> adopting this change in factor of mucking with the internals of the ImageBuffer directly, as it currently does.
Attachments
Patch (40.79 KB, patch)
2012-02-23 13:55 PST, Matthew Delaney
no flags
Patch (40.74 KB, patch)
2012-02-23 15:36 PST, Matthew Delaney
no flags
Patch (41.54 KB, patch)
2012-02-23 15:47 PST, Matthew Delaney
no flags
Patch (41.54 KB, patch)
2012-02-23 16:11 PST, Matthew Delaney
no flags
Patch (36.59 KB, patch)
2012-02-23 20:01 PST, Matthew Delaney
no flags
Patch (36.83 KB, patch)
2012-02-27 12:24 PST, Matthew Delaney
mitz: review+
Matthew Delaney
Comment 1 2012-02-23 13:55:13 PST
Matthew Delaney
Comment 2 2012-02-23 13:56:41 PST
(In reply to comment #1) > Created an attachment (id=128550) [details] > Patch Note: I still need to update the other platforms, though the bots are pretty broken right now anyhow.
Philippe Normand
Comment 3 2012-02-23 13:58:12 PST
Matthew Delaney
Comment 4 2012-02-23 13:59:18 PST
Comment on attachment 128550 [details] Patch That patch had some junk in it, reuploading in a min.
Early Warning System Bot
Comment 5 2012-02-23 14:23:47 PST
WebKit Review Bot
Comment 6 2012-02-23 14:39:55 PST
Comment on attachment 128550 [details] Patch Attachment 128550 [details] did not pass chromium-ews (chromium-xvfb): Output: http://queues.webkit.org/results/11600444
Matthew Delaney
Comment 7 2012-02-23 15:36:19 PST
Matthew Delaney
Comment 8 2012-02-23 15:37:11 PST
I reworked it to require less changes to other ports. So, this patch is EWS food.
WebKit Review Bot
Comment 9 2012-02-23 15:44:27 PST
Comment on attachment 128570 [details] Patch Attachment 128570 [details] did not pass chromium-ews (chromium-xvfb): Output: http://queues.webkit.org/results/11576463
Matthew Delaney
Comment 10 2012-02-23 15:47:42 PST
Matthew Delaney
Comment 11 2012-02-23 16:11:20 PST
Matthew Delaney
Comment 12 2012-02-23 16:11:59 PST
Had a mistype in the last patch.
mitz
Comment 13 2012-02-23 16:53:14 PST
Comment on attachment 128586 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=128586&action=review > Source/WebCore/ChangeLog:15 > + (WebCore::ImageBuffer::devicePixelRatio): Add a way to access if ratio. “if”? > Source/WebCore/ChangeLog:17 > + (WebCore::ImageBuffer::dataSize): Differentiate between the logical size and the underlying data's size. To me, “data size” strongly suggests “number of bytes”. How about “physicalSize” instead? > Source/WebCore/ChangeLog:20 > + and thus clearer use of logicalSize or deviceSize. Here you call it “deviceSize” but I suspect you mean the same thing as “dataSize”. > Source/WebCore/html/HTMLCanvasElement.cpp:527 > - scriptExecutionContext()->globalData()->heap.reportExtraMemoryCost(m_imageBuffer->dataSize()); > + size_t numBytes = 4 * m_imageBuffer->dataSize().width() * m_imageBuffer->dataSize().height(); > + scriptExecutionContext()->globalData()->heap.reportExtraMemoryCost(numBytes); Now I see that dataSize() currently does mean a size in bytes. I strongly suggest leaving it to mean that, and using a different name for the new function. > Source/WebCore/platform/graphics/ImageBuffer.h:84 > + dataSize.scale(devicePixelRatio); Does this need to be rounded up? > Source/WebCore/platform/graphics/ImageBuffer.h:91 > + buf->context()->scale(FloatSize(devicePixelRatio, devicePixelRatio)); > + buf->m_devicePixelRatio = devicePixelRatio; Is there a reason why you didn’t just add the device pixel ratio to the ImageBuffer constructor? > Source/WebCore/platform/graphics/ImageBuffer.h:105 > + const IntSize logicalSize() const > + { > + IntSize logicalSize = dataSize(); > + logicalSize.scale(1 / devicePixelRatio()); > + return logicalSize; > + } > + Because of rounding, this is not necessarily going to return the size you passed the ImageBuffer::create(). Isn’t this going to be inconvenient for clients? > Source/WebCore/platform/graphics/ImageBuffer.h:160 > + Why the newline?
Early Warning System Bot
Comment 14 2012-02-23 16:56:00 PST
Matthew Delaney
Comment 15 2012-02-23 17:25:52 PST
Comment on attachment 128586 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=128586&action=review >> Source/WebCore/ChangeLog:17 >> + (WebCore::ImageBuffer::dataSize): Differentiate between the logical size and the underlying data's size. > > To me, “data size” strongly suggests “number of bytes”. How about “physicalSize” instead? How about "deviceSize" instead? Then it'll match the already-existing notion of "deviceScaleFactor". >> Source/WebCore/ChangeLog:20 >> + and thus clearer use of logicalSize or deviceSize. > > Here you call it “deviceSize” but I suspect you mean the same thing as “dataSize”. Yep, typo when I was already thinking of this as an alternate name! :-) >> Source/WebCore/html/HTMLCanvasElement.cpp:527 >> + scriptExecutionContext()->globalData()->heap.reportExtraMemoryCost(numBytes); > > Now I see that dataSize() currently does mean a size in bytes. I strongly suggest leaving it to mean that, and using a different name for the new function. That old declaration of dataSize() returned the number of bytes and this was the only call site. The new version of the method returns the size w.r.t pixels, not bytes. So, I updated this to have a mult by 4 to calc the number of bytes for the purposes of this gc hook. >> Source/WebCore/platform/graphics/ImageBuffer.h:84 >> + dataSize.scale(devicePixelRatio); > > Does this need to be rounded up? Yea, good call. I'll fix this. >> Source/WebCore/platform/graphics/ImageBuffer.h:91 >> + buf->m_devicePixelRatio = devicePixelRatio; > > Is there a reason why you didn’t just add the device pixel ratio to the ImageBuffer constructor? Yea, I wanted to avoid having to modify all the platform impls ;-)
Simon Fraser (smfr)
Comment 16 2012-02-23 17:57:57 PST
Comment on attachment 128576 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=128576&action=review > Source/WebCore/platform/graphics/ImageBuffer.h:97 > + bool devicePixelRatio() const { return m_devicePixelRatio; } We use the term deviceScaleFactor() elsewhere. However, this is ImageBuffer's pixel ratio, not a device pixel ratio.
Matthew Delaney
Comment 17 2012-02-23 20:01:11 PST
Matthew Delaney
Comment 18 2012-02-23 20:06:40 PST
> We use the term deviceScaleFactor() elsewhere. However, this is ImageBuffer's pixel ratio, not a device pixel ratio. Yea, using deviceScaleFactor here was a dumb idea. I made a new patch that just cuts out using it altogether since it's misleading if the xScale and yScale differ by a little due to integer rounding. Also, I renamed the size of the ImageBuffer's internal backing store to be "internalSize".
Matthew Delaney
Comment 19 2012-02-27 12:24:08 PST
Matthew Delaney
Comment 20 2012-02-27 12:43:53 PST
Note You need to log in before you can comment on or make changes to this bug.