Bug 1467358 - Make WrProgramBinaryDiskCache works on non-Windows r=nical
authorsotaro <sotaro.ikeda.g@gmail.com>
Wed, 13 Jun 2018 20:53:57 -0700
changeset 476738 947f74a553909b6649810ebaf01de4e821e560ff
parent 476737 6b55a54cf88c377f00013b7799f30f749ef059ba
child 476739 74487424ec36bf15f041e99dd57dd4c85052ebba
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1467358
milestone62.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 1467358 - Make WrProgramBinaryDiskCache works on non-Windows r=nical
gfx/webrender_bindings/src/program_cache.rs
--- a/gfx/webrender_bindings/src/program_cache.rs
+++ b/gfx/webrender_bindings/src/program_cache.rs
@@ -56,19 +56,30 @@ fn get_cache_path_from_prof_path(prof_pa
     let prof_path = OsString::from_wide(prof_path.as_ref());
     let mut cache_path = PathBuf::from(&prof_path);
     cache_path.push("shader-cache");
 
     Some(cache_path)
 }
 
 #[cfg(not(target_os="windows"))]
-fn get_cache_path_from_prof_path(_prof_path: &nsAString) -> Option<PathBuf> {
-    // Not supported yet.
-    None
+fn get_cache_path_from_prof_path(prof_path: &nsAString) -> Option<PathBuf> {
+    if prof_path.is_empty() {
+        // Empty means that we do not use disk cache.
+        return None;
+    }
+
+    use std::ffi::OsString;
+
+    let utf8 = String::from_utf16(prof_path.as_ref()).unwrap();
+    let prof_path = OsString::from(utf8);
+    let mut cache_path = PathBuf::from(&prof_path);
+    cache_path.push("shader-cache");
+
+    Some(cache_path)
 }
 
 struct WrProgramBinaryDiskCache {
     cache_path: Option<PathBuf>,
     program_count: u32,
     is_enabled: bool,
     workers: Arc<ThreadPool>,
 }
@@ -231,52 +242,40 @@ impl ProgramCacheObserver for WrProgramC
 
 
 pub struct WrProgramCache {
     program_cache: Rc<ProgramCache>,
     disk_cache: Option<Rc<RefCell<WrProgramBinaryDiskCache>>>,
 }
 
 impl WrProgramCache {
-    #[cfg(target_os = "windows")]
     pub fn new(prof_path: &nsAString, workers: &Arc<ThreadPool>) -> Self {
         let disk_cache = Rc::new(RefCell::new(WrProgramBinaryDiskCache::new(prof_path, workers)));
         let program_cache_observer = Box::new(WrProgramCacheObserver::new(Rc::clone(&disk_cache)));
         let program_cache = ProgramCache::new(Some(program_cache_observer));
 
         WrProgramCache {
             program_cache,
             disk_cache: Some(disk_cache),
         }
     }
 
-    #[cfg(not(target_os="windows"))]
-    pub fn new(_prof_path: &nsAString, _: &Arc<ThreadPool>) -> Self {
-        let program_cache = ProgramCache::new(None);
-
-        WrProgramCache {
-            program_cache,
-            disk_cache: None,
-        }
-    }
-
     pub fn rc_get(&self) -> &Rc<ProgramCache> {
         &self.program_cache
     }
 
     pub fn try_load_from_disk(&self) {
         if let Some(ref disk_cache) = self.disk_cache {
             disk_cache.borrow_mut().try_load_from_disk(&self.program_cache);
         } else {
             error!("Shader disk cache is not supported");
         }
     }
 }
 
-#[cfg(target_os = "windows")]
 pub fn remove_disk_cache(prof_path: &nsAString) -> Result<(), Error> {
     use std::fs::remove_dir_all;
     use std::time::{Instant};
 
     if let Some(cache_path) = get_cache_path_from_prof_path(prof_path) {
         if cache_path.exists() {
             let start = Instant::now();
 
@@ -284,15 +283,8 @@ pub fn remove_disk_cache(prof_path: &nsA
 
             let elapsed = start.elapsed();
             let elapsed_ms = (elapsed.as_secs() * 1_000) + (elapsed.subsec_nanos() / 1_000_000) as u64;
             info!("remove_disk_cache: {} ms", elapsed_ms);
         }
     }
     Ok(())
 }
-
-#[cfg(not(target_os="windows"))]
-pub fn remove_disk_cache(_prof_path: &nsAString) -> Result<(), Error> {
-    error!("Shader disk cache is not supported");
-    return Err(Error::new(ErrorKind::Other, "Not supported"))
-}
-