Closed Bug 1073363 Opened 7 years ago Closed 7 years ago

Add a GeneralPattern class to Moz2D to solve the problem of writing general pattern creation functions

Categories

(Core :: Graphics, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla35

People

(Reporter: jwatt, Assigned: jwatt)

Details

Attachments

(3 files, 3 obsolete files)

No description provided.
Attached patch patch (obsolete) — Splinter Review
Attachment #8495694 - Flags: review?(bas)
An alternative to the Init* functions would be to replace them with a function that returns an address for use with the placement operator:

  Pattern* ctorAddr(PatternType aType) {
    MOZ_ASSERT(!mPattern);
    switch (aType) {
    case PatternType::COLOR:
      return mPattern = mColorPattern.addr();
    case PatternType::LINEAR_GRADIENT:
      return mPattern = mLinearGradientPattern.addr();
    case PatternType::RADIAL_GRADIENT:
      return mPattern = mRadialGradientPattern.addr();
    case PatternType::SURFACE:
      return mPattern = mSurfacePattern.addr();
    default:
      MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected pattern type");
  }

Assuming that in the general pattern creation function the GeneralPattern is aPattern, you'd then initialize a pattern like:

  ColorPattern pattern =
     new (aPattern->ctorAddr(PatternType::COLOR) ColorPattern(color);

instead of:

  ColorPattern pattern = aPattern->InitColorPattern(color);

Other than making calling code a bit more verbose, I'm not totally loving that this would mean assigning to mPattern without actually knowing that the ctorAddr caller is calling the [appropriate] ctor.
Attachment #8495694 - Attachment is obsolete: true
Attachment #8495694 - Flags: review?(bas)
Attachment #8495762 - Flags: review?(bas)
Attachment #8495764 - Flags: review?(bas)
Feel free to r- this part, or just r+ the canvas part (not sure the gfxPattern changes are worth it, given that it's going to go away in the short to medium term).
Attachment #8495765 - Flags: review?(bas)
Put in its own file, as requested on IRC.
Attachment #8495764 - Attachment is obsolete: true
Attachment #8495764 - Flags: review?(bas)
Attachment #8496448 - Flags: review?(bas)
Attachment #8495765 - Attachment is obsolete: true
Attachment #8495765 - Flags: review?(bas)
Attachment #8496449 - Flags: review?(bas)
Attachment #8495762 - Flags: review?(bas) → review+
Attachment #8496448 - Flags: review?(bas) → review+
Attachment #8496449 - Flags: review?(bas) → review+
You need to log in before you can comment on or make changes to this bug.