Bug 685236 - Stop using GetNativePath in gfx/. r?jrmuizel draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sun, 17 Dec 2017 00:13:30 +0900
changeset 715691 4295716047daef1499355640992486975296f4b0
parent 715690 b957358ab015866ee4a5449521c6f5006d86c4b7
child 715692 3c7a6e50dde65de54928c313f1ce6afadda6b4eb
push id94228
push userVYV03354@nifty.ne.jp
push dateThu, 04 Jan 2018 11:56:10 +0000
reviewersjrmuizel
bugs685236
milestone59.0a1
Bug 685236 - Stop using GetNativePath in gfx/. r?jrmuizel MozReview-Commit-ID: EdcKDRQeGXg
gfx/2d/2D.h
gfx/2d/DrawEventRecorder.cpp
gfx/2d/DrawEventRecorder.h
gfx/2d/Factory.cpp
gfx/config/gfxVars.h
gfx/gl/GLLibraryEGL.cpp
gfx/ipc/GraphicsMessages.ipdlh
gfx/layers/composite/FPSCounter.cpp
gfx/thebes/gfxPlatform.cpp
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -17,16 +17,17 @@
 #include <vector>
 
 // GenericRefCountedBase allows us to hold on to refcounted objects of any type
 // (contrary to RefCounted<T> which requires knowing the type T) and, in particular,
 // without having a dependency on that type. This is used for DrawTargetSkia
 // to be able to hold on to a GLContext.
 #include "mozilla/GenericRefCounted.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/Path.h"
 
 // This RefPtr class isn't ideal for usage in Azure, as it doesn't allow T**
 // outparams using the &-operator. But it will have to do as there's no easy
 // solution.
 #include "mozilla/RefPtr.h"
 #include "mozilla/StaticMutex.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/ThreadSafeWeakPtr.h"
@@ -1475,16 +1476,17 @@ struct Config {
   : mLogForwarder(nullptr)
   , mMaxTextureSize(8192)
   , mMaxAllocSize(52000000)
   {}
 };
 
 class GFX2D_API Factory
 {
+  using char_type = filesystem::Path::value_type;
 public:
   static void Init(const Config& aConfig);
   static void ShutDown();
 
   static bool HasSSE2();
 
   /**
    * Returns false if any of the following are true:
@@ -1639,17 +1641,17 @@ public:
                                     void* aClosure = nullptr);
 
   static void
     CopyDataSourceSurface(DataSourceSurface* aSource,
                           DataSourceSurface* aDest);
 
 
   static already_AddRefed<DrawEventRecorder>
-    CreateEventRecorderForFile(const char *aFilename);
+    CreateEventRecorderForFile(const char_type* aFilename);
 
   static void SetGlobalEventRecorder(DrawEventRecorder *aRecorder);
 
   static uint32_t GetMaxSurfaceSize(BackendType aType);
 
   static LogForwarder* GetLogForwarder() { return sConfig ? sConfig->mLogForwarder : nullptr; }
 
 private:
--- a/gfx/2d/DrawEventRecorder.cpp
+++ b/gfx/2d/DrawEventRecorder.cpp
@@ -2,16 +2,20 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DrawEventRecorder.h"
 #include "PathRecording.h"
 #include "RecordingTypes.h"
+#ifdef __MINGW32__
+#include <fcntl.h>
+#include <ext/stdio_filebuf.h>
+#endif
 
 namespace mozilla {
 namespace gfx {
 
 using namespace std;
 
 DrawEventRecorderPrivate::DrawEventRecorderPrivate() : mExternalFonts(false)
 {
@@ -30,54 +34,87 @@ DrawEventRecorderFile::RecordEvent(const
 void
 DrawEventRecorderMemory::RecordEvent(const RecordedEvent &aEvent)
 {
   WriteElement(mOutputStream, aEvent.mType);
 
   aEvent.RecordToStream(mOutputStream);
 }
 
-DrawEventRecorderFile::DrawEventRecorderFile(const char *aFilename)
+DrawEventRecorderFile::DrawEventRecorderFile(const char_type* aFilename)
+#if defined(__MINGW32__)
+  : mFileBuf(new __gnu_cxx::stdio_filebuf<char>(
+               _wopen(reinterpret_cast<const wchar_t*>(aFilename),
+                      _O_WRONLY | _O_BINARY | _O_CREAT | _O_TRUNC),
+               std::ios::out | std::ios::binary | std::ios::trunc))
+  , mOutputStream(mFileBuf.get())
+#elif defined(XP_WIN)
+  : mOutputStream(reinterpret_cast<const wchar_t*>(aFilename), ofstream::binary)
+#else
   : mOutputStream(aFilename, ofstream::binary)
+#endif
 {
   WriteHeader(mOutputStream);
 }
 
 DrawEventRecorderFile::~DrawEventRecorderFile()
 {
+#ifdef __MINGW32__
+  mFileBuf->close();
+#else
   mOutputStream.close();
+#endif
 }
 
 void
 DrawEventRecorderFile::Flush()
 {
   mOutputStream.flush();
 }
 
 bool
 DrawEventRecorderFile::IsOpen()
 {
+#ifdef __MINGW32__
+  return mFileBuf->is_open();
+#else
   return mOutputStream.is_open();
+#endif
 }
 
 void
-DrawEventRecorderFile::OpenNew(const char *aFilename)
+DrawEventRecorderFile::OpenNew(const char_type* aFilename)
 {
-  MOZ_ASSERT(!mOutputStream.is_open());
+  MOZ_ASSERT(!IsOpen());
 
+#ifdef __MINGW32__
+  int fd = _wopen(reinterpret_cast<const wchar_t*>(aFilename),
+                  _O_WRONLY | _O_BINARY | _O_CREAT | _O_TRUNC);
+  mFileBuf.reset(new __gnu_cxx::stdio_filebuf<char>(fd, std::ios::out |
+                                                        std::ios::binary |
+                                                        std::ios::trunc));
+  mOutputStream.rdbuf(mFileBuf.get());
+#elif defined(XP_WIN)
+  mOutputStream.open(reinterpret_cast<const wchar_t*>(aFilename), ofstream::binary);
+#else
   mOutputStream.open(aFilename, ofstream::binary);
+#endif
   WriteHeader(mOutputStream);
 }
 
 void
 DrawEventRecorderFile::Close()
 {
-  MOZ_ASSERT(mOutputStream.is_open());
+  MOZ_ASSERT(IsOpen());
 
+#ifdef __MINGW32__
+  mFileBuf->close();
+#else
   mOutputStream.close();
+#endif
 }
 
 DrawEventRecorderMemory::DrawEventRecorderMemory()
 {
   WriteHeader(mOutputStream);
 }
 
 DrawEventRecorderMemory::DrawEventRecorderMemory(const SerializeResourcesFn &aFn) :
--- a/gfx/2d/DrawEventRecorder.h
+++ b/gfx/2d/DrawEventRecorder.h
@@ -123,46 +123,52 @@ protected:
   std::unordered_set<SourceSurface*> mStoredSurfaces;
   std::vector<RefPtr<UnscaledFont>> mUnscaledFonts;
   std::unordered_map<UnscaledFont*, size_t> mUnscaledFontMap;
   bool mExternalFonts;
 };
 
 class DrawEventRecorderFile : public DrawEventRecorderPrivate
 {
+  using char_type = filesystem::Path::value_type;
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderFile, override)
-  explicit DrawEventRecorderFile(const char *aFilename);
+  explicit DrawEventRecorderFile(const char_type* aFilename);
   ~DrawEventRecorderFile();
 
   void RecordEvent(const RecordedEvent &aEvent) override;
 
   /**
    * Returns whether a recording file is currently open.
    */
   bool IsOpen();
 
   /**
    * Opens new file with the provided name. The recorder does NOT forget which
    * objects it has recorded. This can be used with Close, so that a recording
    * can be processed in chunks. The file must not already be open.
    */
-  void OpenNew(const char *aFilename);
+  void OpenNew(const char_type* aFilename);
 
   /**
    * Closes the file so that it can be processed. The recorder does NOT forget
    * which objects it has recorded. This can be used with OpenNew, so that a
    * recording can be processed in chunks. The file must be open.
    */
   void Close();
 
 private:
   void Flush() override;
 
+#ifdef __MINGW32__
+  mozilla::UniquePtr<std::filebuf> mFileBuf;
+  std::ostream mOutputStream;
+#else
   std::ofstream mOutputStream;
+#endif
 };
 
 typedef std::function<void(MemStream &aStream, std::vector<RefPtr<UnscaledFont>> &aUnscaledFonts)> SerializeResourcesFn;
 
 // WARNING: This should not be used in its existing state because
 // it is likely to OOM because of large continguous allocations.
 class DrawEventRecorderMemory final : public DrawEventRecorderPrivate
 {
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -1134,17 +1134,17 @@ Factory::CopyDataSourceSurface(DataSourc
               destMap.mData, destMap.mStride, aDest->GetFormat(),
               aSource->GetSize());
 
   aSource->Unmap();
   aDest->Unmap();
 }
 
 already_AddRefed<DrawEventRecorder>
-Factory::CreateEventRecorderForFile(const char *aFilename)
+Factory::CreateEventRecorderForFile(const char_type* aFilename)
 {
   return MakeAndAddRef<DrawEventRecorderFile>(aFilename);
 }
 
 void
 Factory::SetGlobalEventRecorder(DrawEventRecorder *aRecorder)
 {
   mRecorder = aRecorder;
--- a/gfx/config/gfxVars.h
+++ b/gfx/config/gfxVars.h
@@ -34,17 +34,17 @@ class gfxVarReceiver;
   _(PDMWMFDisableD3D11Dlls,     nsCString,        nsCString())          \
   _(PDMWMFDisableD3D9Dlls,      nsCString,        nsCString())          \
   _(DXInterop2Blocked,          bool,             false)                \
   _(UseWebRender,               bool,             false)                \
   _(UseWebRenderANGLE,          bool,             false)                \
   _(UseWebRenderProgramBinary,  bool,             false)                \
   _(WebRenderDebugFlags,        int32_t,          0)                    \
   _(ScreenDepth,                int32_t,          0)                    \
-  _(GREDirectory,               nsCString,        nsCString())          \
+  _(GREDirectory,               nsString,         nsString())           \
   _(UseOMTP,                    bool,             false)                \
   _(AllowD3D11KeyedMutex,       bool,             false)                \
 
   /* Add new entries above this line. */
 
 // Define the default animation backend on the compositor. Now we don't use
 // stylo on the compositor only on Android, and this is a fixed flag. If
 // we want to update this flag, please add a new gfxVars for it.
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -101,23 +101,23 @@ static PRLibrary* LoadApitraceLibrary()
 
 #endif // ANDROID
 
 #ifdef XP_WIN
 // see the comment in GLLibraryEGL::EnsureInitialized() for the rationale here.
 static PRLibrary*
 LoadLibraryForEGLOnWindows(const nsAString& filename)
 {
-    nsAutoCString path(gfx::gfxVars::GREDirectory());
+    nsAutoString path(gfx::gfxVars::GREDirectory());
     path.Append(PR_GetDirectorySeparator());
-    path.Append(ToNewUTF8String(filename));
+    path.Append(filename);
 
     PRLibSpec lspec;
-    lspec.type = PR_LibSpec_Pathname;
-    lspec.value.pathname = path.get();
+    lspec.type = PR_LibSpec_PathnameU;
+    lspec.value.pathname_u = path.get();
     return PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_LOCAL);
 }
 
 #endif // XP_WIN
 
 static EGLDisplay
 GetAndInitWARPDisplay(GLLibraryEGL& egl, void* displayType)
 {
--- a/gfx/ipc/GraphicsMessages.ipdlh
+++ b/gfx/ipc/GraphicsMessages.ipdlh
@@ -72,16 +72,17 @@ struct GPUDeviceData
 
 union GfxVarValue
 {
   BackendType;
   bool;
   gfxImageFormat;
   IntSize;
   nsCString;
+  nsString;
   int32_t;
 };
 
 struct GfxVarUpdate
 {
   size_t index;
   GfxVarValue value;
 };
--- a/gfx/layers/composite/FPSCounter.cpp
+++ b/gfx/layers/composite/FPSCounter.cpp
@@ -359,18 +359,15 @@ FPSCounter::WriteFrameTimeStamps()
   int mode = 644;
   int openFlags = PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE;
   rv = resultFile->OpenNSPRFileDesc(openFlags, mode, &fd);
   NS_ENSURE_SUCCESS(rv, rv);
 
   WriteFrameTimeStamps(fd);
   PR_Close(fd);
 
-  nsAutoCString path;
-  rv = resultFile->GetNativePath(path);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  printf_stderr("Wrote FPS data to file: %s\n", path.get());
+  printf_stderr("Wrote FPS data to file: %s\n",
+                resultFile->DisplayPath().get());
   return NS_OK;
 }
 
 } // end namespace layers
 } // end namespace mozilla
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -562,34 +562,43 @@ gfxPlatform::InitChild(const ContentDevi
 
 void RecordingPrefChanged(const char *aPrefName, void *aClosure)
 {
   if (Preferences::GetBool("gfx.2d.recording", false)) {
     nsAutoCString fileName;
     nsAutoString prefFileName;
     nsresult rv = Preferences::GetString("gfx.2d.recordingfile", prefFileName);
     if (NS_SUCCEEDED(rv)) {
-      fileName.Append(NS_ConvertUTF16toUTF8(prefFileName));
+      CopyUTF16toUTF8(prefFileName, fileName);
     } else {
       nsCOMPtr<nsIFile> tmpFile;
       if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)))) {
         return;
       }
       fileName.AppendPrintf("moz2drec_%i_%i.aer", XRE_GetProcessType(), getpid());
 
       nsresult rv = tmpFile->AppendNative(fileName);
       if (NS_FAILED(rv))
         return;
 
+#ifdef XP_WIN
+      rv = tmpFile->GetPath(prefFileName);
+      CopyUTF16toUTF8(prefFileName, fileName);
+#else
       rv = tmpFile->GetNativePath(fileName);
+#endif
       if (NS_FAILED(rv))
         return;
     }
 
+#ifdef XP_WIN
+    gPlatform->mRecorder = Factory::CreateEventRecorderForFile(prefFileName.BeginReading());
+#else
     gPlatform->mRecorder = Factory::CreateEventRecorderForFile(fileName.BeginReading());
+#endif
     printf_stderr("Recording to %s\n", fileName.get());
     Factory::SetGlobalEventRecorder(gPlatform->mRecorder);
   } else {
     Factory::SetGlobalEventRecorder(nullptr);
   }
 }
 
 #define WR_DEBUG_PREF "gfx.webrender.debug"
@@ -672,21 +681,21 @@ gfxPlatform::Init()
         nsAutoCString d3d9;
         Preferences::GetCString("media.wmf.disable-d3d9-for-dlls", d3d9);
         gfxVars::SetPDMWMFDisableD3D9Dlls(d3d9);
       }
 
       nsCOMPtr<nsIFile> file;
       nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
       if (NS_FAILED(rv)) {
-        gfxVars::SetGREDirectory(nsCString());
+        gfxVars::SetGREDirectory(nsString());
       } else {
-        nsAutoCString nativePath;
-        file->GetNativePath(nativePath);
-        gfxVars::SetGREDirectory(nsCString(nativePath));
+        nsAutoString path;
+        file->GetPath(path);
+        gfxVars::SetGREDirectory(nsString(path));
       }
     }
 
     // Drop a note in the crash report if we end up forcing an option that could
     // destabilize things.  New items should be appended at the end (of an existing
     // or in a new section), so that we don't have to know the version to interpret
     // these cryptic strings.
     {