Bug 1581307 - Remove wr::WrExternalImageId r=jrmuizel
authorsotaro <sotaro.ikeda.g@gmail.com>
Mon, 16 Sep 2019 22:13:16 +0000
changeset 493479 7c893cf0c368c6453e63f06af491368e924e83c9
parent 493478 6c6c2a82876fa91f7b38483aec7bfb7632f68bf7
child 493480 0bf953d07a4f672542ff1ccd401980fc905604a2
push id114090
push userrgurzau@mozilla.com
push dateTue, 17 Sep 2019 09:38:30 +0000
treeherdermozilla-inbound@04da00a61c6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1581307
milestone71.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 1581307 - Remove wr::WrExternalImageId r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D45937
gfx/layers/ipc/SharedSurfacesChild.cpp
gfx/layers/ipc/SharedSurfacesParent.cpp
gfx/webrender_bindings/RenderThread.cpp
gfx/webrender_bindings/RenderThread.h
gfx/webrender_bindings/RendererOGL.cpp
gfx/webrender_bindings/RendererOGL.h
gfx/webrender_bindings/WebRenderTypes.h
gfx/webrender_bindings/src/bindings.rs
--- a/gfx/layers/ipc/SharedSurfacesChild.cpp
+++ b/gfx/layers/ipc/SharedSurfacesChild.cpp
@@ -571,17 +571,17 @@ nsresult SharedSurfacesAnimation::Update
     wr::ImageKey& aKey) {
   SharedSurfacesChild::SharedUserData* data = nullptr;
   nsresult rv = SharedSurfacesChild::ShareInternal(aSurface, &data);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   MOZ_ASSERT(data);
-  if (mId.mHandle != data->Id().mHandle) {
+  if (wr::AsUint64(mId) != wr::AsUint64(data->Id())) {
     mKeys.Clear();
     mId = data->Id();
   }
 
   // We iterate through all of the items to ensure we clean up the old
   // RenderRootStateManager references. Most of the time there will be few
   // entries and this should not be particularly expensive compared to the
   // cost of duplicating image keys. In an ideal world, we would generate a
--- a/gfx/layers/ipc/SharedSurfacesParent.cpp
+++ b/gfx/layers/ipc/SharedSurfacesParent.cpp
@@ -50,31 +50,31 @@ void SharedSurfacesParent::Shutdown() {
   sInstance = nullptr;
 }
 
 /* static */
 already_AddRefed<DataSourceSurface> SharedSurfacesParent::Get(
     const wr::ExternalImageId& aId) {
   StaticMutexAutoLock lock(sMutex);
   if (!sInstance) {
-    gfxCriticalNote << "SSP:Get " << aId.mHandle << " shtd";
+    gfxCriticalNote << "SSP:Get " << wr::AsUint64(aId) << " shtd";
     return nullptr;
   }
 
   RefPtr<SourceSurfaceSharedDataWrapper> surface;
   sInstance->mSurfaces.Get(wr::AsUint64(aId), getter_AddRefs(surface));
   return surface.forget();
 }
 
 /* static */
 already_AddRefed<DataSourceSurface> SharedSurfacesParent::Acquire(
     const wr::ExternalImageId& aId) {
   StaticMutexAutoLock lock(sMutex);
   if (!sInstance) {
-    gfxCriticalNote << "SSP:Acq " << aId.mHandle << " shtd";
+    gfxCriticalNote << "SSP:Acq " << wr::AsUint64(aId) << " shtd";
     return nullptr;
   }
 
   RefPtr<SourceSurfaceSharedDataWrapper> surface;
   sInstance->mSurfaces.Get(wr::AsUint64(aId), getter_AddRefs(surface));
 
   if (surface) {
     DebugOnly<bool> rv = surface->AddConsumer();
@@ -108,17 +108,17 @@ bool SharedSurfacesParent::Release(const
 
 /* static */
 void SharedSurfacesParent::AddSameProcess(const wr::ExternalImageId& aId,
                                           SourceSurfaceSharedData* aSurface) {
   MOZ_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(NS_IsMainThread());
   StaticMutexAutoLock lock(sMutex);
   if (!sInstance) {
-    gfxCriticalNote << "SSP:Ads " << aId.mHandle << " shtd";
+    gfxCriticalNote << "SSP:Ads " << wr::AsUint64(aId) << " shtd";
     return;
   }
 
   // If the child bridge detects it is in the combined UI/GPU process, then it
   // will insert a wrapper surface holding the shared memory buffer directly.
   // This is good because we avoid mapping the same shared memory twice, but
   // still allow the original surface to be freed and remove the wrapper from
   // the table when it is no longer needed.
@@ -166,26 +166,26 @@ void SharedSurfacesParent::DestroyProces
 /* static */
 void SharedSurfacesParent::Add(const wr::ExternalImageId& aId,
                                const SurfaceDescriptorShared& aDesc,
                                base::ProcessId aPid) {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   MOZ_ASSERT(aPid != base::GetCurrentProcId());
   StaticMutexAutoLock lock(sMutex);
   if (!sInstance) {
-    gfxCriticalNote << "SSP:Add " << aId.mHandle << " shtd";
+    gfxCriticalNote << "SSP:Add " << wr::AsUint64(aId) << " shtd";
     return;
   }
 
   // Note that the surface wrapper maps in the given handle as read only.
   RefPtr<SourceSurfaceSharedDataWrapper> surface =
       new SourceSurfaceSharedDataWrapper();
   if (NS_WARN_IF(!surface->Init(aDesc.size(), aDesc.stride(), aDesc.format(),
                                 aDesc.handle(), aPid))) {
-    gfxCriticalNote << "SSP:Add " << aId.mHandle << " init";
+    gfxCriticalNote << "SSP:Add " << wr::AsUint64(aId) << " init";
     return;
   }
 
   uint64_t id = wr::AsUint64(aId);
   MOZ_ASSERT(!sInstance->mSurfaces.Contains(id));
 
   RefPtr<wr::RenderSharedSurfaceTextureHost> texture =
       new wr::RenderSharedSurfaceTextureHost(surface);
--- a/gfx/webrender_bindings/RenderThread.cpp
+++ b/gfx/webrender_bindings/RenderThread.cpp
@@ -687,21 +687,21 @@ void RenderThread::UnregisterExternalIma
 }
 
 void RenderThread::DeferredRenderTextureHostDestroy() {
   MutexAutoLock lock(mRenderTextureMapLock);
   mRenderTexturesDeferred.clear();
 }
 
 RenderTextureHost* RenderThread::GetRenderTexture(
-    wr::WrExternalImageId aExternalImageId) {
+    wr::ExternalImageId aExternalImageId) {
   MOZ_ASSERT(IsInRenderThread());
 
   MutexAutoLock lock(mRenderTextureMapLock);
-  auto it = mRenderTextures.find(aExternalImageId.mHandle);
+  auto it = mRenderTextures.find(AsUint64(aExternalImageId));
   MOZ_ASSERT(it != mRenderTextures.end());
   if (it == mRenderTextures.end()) {
     return nullptr;
   }
   return it->second;
 }
 
 void RenderThread::InitDeviceTask() {
--- a/gfx/webrender_bindings/RenderThread.h
+++ b/gfx/webrender_bindings/RenderThread.h
@@ -208,17 +208,17 @@ class RenderThread final {
 
   /// Can only be called from the render thread.
   void NofityForUse(uint64_t aExternalImageId);
 
   /// Can only be called from the render thread.
   void UnregisterExternalImageDuringShutdown(uint64_t aExternalImageId);
 
   /// Can only be called from the render thread.
-  RenderTextureHost* GetRenderTexture(WrExternalImageId aExternalImageId);
+  RenderTextureHost* GetRenderTexture(ExternalImageId aExternalImageId);
 
   /// Can be called from any thread.
   bool IsDestroyed(wr::WindowId aWindowId);
   /// Can be called from any thread.
   void SetDestroyed(wr::WindowId aWindowId);
   /// Can be called from any thread.
   bool TooManyPendingFrames(wr::WindowId aWindowId);
   /// Can be called from any thread.
--- a/gfx/webrender_bindings/RendererOGL.cpp
+++ b/gfx/webrender_bindings/RendererOGL.cpp
@@ -15,30 +15,30 @@
 #include "mozilla/webrender/RenderCompositor.h"
 #include "mozilla/webrender/RenderTextureHost.h"
 #include "mozilla/widget/CompositorWidget.h"
 
 namespace mozilla {
 namespace wr {
 
 wr::WrExternalImage wr_renderer_lock_external_image(
-    void* aObj, wr::WrExternalImageId aId, uint8_t aChannelIndex,
+    void* aObj, wr::ExternalImageId aId, uint8_t aChannelIndex,
     wr::ImageRendering aRendering) {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
   RenderTextureHost* texture = renderer->GetRenderTexture(aId);
   MOZ_ASSERT(texture);
   if (!texture) {
     gfxCriticalNote << "Failed to lock ExternalImage for extId:"
                     << AsUint64(aId);
     return InvalidToWrExternalImage();
   }
   return texture->Lock(aChannelIndex, renderer->gl(), aRendering);
 }
 
-void wr_renderer_unlock_external_image(void* aObj, wr::WrExternalImageId aId,
+void wr_renderer_unlock_external_image(void* aObj, wr::ExternalImageId aId,
                                        uint8_t aChannelIndex) {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
   RenderTextureHost* texture = renderer->GetRenderTexture(aId);
   MOZ_ASSERT(texture);
   if (!texture) {
     return;
   }
   texture->Unlock();
@@ -225,17 +225,17 @@ void RendererOGL::SetFrameStartTime(cons
 }
 
 RefPtr<WebRenderPipelineInfo> RendererOGL::FlushPipelineInfo() {
   auto info = wr_renderer_flush_pipeline_info(mRenderer);
   return new WebRenderPipelineInfo(info);
 }
 
 RenderTextureHost* RendererOGL::GetRenderTexture(
-    wr::WrExternalImageId aExternalImageId) {
+    wr::ExternalImageId aExternalImageId) {
   return mThread->GetRenderTexture(aExternalImageId);
 }
 
 void RendererOGL::AccumulateMemoryReport(MemoryReport* aReport) {
   wr_renderer_accumulate_memory_report(GetRenderer(), aReport);
 
   LayoutDeviceIntSize size = mCompositor->GetBufferSize();
 
--- a/gfx/webrender_bindings/RendererOGL.h
+++ b/gfx/webrender_bindings/RendererOGL.h
@@ -42,20 +42,20 @@ class RenderTextureHost;
 
 /// Owns the WebRender renderer and GL context.
 ///
 /// There is one renderer per window, all owned by the render thread.
 /// This class is a similar abstraction to CompositorOGL except that it is used
 /// on the render thread instead of the compositor thread.
 class RendererOGL {
   friend wr::WrExternalImage LockExternalImage(void* aObj,
-                                               wr::WrExternalImageId aId,
+                                               wr::ExternalImageId aId,
                                                uint8_t aChannelIndex,
                                                wr::ImageRendering);
-  friend void UnlockExternalImage(void* aObj, wr::WrExternalImageId aId,
+  friend void UnlockExternalImage(void* aObj, wr::ExternalImageId aId,
                                   uint8_t aChannelIndex);
 
  public:
   wr::WrExternalImageHandler GetExternalImageHandler();
 
   /// This can be called on the render thread only.
   void Update();
 
@@ -92,17 +92,17 @@ class RendererOGL {
   void CheckGraphicsResetStatus();
 
   layers::SyncObjectHost* GetSyncObject() const;
 
   layers::CompositorBridgeParent* GetCompositorBridge() { return mBridge; }
 
   RefPtr<WebRenderPipelineInfo> FlushPipelineInfo();
 
-  RenderTextureHost* GetRenderTexture(wr::WrExternalImageId aExternalImageId);
+  RenderTextureHost* GetRenderTexture(wr::ExternalImageId aExternalImageId);
 
   void AccumulateMemoryReport(MemoryReport* aReport);
 
   wr::Renderer* GetRenderer() { return mRenderer; }
 
   gl::GLContext* gl() const;
 
  protected:
--- a/gfx/webrender_bindings/WebRenderTypes.h
+++ b/gfx/webrender_bindings/WebRenderTypes.h
@@ -39,17 +39,16 @@ typedef uintptr_t usize;
 typedef wr::WrWindowId WindowId;
 typedef wr::WrPipelineId PipelineId;
 typedef wr::WrDocumentId DocumentId;
 typedef wr::WrRemovedPipeline RemovedPipeline;
 typedef wr::WrImageKey ImageKey;
 typedef wr::WrFontKey FontKey;
 typedef wr::WrFontInstanceKey FontInstanceKey;
 typedef wr::WrEpoch Epoch;
-typedef wr::WrExternalImageId ExternalImageId;
 
 typedef mozilla::Maybe<mozilla::wr::IdNamespace> MaybeIdNamespace;
 typedef mozilla::Maybe<mozilla::wr::ImageMask> MaybeImageMask;
 typedef Maybe<ExternalImageId> MaybeExternalImageId;
 
 typedef Maybe<FontInstanceOptions> MaybeFontInstanceOptions;
 typedef Maybe<FontInstancePlatformOptions> MaybeFontInstancePlatformOptions;
 
@@ -682,22 +681,22 @@ static inline wr::WrOpacityProperty ToWr
   wr::WrOpacityProperty prop;
   prop.id = id;
   prop.opacity = opacity;
   return prop;
 }
 
 // Whenever possible, use wr::ExternalImageId instead of manipulating uint64_t.
 inline uint64_t AsUint64(const ExternalImageId& aId) {
-  return static_cast<uint64_t>(aId.mHandle);
+  return static_cast<uint64_t>(aId._0);
 }
 
 static inline ExternalImageId ToExternalImageId(uint64_t aID) {
   ExternalImageId Id;
-  Id.mHandle = aID;
+  Id._0 = aID;
   return Id;
 }
 
 static inline wr::WrExternalImage RawDataToWrExternalImage(const uint8_t* aBuff,
                                                            size_t size) {
   return wr::WrExternalImage{
       wr::WrExternalImageType::RawData, 0, 0.0f, 0.0f, 0.0f, 0.0f, aBuff, size};
 }
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -362,32 +362,16 @@ impl<'a> Into<ImageDescriptor> for &'a W
             format: self.format,
             is_opaque: self.opacity == OpacityType::Opaque,
             offset: 0,
             allow_mipmaps: false,
         }
     }
 }
 
-/// cbindgen:field-names=[mHandle]
-#[repr(C)]
-#[derive(Copy, Clone)]
-pub struct WrExternalImageId(pub u64);
-
-impl Into<ExternalImageId> for WrExternalImageId {
-    fn into(self) -> ExternalImageId {
-        ExternalImageId(self.0)
-    }
-}
-impl Into<WrExternalImageId> for ExternalImageId {
-    fn into(self) -> WrExternalImageId {
-        WrExternalImageId(self.0)
-    }
-}
-
 #[repr(u32)]
 #[allow(dead_code)]
 enum WrExternalImageType {
     RawData,
     NativeTexture,
     Invalid,
 }
 
@@ -406,54 +390,54 @@ struct WrExternalImage {
     // external image buffer
     buff: *const u8,
     size: usize,
 }
 
 extern "C" {
     fn wr_renderer_lock_external_image(
         renderer: *mut c_void,
-        external_image_id: WrExternalImageId,
+        external_image_id: ExternalImageId,
         channel_index: u8,
         rendering: ImageRendering) -> WrExternalImage;
     fn wr_renderer_unlock_external_image(
         renderer: *mut c_void,
-        external_image_id: WrExternalImageId,
+        external_image_id: ExternalImageId,
         channel_index: u8);
 }
 
 #[repr(C)]
 #[derive(Copy, Clone, Debug)]
 pub struct WrExternalImageHandler {
     external_image_obj: *mut c_void,
 }
 
 impl ExternalImageHandler for WrExternalImageHandler {
     fn lock(&mut self,
             id: ExternalImageId,
             channel_index: u8,
             rendering: ImageRendering)
             -> ExternalImage {
 
-        let image = unsafe { wr_renderer_lock_external_image(self.external_image_obj, id.into(), channel_index, rendering) };
+        let image = unsafe { wr_renderer_lock_external_image(self.external_image_obj, id, channel_index, rendering) };
         ExternalImage {
             uv: TexelRect::new(image.u0, image.v0, image.u1, image.v1),
             source: match image.image_type {
                 WrExternalImageType::NativeTexture => ExternalImageSource::NativeTexture(image.handle),
                 WrExternalImageType::RawData => ExternalImageSource::RawData(unsafe { make_slice(image.buff, image.size) }),
                 WrExternalImageType::Invalid => ExternalImageSource::Invalid,
             },
         }
     }
 
     fn unlock(&mut self,
               id: ExternalImageId,
               channel_index: u8) {
         unsafe {
-            wr_renderer_unlock_external_image(self.external_image_obj, id.into(), channel_index);
+            wr_renderer_unlock_external_image(self.external_image_obj, id, channel_index);
         }
     }
 }
 
 #[repr(C)]
 #[derive(Clone, Copy)]
 // Used for ComponentTransfer only
 pub struct WrFilterData {
@@ -1624,26 +1608,26 @@ pub extern "C" fn wr_resource_updates_ad
     );
 }
 
 #[no_mangle]
 pub extern "C" fn wr_resource_updates_add_external_image(
     txn: &mut Transaction,
     image_key: WrImageKey,
     descriptor: &WrImageDescriptor,
-    external_image_id: WrExternalImageId,
+    external_image_id: ExternalImageId,
     image_type: &ExternalImageType,
     channel_index: u8
 ) {
     txn.add_image(
         image_key,
         descriptor.into(),
         ImageData::External(
             ExternalImageData {
-                id: external_image_id.into(),
+                id: external_image_id,
                 channel_index: channel_index,
                 image_type: *image_type,
             }
         ),
         None
     );
 }
 
@@ -1671,50 +1655,50 @@ pub extern "C" fn wr_resource_updates_se
     txn.set_blob_image_visible_area(key, *area);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_resource_updates_update_external_image(
     txn: &mut Transaction,
     key: WrImageKey,
     descriptor: &WrImageDescriptor,
-    external_image_id: WrExternalImageId,
+    external_image_id: ExternalImageId,
     image_type: &ExternalImageType,
     channel_index: u8
 ) {
     txn.update_image(
         key,
         descriptor.into(),
         ImageData::External(
             ExternalImageData {
-                id: external_image_id.into(),
+                id: external_image_id,
                 channel_index,
                 image_type: *image_type,
             }
         ),
         &DirtyRect::All,
     );
 }
 
 #[no_mangle]
 pub extern "C" fn wr_resource_updates_update_external_image_with_dirty_rect(
     txn: &mut Transaction,
     key: WrImageKey,
     descriptor: &WrImageDescriptor,
-    external_image_id: WrExternalImageId,
+    external_image_id: ExternalImageId,
     image_type: &ExternalImageType,
     channel_index: u8,
     dirty_rect: DeviceIntRect,
 ) {
     txn.update_image(
         key,
         descriptor.into(),
         ImageData::External(
             ExternalImageData {
-                id: external_image_id.into(),
+                id: external_image_id,
                 channel_index,
                 image_type: *image_type,
             }
         ),
         &DirtyRect::Partial(dirty_rect)
     );
 }