move SK_MMAP_SUPPORT into SkPreConfig, so we can know about its availability
throughout the code.
Add SkData::NewFromMMap() help factory.
Refactor (now gone) SkMMapStream into SkStream::NewFromFile() factory
Review URL: https://codereview.chromium.org/12919013
git-svn-id: http://skia.googlecode.com/svn/trunk/include@8200 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkData.h b/core/SkData.h
index 9a0cb09..6b09119 100644
--- a/core/SkData.h
+++ b/core/SkData.h
@@ -89,6 +89,12 @@
static SkData* NewFromMalloc(const void* data, size_t length);
/**
+ * Create a new dataref from a pointer allocated by mmap. The Data object
+ * will handle calling munmap().
+ */
+ static SkData* NewFromMMap(const void* data, size_t length);
+
+ /**
* Create a new dataref using a subset of the data in the specified
* src dataref.
*/
diff --git a/core/SkMMapStream.h b/core/SkMMapStream.h
deleted file mode 100644
index a3b35f2..0000000
--- a/core/SkMMapStream.h
+++ /dev/null
@@ -1,30 +0,0 @@
-
-/*
- * Copyright 2008 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkMMapStream_DEFINED
-#define SkMMapStream_DEFINED
-
-#include "SkStream.h"
-
-class SkMMAPStream : public SkMemoryStream {
-public:
- SkMMAPStream(const char filename[]);
- virtual ~SkMMAPStream();
-
- virtual void setMemory(const void* data, size_t length, bool);
-private:
- void* fAddr;
- size_t fSize;
-
- void closeMMap();
-
- typedef SkMemoryStream INHERITED;
-};
-
-#endif
diff --git a/core/SkPreConfig.h b/core/SkPreConfig.h
index 2246b63..11cb223 100644
--- a/core/SkPreConfig.h
+++ b/core/SkPreConfig.h
@@ -108,6 +108,17 @@
//////////////////////////////////////////////////////////////////////
+#ifndef SK_MMAP_SUPPORT
+ #ifdef SK_BUILD_FOR_WIN32
+ // by default, if we're windows, we assume we don't have mmap
+ #define SK_MMAP_SUPPORT 0
+ #else
+ #define SK_MMAP_SUPPORT 1
+ #endif
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
/**
* SK_CPU_SSE_LEVEL
*
diff --git a/core/SkStream.h b/core/SkStream.h
index 7e3c1a3..eb0cd47 100644
--- a/core/SkStream.h
+++ b/core/SkStream.h
@@ -17,6 +17,13 @@
class SK_API SkStream : public SkRefCnt {
public:
+ /**
+ * Attempts to open the specified file, and return a stream to it (using
+ * mmap if available). On success, the caller must call unref() on the
+ * returned object. On failure, returns NULL.
+ */
+ static SkStream* NewFromFile(const char path[]);
+
SK_DECLARE_INST_COUNT(SkStream)
/** Called to rewind to the beginning of the stream. If this cannot be