Closed Bug 492724 Opened 15 years ago Closed 15 years ago

Pull out canvas utility functions into CanvasUtils

Categories

(Core :: Graphics: Canvas2D, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: vlad, Assigned: vlad)

References

Details

Attachments

(1 file, 2 obsolete files)

Attached patch move some functionality into CanvasUtils.h (obsolete) (deleted) — Splinter Review
There are a few canvas functions that really ought to be shared with any other contexts. This introduces CanvasUtils for those common functions. Though from looking at this, ThebesSurfaceFromElement isn't really canvas specific; it could be used elsewhere. roc, what do you think about putting that on nsLayoutUtils?
Attachment #377120 - Flags: review?(roc)
That makes sense. Make sure it's 2-space-indent there though. It has a lot of code in common with nsBaseDragService::DrawDragForImage, although it's probably hard to share. Also I think instead of taking 4 out parameters it would make more sense for ThebesSurfaceFromElement to return a struct or at least take a struct as a single out parameter.
Also if you're going to call it CanvasUtils instead of nsCanvasUtils, put it in the mozilla namespace.
Attached patch updated (obsolete) (deleted) — Splinter Review
moved some stuff into CanvasUtils, and some stuff into nsLayoutUtils. Used struct, etc.
Assignee: nobody → vladimir
Attachment #377120 - Attachment is obsolete: true
Attachment #384924 - Flags: review?(roc)
Attachment #377120 - Flags: review?(roc)
+ // Check that the rectangle [x,y,w,h] is a subrectangle of [0,0,realWidth,realHeight] + + static PRBool CheckSaneSubrectSize(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h, + PRInt32 realWidth, PRInt32 realHeight) Why not just nsIntRect(0, 0, realWidth, realHeight).Contains(nsIntRect(x, y, w, h))? + * Obtain a gfxASurface from the given DOM element, if possible. + * This obtains the most natural surface from the element; that + * is, the one that can be obtained with the fewest conversions. It's probably worth saying exactly what it does for each element type. + struct SurfaceFromElementResult { + nsRefPtr<gfxASurface> surface; + gfxIntSize size; + nsCOMPtr<nsIPrincipal> principal; + PRBool isWriteOnly; + }; mBlahBlah convention + surf = new gfxImageSurface(gfxIntSize(w, h), gfxASurface::ImageFormatARGB32); + else + surf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(w, h), gfxASurface::ImageFormatARGB32); We generally have {} around single statements in layout, apart from break/return/continue. See what I mean about suckiness of per-module style. + static nsresult SurfaceFromElement(nsIDOMElement *aElement, + PRUint32 aSurfaceFlags, + SurfaceFromElementResult *aResult); Why not just return SurfaceFromElementResult directly, and set mSurface to null on error?
Attached patch updated (deleted) — Splinter Review
Updated with comments addressed.
Attachment #384924 - Attachment is obsolete: true
Attachment #385038 - Flags: review?(roc)
Attachment #384924 - Flags: review?(roc)
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Depends on: 500988
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: