Bug 1428258 - Stop using GetNativePath in gfx/. r=jrmuizel
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sun, 17 Dec 2017 00:13:30 +0900
changeset 404762 e3b034c3ac976c423b0b712e337fecb6ac48689f
parent 404761 3089af2474ef23d5edd96c3e5f027a22ab217e21
child 404763 e28a37787c938b78a435422d4830cd05487815eb
push id33489
push userdluca@mozilla.com
push dateThu, 22 Feb 2018 09:59:00 +0000
treeherdermozilla-central@c1c444858b32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1428258
milestone60.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 1428258 - 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"
@@ -1529,16 +1530,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:
@@ -1693,17 +1695,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
@@ -30,17 +30,17 @@ 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)
   : mOutputStream(aFilename, ofstream::binary)
 {
   WriteHeader(mOutputStream);
 }
 
 DrawEventRecorderFile::~DrawEventRecorderFile()
 {
   mOutputStream.close();
@@ -54,17 +54,17 @@ DrawEventRecorderFile::Flush()
 
 bool
 DrawEventRecorderFile::IsOpen()
 {
   return mOutputStream.is_open();
 }
 
 void
-DrawEventRecorderFile::OpenNew(const char *aFilename)
+DrawEventRecorderFile::OpenNew(const char_type* aFilename)
 {
   MOZ_ASSERT(!mOutputStream.is_open());
 
   mOutputStream.open(aFilename, ofstream::binary);
   WriteHeader(mOutputStream);
 }
 
 void
--- a/gfx/2d/DrawEventRecorder.h
+++ b/gfx/2d/DrawEventRecorder.h
@@ -5,18 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_DRAWEVENTRECORDER_H_
 #define MOZILLA_GFX_DRAWEVENTRECORDER_H_
 
 #include "2D.h"
 #include "RecordedEvent.h"
 #include "RecordingTypes.h"
-#include <ostream>
-#include <fstream>
+#include "mozilla/FStream.h"
 
 #include <unordered_set>
 #include <unordered_map>
 #include <functional>
 
 namespace mozilla {
 namespace gfx {
 
@@ -124,46 +123,47 @@ 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;
 
-  std::ofstream mOutputStream;
+  mozilla::OFStream mOutputStream;
 };
 
 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
@@ -1135,17 +1135,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. */
 
 // Some graphics settings are computed on the UI process and must be
 // communicated to content and GPU processes. gfxVars helps facilitate
 // this. Its function is similar to gfxPrefs, except rather than hold
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -104,23 +104,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->HumanReadablePath().get());
   return NS_OK;
 }
 
 } // end namespace layers
 } // end namespace mozilla
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -561,34 +561,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"
@@ -670,21 +679,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.
     {