Closed Bug 887927 Opened 11 years ago Closed 11 years ago

SourceSurfaceSkia needs to copy the bitmap when DT is destroyed

Categories

(Core :: Graphics: Canvas2D, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla25

People

(Reporter: snorp, Assigned: snorp)

References

Details

Attachments

(1 file, 3 obsolete files)

If we have an outstanding SourceSurfaceSkia referencing a DT that gets destroyed, we will fail to do the readback later on if GetData() is called. SkBitmap is not really independent like it is with software. It is not surprising that it would need the device to be alive in order to do the readback, and I guess it does not hold a strong reference.
Comment on attachment 768479 [details] [diff] [review]
Make a copy of the SkBitmap when DT is destroyed

Review of attachment 768479 [details] [diff] [review]:
-----------------------------------------------------------------

::: gfx/2d/SourceSurfaceSkia.cpp
@@ +110,5 @@
>  
>  void
>  SourceSurfaceSkia::DrawTargetDestroyed()
>  {
> +  DrawTargetWillChange();

Can we do this only for SkiaGL?

It works fine for software!
Or even better, can't we just take ownership of the device in the SourceSurfaceSkia?

It's a fairly common pattern to create a draw target, draw into it, snapshot and let the DT die. Having to make a copy when that happens could be expensive.
Alright, so I made SourceSurfaceSkia hold a reference to the SkDevice. This made it possible for the SkBitmap to attempt to lock the pixels (where before I assume it just bailed immediately). This doesn't work, though, because the SkDevice relies on the GLContext which is only held in DrawTargetSkia (via a GenericRefPtr member). So once the DrawTargetSkia is gone, the SkDevice (and GrContext, etc) are all effectively busted. I think we'll have to live with a copy when the DT goes away, at least for SkiaGL.
I've also tried having SourceSurfaceSkia hold a reference to the GLContext. This would've worked before, but the code has changed such that GLContextSkia now uses the DT to retrieve the GLContext. So we absolutely must have the originating DT be alive for SourceSurfaceSkia to complete a readback (with current code). We can hold a reference to it in SourceSurfaceSkia, but I think the lifetime of the DT now becomes a little more ambiguous than we would like.

I think I would like to just copy the SkBitmap when the DT is destroyed but only when using GL. Unless you are going to just throw the SourceSurface away, you're going to end up doing a readback at some point anyway. For software we can keep it as it is now.
Attachment #768479 - Attachment is obsolete: true
Attachment #768479 - Flags: review?(matt.woodrow)
Attachment #768706 - Flags: review?(matt.woodrow) → review?(gwright)
Attachment #768706 - Flags: review?(gwright) → review+
Attachment #768706 - Attachment is obsolete: true
Matt and I talked some more and agreed that just refing the DT in the SourceSurfaceSkia is better since the performance remains the same regardless of whether or not the callerd destroys the DT (or rather, tries to, since it will remain alive while any outstanding SourceSurfaceSkias are alive).
Attachment #769100 - Attachment is obsolete: true
https://hg.mozilla.org/mozilla-central/rev/295946bd016a
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: