Bug 1310885 - Part 3. (gecko) Create a new API to receive cached ImageValue from stylo. r=heycam
☠☠ backed out by 644548803654 ☠ ☠
authorcku <cku@mozilla.com>
Tue, 02 May 2017 16:20:01 +0800
changeset 358032 7c2db290c4b64b0e50b1a44f5d2a42bfe119f196
parent 358031 accca3d23d7bf2df1b66186e564c79e87e67f45a
child 358033 9245a2fbb97450916828f075badf20741dbcd6f0
push id31808
push usercbook@mozilla.com
push dateFri, 12 May 2017 12:37:49 +0000
treeherdermozilla-central@030c0a7c8781 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1310885
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1310885 - Part 3. (gecko) Create a new API to receive cached ImageValue from stylo. r=heycam This patch implement several things: 1. Implement a new constructor for nsStyleImageRequest to receive an existing ImageValue from the caller. 2. Implement Gecko_ImageValue_Create to allow stylo to create a gecko::ImageValue object. 3. Implement Gecko_SetXXXXImageValue to allow stylo to pass a created ImageValue back to gecko. MozReview-Commit-ID: 1SbW5w8FSV2
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -1166,19 +1166,50 @@ CreateStyleImageRequest(nsStyleImageRequ
 
   RefPtr<nsStyleImageRequest> req =
     new nsStyleImageRequest(aModeFlags, url, do_AddRef(aURI.mExtraData));
   return req.forget();
 }
 
 NS_IMPL_THREADSAFE_FFI_REFCOUNTING(mozilla::css::ImageValue, ImageValue);
 
+static already_AddRefed<nsStyleImageRequest>
+CreateStyleImageRequest(nsStyleImageRequest::Mode aModeFlags,
+                        mozilla::css::ImageValue* aImageValue)
+{
+  RefPtr<nsStyleImageRequest> req =
+    new nsStyleImageRequest(aModeFlags, aImageValue);
+  return req.forget();
+}
+
+mozilla::css::ImageValue*
+Gecko_ImageValue_Create(ServoBundledURI aURI)
+{
+  NS_ConvertUTF8toUTF16 url(reinterpret_cast<const char*>(aURI.mURLString),
+                            aURI.mURLStringLength);
+
+  RefPtr<ImageValue> value(new ImageValue(url, do_AddRef(aURI.mExtraData)));
+  return value.forget().take();
+}
+
+void
+Gecko_SetLayerImageImageValue(nsStyleImage* aImage,
+                              mozilla::css::ImageValue* aImageValue)
+{
+  MOZ_ASSERT(aImage && aImageValue);
+
+  RefPtr<nsStyleImageRequest> req =
+    CreateStyleImageRequest(nsStyleImageRequest::Mode::Track, aImageValue);
+  aImage->SetImageRequest(req.forget());
+}
+
 void
 Gecko_SetUrlImageValue(nsStyleImage* aImage, ServoBundledURI aURI)
 {
+  MOZ_ASSERT(aImage);
   RefPtr<nsStyleImageRequest> req =
     CreateStyleImageRequest(nsStyleImageRequest::Mode::Track, aURI);
   aImage->SetImageRequest(req.forget());
 }
 
 void
 Gecko_SetImageElement(nsStyleImage* aImage, nsIAtom* aAtom) {
   MOZ_ASSERT(aImage);
@@ -1204,30 +1235,51 @@ Gecko_InitializeImageCropRect(nsStyleIma
 void
 Gecko_SetCursorArrayLength(nsStyleUserInterface* aStyleUI, size_t aLen)
 {
   aStyleUI->mCursorImages.Clear();
   aStyleUI->mCursorImages.SetLength(aLen);
 }
 
 void
+Gecko_SetCursorImageValue(nsCursorImage* aCursor,
+                          mozilla::css::ImageValue* aImageValue)
+{
+  MOZ_ASSERT(aCursor && aImageValue);
+
+  aCursor->mImage =
+    CreateStyleImageRequest(nsStyleImageRequest::Mode::Discard, aImageValue);
+}
+
+void
 Gecko_SetCursorImage(nsCursorImage* aCursor, ServoBundledURI aURI)
 {
   aCursor->mImage =
     CreateStyleImageRequest(nsStyleImageRequest::Mode::Discard, aURI);
 }
 
 void
 Gecko_CopyCursorArrayFrom(nsStyleUserInterface* aDest,
                           const nsStyleUserInterface* aSrc)
 {
   aDest->mCursorImages = aSrc->mCursorImages;
 }
 
 void
+Gecko_SetContentDataImageValue(nsStyleContentData* aContent,
+                               mozilla::css::ImageValue* aImageValue)
+{
+  MOZ_ASSERT(aContent && aImageValue);
+
+  RefPtr<nsStyleImageRequest> req =
+    CreateStyleImageRequest(nsStyleImageRequest::Mode::Track, aImageValue);
+  aContent->SetImageRequest(req.forget());
+}
+
+void
 Gecko_SetContentDataImage(nsStyleContentData* aContent, ServoBundledURI aURI)
 {
   RefPtr<nsStyleImageRequest> req = CreateStyleImageRequest(nsStyleImageRequest::Mode::Track, aURI);
   aContent->SetImageRequest(req.forget());
 }
 
 void
 Gecko_SetContentDataArray(nsStyleContentData* aContent,
@@ -1271,16 +1323,26 @@ Gecko_CreateGradient(uint8_t aShape,
 
 void
 Gecko_SetListStyleImageNone(nsStyleList* aList)
 {
   aList->mListStyleImage = nullptr;
 }
 
 void
+Gecko_SetListStyleImageImageValue(nsStyleList* aList,
+                             mozilla::css::ImageValue* aImageValue)
+{
+  MOZ_ASSERT(aList && aImageValue);
+
+  aList->mListStyleImage =
+    CreateStyleImageRequest(nsStyleImageRequest::Mode(0), aImageValue);
+}
+
+void
 Gecko_SetListStyleImage(nsStyleList* aList,
                         ServoBundledURI aURI)
 {
   aList->mListStyleImage =
     CreateStyleImageRequest(nsStyleImageRequest::Mode(0), aURI);
 }
 
 void
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -271,41 +271,55 @@ void Gecko_CopyImageOrientationFrom(nsSt
 // Counter style.
 void Gecko_SetListStyleType(nsStyleList* style_struct, uint32_t type);
 void Gecko_CopyListStyleTypeFrom(nsStyleList* dst, const nsStyleList* src);
 
 // background-image style.
 void Gecko_SetNullImageValue(nsStyleImage* image);
 void Gecko_SetGradientImageValue(nsStyleImage* image, nsStyleGradient* gradient);
 NS_DECL_THREADSAFE_FFI_REFCOUNTING(mozilla::css::ImageValue, ImageValue);
+mozilla::css::ImageValue* Gecko_ImageValue_Create(ServoBundledURI aURI);
+void Gecko_SetLayerImageImageValue(nsStyleImage* image,
+                                   mozilla::css::ImageValue* aImageValue);
+
+// XXX cku: remove this function after gecko and stylo side are both ready
 void Gecko_SetUrlImageValue(nsStyleImage* image,
                             ServoBundledURI uri);
 void Gecko_SetImageElement(nsStyleImage* image, nsIAtom* atom);
 void Gecko_CopyImageValueFrom(nsStyleImage* image, const nsStyleImage* other);
 void Gecko_InitializeImageCropRect(nsStyleImage* image);
 
 nsStyleGradient* Gecko_CreateGradient(uint8_t shape,
                                       uint8_t size,
                                       bool repeating,
                                       bool legacy_syntax,
                                       uint32_t stops);
 
 // list-style-image style.
 void Gecko_SetListStyleImageNone(nsStyleList* style_struct);
+void Gecko_SetListStyleImageImageValue(nsStyleList* style_struct,
+                                  mozilla::css::ImageValue* aImageValue);
+// XXX cku: remove this function after gecko and stylo side are both ready
 void Gecko_SetListStyleImage(nsStyleList* style_struct,
                              ServoBundledURI uri);
 void Gecko_CopyListStyleImageFrom(nsStyleList* dest, const nsStyleList* src);
 
 // cursor style.
 void Gecko_SetCursorArrayLength(nsStyleUserInterface* ui, size_t len);
+void Gecko_SetCursorImageValue(nsCursorImage* aCursor,
+                               mozilla::css::ImageValue* aImageValue);
+// XXX cku: remove this function after gecko and stylo side are both ready
 void Gecko_SetCursorImage(nsCursorImage* cursor,
                           ServoBundledURI uri);
 void Gecko_CopyCursorArrayFrom(nsStyleUserInterface* dest,
                                const nsStyleUserInterface* src);
 
+void Gecko_SetContentDataImageValue(nsStyleContentData* aList,
+                                    mozilla::css::ImageValue* aImageValue);
+// XXX cku: remove this function after gecko and stylo side are both ready
 void Gecko_SetContentDataImage(nsStyleContentData* content_data, ServoBundledURI uri);
 void Gecko_SetContentDataArray(nsStyleContentData* content_data, nsStyleContentType type, uint32_t len);
 
 // Dirtiness tracking.
 uint32_t Gecko_GetNodeFlags(RawGeckoNodeBorrowed node);
 void Gecko_SetNodeFlags(RawGeckoNodeBorrowed node, uint32_t flags);
 void Gecko_UnsetNodeFlags(RawGeckoNodeBorrowed node, uint32_t flags);
 void Gecko_SetOwnerDocumentNeedsStyleFlush(RawGeckoElementBorrowed element);
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -34,16 +34,17 @@
 
 #include "mozilla/dom/AnimationEffectReadOnlyBinding.h" // for PlaybackDirection
 #include "mozilla/dom/DocGroup.h"
 #include "mozilla/dom/ImageTracker.h"
 #include "mozilla/Likely.h"
 #include "nsIURI.h"
 #include "nsIDocument.h"
 #include <algorithm>
+#include "ImageLoader.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static_assert((((1 << nsStyleStructID_Length) - 1) &
                ~(NS_STYLE_INHERIT_MASK)) == 0,
               "Not enough bits in NS_STYLE_INHERIT_MASK");
 
@@ -2014,16 +2015,25 @@ nsStyleImageRequest::nsStyleImageRequest
     const nsAString& aURL,
     already_AddRefed<URLExtraData> aExtraData)
   : mImageValue(new css::ImageValue(aURL, Move(aExtraData)))
   , mModeFlags(aModeFlags)
   , mResolved(false)
 {
 }
 
+nsStyleImageRequest::nsStyleImageRequest(
+    Mode aModeFlags,
+    mozilla::css::ImageValue* aImageValue)
+  : mImageValue(aImageValue)
+  , mModeFlags(aModeFlags)
+  , mResolved(false)
+{
+}
+
 nsStyleImageRequest::~nsStyleImageRequest()
 {
   // We may or may not be being destroyed on the main thread.  To clean
   // up, we must untrack and unlock the image (depending on mModeFlags),
   // and release mRequestProxy and mImageValue, all on the main thread.
   {
     RefPtr<StyleImageRequestCleanupTask> task =
         new StyleImageRequestCleanupTask(mModeFlags,
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -342,16 +342,22 @@ public:
 
   // Can be called from any thread, but Resolve() must be called later
   // on the main thread before get() can be used.
   nsStyleImageRequest(
       Mode aModeFlags,
       const nsAString& aURL,
       already_AddRefed<mozilla::URLExtraData> aExtraData);
 
+  // Can be called from any thread, but Resolve() must be called later
+  // on the main thread before get() can be used.
+  nsStyleImageRequest(
+      Mode aModeFlags,
+      mozilla::css::ImageValue* aImageValue);
+
   bool Resolve(nsPresContext* aPresContext);
   bool IsResolved() const { return mResolved; }
 
   imgRequestProxy* get() {
     MOZ_ASSERT(IsResolved(), "Resolve() must be called first");
     MOZ_ASSERT(NS_IsMainThread());
     return mRequestProxy.get();
   }