Bug 227614

Summary: [CG] REGRESSION(r278863): The destination rectangle is truncated when the sub-image is used
Product: WebKit Reporter: Said Abou-Hallawa <sabouhallawa>
Component: ImagesAssignee: Said Abou-Hallawa <sabouhallawa>
Status: RESOLVED FIXED    
Severity: Normal CC: simon.fraser, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=226916
https://bugs.webkit.org/show_bug.cgi?id=225377
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Said Abou-Hallawa 2021-07-02 02:39:14 PDT
This was overlooked when GraphicsContextCG::drawNativeImage() was re-factored in r278863.
Comment 1 Said Abou-Hallawa 2021-07-02 02:40:38 PDT
<rdar://79840643>
Comment 2 Said Abou-Hallawa 2021-07-02 02:41:06 PDT
Created attachment 432773 [details]
Patch
Comment 3 Said Abou-Hallawa 2021-07-02 15:06:37 PDT
Created attachment 432827 [details]
Patch
Comment 4 Simon Fraser (smfr) 2021-07-02 19:09:01 PDT
Comment on attachment 432827 [details]
Patch

If we are drawing the whole image why do we hit the subimage codepath?
Comment 5 Said Abou-Hallawa 2021-07-02 20:02:43 PDT
Consider the case of drawing the whole ImageBuffer through ImageBuffer::draw(). Assume this ImageBuffer has the following parameters:
    logicalSize = { 392, 44 }
    resolutionScale = 1.91326535

ImageBufferBackend::calculateBackendSize() gets the enclosing rectangle for the backend size:
    backendSize = ceil(logicalSize * resolutionScale) = ceil({ 392 * 1.91326535, 44 * 1.91326535 }) = ceil({ 750, 84.1836754 }) = { 750, 85 }

The caller will pass the following arguments to ImageBuffer::draw():
    destRect = { 0,  0, 392, 44 }
    srcRect = { 0, 0, 392, 44 }

But ImageBufferCGBackend::draw() will pass the following arguments to GraphicsContextCG::drawNativeImage()
    imageSize = { 750, 85 } // = backendSize
    destRect = { 0,  0, 392, 44 }
    srcRect = { 0, 0, 750, 84.1836754 } // = logicalSize * resolutionScale

The condition to use the subimage codepath is the following:

    if (normalizedSrcRect != imageRect) // normalizedSrcRect is equal to srcRect in this case.

And this condition is true in this case because { 0, 0, 750, 84.1836754 } != { 0, 0, 750, 85 }

So yes in this case, we should not hit the subimage codepath. But I was trying to fix the regression and to put the calculation code back as it was before r278863.
Comment 6 Simon Fraser (smfr) 2021-07-06 09:36:23 PDT
Yes, my point was let's fix the rounding issues so we don't hit the subimage code path  for every back buffer -> front buffer copy which will never benefit from the cache.
Comment 7 Said Abou-Hallawa 2021-07-06 15:01:12 PDT
Created attachment 432978 [details]
Patch
Comment 8 Said Abou-Hallawa 2021-07-06 15:10:27 PDT
I fixed the issue of drawing the back ImageBuffer to the front ImageBuffer in RemoteLayerBackingStore::display(). Drawing the whole ImageBuffer should not go through the sub-image code path. But I had to adjust the calculation of the imageSize to match the logicalSize and the destRect to match the backendSize correctly.
Comment 9 Said Abou-Hallawa 2021-07-06 15:13:55 PDT
I think this bug is related to bug 225377
Comment 10 Said Abou-Hallawa 2021-07-07 14:14:41 PDT
Created attachment 433074 [details]
Patch
Comment 11 Said Abou-Hallawa 2021-07-13 00:37:45 PDT
Created attachment 433394 [details]
Patch
Comment 12 Simon Fraser (smfr) 2021-07-13 11:21:15 PDT
Comment on attachment 433394 [details]
Patch

Since this restores the behavior to shipping, r=me. However, we need to figure out how to avoid the sub image code path here (bug 227912).
Comment 13 EWS 2021-07-13 12:38:41 PDT
Committed r279885 (239637@main): <https://commits.webkit.org/239637@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 433394 [details].