Status

()

--
enhancement
RESOLVED FIXED
9 years ago
9 years ago

People

(Reporter: cjones, Assigned: cjones)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

Comment hidden (empty)
Created attachment 449217 [details] [diff] [review]
Implement serialization of a grab-bag of gfx types
Assignee: nobody → jones.chris.g
Attachment #449217 - Flags: review?(joe)
Created attachment 449326 [details] [diff] [review]
Implement serialization of a grab-bag of gfx types   

Sorry, the previous patch had some lazy shortcuts that I forgot to fix.
Attachment #449217 - Attachment is obsolete: true
Attachment #449326 - Flags: review?(joe)
Attachment #449217 - Flags: review?(joe)
Comment on attachment 449326 [details] [diff] [review]
Implement serialization of a grab-bag of gfx types   


>@@ -245,16 +252,17 @@ struct ParamTraits<nsTArray<E> >
> 
>   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
>   {
>     PRUint32 length;
>     if (!ReadParam(aMsg, aIter, &length)) {
>       return false;
>     }
> 
>+    aResult->SetCapacity(length);
>     for (PRUint32 index = 0; index < length; index++) {
>       E* element = aResult->AppendElement();
>       if (!(element && ReadParam(aMsg, aIter, element))) {
>         return false;
>       }
>     }
> 
>     return true;

This hunk should probably be part of a separate bug, right?

>@@ -327,16 +335,108 @@ struct ParamTraits<gfxMatrix>
>   static void Log(const paramType& aParam, std::wstring* aLog)
>   {
>     aLog->append(StringPrintf(L"[[%g %g] [%g %g] [%g %g]]", aParam.xx, aParam.xy, aParam.yx, aParam.yy,
> 	  						    aParam.x0, aParam.y0));
>   }
> };
> 
> template<>
>+struct ParamTraits<gfx3DMatrix>
>+{
>+  typedef gfx3DMatrix paramType;
>+
>+  static void Write(Message* msg, const paramType& param)
>+  {
>+#define Wr(_f)  WriteParam(msg, param. _f)
>+    Wr(_11); Wr(_12); Wr(_13); Wr(_14);
>+    Wr(_21); Wr(_22); Wr(_23); Wr(_24);
>+    Wr(_31); Wr(_32); Wr(_33); Wr(_34);
>+    Wr(_41); Wr(_42); Wr(_43); Wr(_44);
>+#undef Wr
>+  }
>+
>+  static bool Read(const Message* msg, void** iter, paramType* result)
>+  {
>+#define Rd(_f)  ReadParam(msg, iter, &result-> _f)
>+    return (Rd(_11) && Rd(_12) && Rd(_13) && Rd(_14) &&
>+            Rd(_21) && Rd(_22) && Rd(_23) && Rd(_24) &&
>+            Rd(_31) && Rd(_32) && Rd(_33) && Rd(_34) &&
>+            Rd(_41) && Rd(_42) && Rd(_43) && Rd(_44));
>+#undef Rd
>+  }
>+};
>+
>+ template<>
>+struct ParamTraits<mozilla::GraphicsFilterType>
>+{
>+  typedef mozilla::GraphicsFilterType paramType;
>+
>+  static void Write(Message* msg, const paramType& param)
>+  {
>+    switch (param) {
>+    case gfxPattern::FILTER_FAST:
>+    case gfxPattern::FILTER_GOOD:
>+    case gfxPattern::FILTER_BEST:
>+    case gfxPattern::FILTER_NEAREST:
>+    case gfxPattern::FILTER_BILINEAR:
>+    case gfxPattern::FILTER_GAUSSIAN:
>+      WriteParam(msg, int32(param));
>+      return;
>+
>+    default:
>+      NS_RUNTIMEABORT("not reached");
>+      return;
>+    }
>+  }
>+
>+  static bool Read(const Message* msg, void** iter, paramType* result)
>+  {
>+    int32 filter;
>+    if (!ReadParam(msg, iter, &filter))
>+      return false;
>+
>+    switch (filter) {
>+    case gfxPattern::FILTER_FAST:
>+    case gfxPattern::FILTER_GOOD:
>+    case gfxPattern::FILTER_BEST:
>+    case gfxPattern::FILTER_NEAREST:
>+    case gfxPattern::FILTER_BILINEAR:
>+    case gfxPattern::FILTER_GAUSSIAN:
>+      *result = paramType(filter);
>+      return true;
>+
>+    default:
>+      return false;
>+    }
>+  }
>+};
>+template<>
>+struct ParamTraits<gfxRGBA>
>+{
>+  typedef gfxRGBA paramType;
>+
>+  static void Write(Message* msg, const paramType& param)
>+  {
>+    WriteParam(msg, param.r);
>+    WriteParam(msg, param.g);
>+    WriteParam(msg, param.b);
>+    WriteParam(msg, param.a);
>+  }
>+
>+  static bool Read(const Message* msg, void** iter, paramType* result)
>+  {
>+    return (ReadParam(msg, iter, &result->r) &&
>+            ReadParam(msg, iter, &result->g) &&
>+            ReadParam(msg, iter, &result->b) &&
>+            ReadParam(msg, iter, &result->a));
>+  }
>+};
>+
>+template<>
> struct ParamTraits<mozilla::void_t>
> {
>   typedef mozilla::void_t paramType;
>   static void Write(Message* aMsg, const paramType& aParam) { }
>   static bool
>   Read(const Message* aMsg, void** aIter, paramType* aResult)
>   {
>     *aResult = paramType();
>@@ -352,11 +452,96 @@ struct ParamTraits<mozilla::null_t>
>   static bool
>   Read(const Message* aMsg, void** aIter, paramType* aResult)
>   {
>     *aResult = paramType();
>     return true;
>   }
> };
> 
>+template<>
>+struct ParamTraits<nsIntPoint>
>+{
>+  typedef nsIntPoint paramType;
>+  
>+  static void Write(Message* msg, const paramType& param)
>+  {
>+    WriteParam(msg, param.x);
>+    WriteParam(msg, param.y);
>+  }
>+
>+  static bool Read(const Message* msg, void** iter, paramType* result)
>+  {
>+    return (ReadParam(msg, iter, &result->x) &&
>+            ReadParam(msg, iter, &result->y));
>+  }
>+};
>+
>+template<>
>+struct ParamTraits<nsIntRect>
>+{
>+  typedef nsIntRect paramType;
>+  
>+  static void Write(Message* msg, const paramType& param)
>+  {
>+    WriteParam(msg, param.x);
>+    WriteParam(msg, param.y);
>+    WriteParam(msg, param.width);
>+    WriteParam(msg, param.height);
>+  }
>+
>+  static bool Read(const Message* msg, void** iter, paramType* result)
>+  {
>+    return (ReadParam(msg, iter, &result->x) &&
>+            ReadParam(msg, iter, &result->y) &&
>+            ReadParam(msg, iter, &result->width) &&
>+            ReadParam(msg, iter, &result->height));
>+  }
>+};
>+
>+template<>
>+struct ParamTraits<nsIntRegion>
>+{
>+  typedef nsIntRegion paramType;
>+
>+  static void Write(Message* msg, const paramType& param)
>+  {
>+    nsIntRegionRectIterator it(param);
>+    while (const nsIntRect* r = it.Next())
>+      WriteParam(msg, *r);
>+    // empty rects are sentinel values because nsRegions will never
>+    // contain them
>+    WriteParam(msg, nsIntRect());
>+  }
>+
>+  static bool Read(const Message* msg, void** iter, paramType* result)
>+  {
>+    nsIntRect rect;
>+    while (ReadParam(msg, iter, &rect)) {
>+      if (rect.IsEmpty())
>+        return true;
>+      result->Or(*result, rect);
>+    }
>+    return false;
>+  }
>+};
>+
>+template<>
>+struct ParamTraits<nsIntSize>
>+{
>+  typedef nsIntSize paramType;
>+  
>+  static void Write(Message* msg, const paramType& param)
>+  {
>+    WriteParam(msg, param.width);
>+    WriteParam(msg, param.height); 
>+  }
>+
>+  static bool Read(const Message* msg, void** iter, paramType* result)
>+  {
>+    return (ReadParam(msg, iter, &result->width) &&
>+            ReadParam(msg, iter, &result->height));
>+  }
>+};
>+
> } /* namespace IPC */
> 
> #endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */
Attachment #449326 - Flags: review?(joe) → review+
Created attachment 449808 [details] [diff] [review]
Implement serialization of a grab-bag of gfx types, v2 with test

(In reply to comment #3)
> (From update of attachment 449326 [details] [diff] [review])
> 
> >@@ -245,16 +252,17 @@ struct ParamTraits<nsTArray<E> >
> > 
> >   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
> >   {
> >     PRUint32 length;
> >     if (!ReadParam(aMsg, aIter, &length)) {
> >       return false;
> >     }
> > 
> >+    aResult->SetCapacity(length);
> >     for (PRUint32 index = 0; index < length; index++) {
> >       E* element = aResult->AppendElement();
> >       if (!(element && ReadParam(aMsg, aIter, element))) {
> >         return false;
> >       }
> >     }
> > 
> >     return true;
> 
> This hunk should probably be part of a separate bug, right?
> 

We discussed this on IRC.  nsIntRegion isn't memmove()able but nsTArray tries to do so anyway.  This makes for crashy and iloopy, and the SetCapacity() is a partial workaround.  This v2 patch adds a test that reliably ilooped for me in a debug/linux/tracemalloc build without the SetCapacity().
http://hg.mozilla.org/mozilla-central/rev/83deceb1879e
Status: NEW → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.