Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(933)

Unified Diff: sky/engine/bindings-dart/core/dart/DartStringCache.h

Issue 875013003: Import Dart bindings as of Blink r188698. This merely copies the files over and does not attach any… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/engine/bindings-dart/core/dart/DartStringCache.h
diff --git a/sky/engine/platform/graphics/GraphicsContextStateSaver.h b/sky/engine/bindings-dart/core/dart/DartStringCache.h
similarity index 56%
copy from sky/engine/platform/graphics/GraphicsContextStateSaver.h
copy to sky/engine/bindings-dart/core/dart/DartStringCache.h
index 0b35abe6a07ece3552a1802cc000830e45f18cfc..3ab2b869931e4760d5a60e65d7d64cfd6a05a385 100644
--- a/sky/engine/platform/graphics/GraphicsContextStateSaver.h
+++ b/sky/engine/bindings-dart/core/dart/DartStringCache.h
@@ -1,4 +1,5 @@
-// Copyright (C) 2013 Google Inc. All rights reserved.
+// Copyright 2012, Google Inc.
+// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -26,53 +27,49 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSCONTEXTSTATESAVER_H_
-#define SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSCONTEXTSTATESAVER_H_
+#ifndef DartStringCache_h
+#define DartStringCache_h
-#include "sky/engine/platform/PlatformExport.h"
-#include "sky/engine/platform/graphics/GraphicsContext.h"
+#include "wtf/HashMap.h"
+#include "wtf/RefPtr.h"
+#include "wtf/text/StringHash.h"
+#include "wtf/text/StringImpl.h"
+
+#include <dart_api.h>
namespace blink {
-class PLATFORM_EXPORT GraphicsContextStateSaver {
- WTF_MAKE_FAST_ALLOCATED;
+class DartStringCache {
public:
- GraphicsContextStateSaver(GraphicsContext& context, bool saveAndRestore = true)
- : m_context(context)
- , m_saveAndRestore(saveAndRestore)
- {
- if (m_saveAndRestore)
- m_context.save();
- }
+ DartStringCache();
- ~GraphicsContextStateSaver()
+ Dart_WeakPersistentHandle get(StringImpl* stringImpl, bool autoDartScope = true)
{
- if (m_saveAndRestore)
- m_context.restore();
- }
+ ASSERT(stringImpl);
- void save()
- {
- ASSERT(!m_saveAndRestore);
- m_context.save();
- m_saveAndRestore = true;
- }
+ if (m_lastStringImpl.get() == stringImpl)
+ return m_lastDartString;
- void restore()
- {
- ASSERT(m_saveAndRestore);
- m_context.restore();
- m_saveAndRestore = false;
+ return getSlow(stringImpl, autoDartScope);
}
- GraphicsContext* context() const { return &m_context; }
- bool saved() const { return m_saveAndRestore; }
+ void clearWeakHandles();
+
+ // FIXME: implement clearing on GC.
private:
- GraphicsContext& m_context;
- bool m_saveAndRestore;
+ Dart_WeakPersistentHandle getSlow(StringImpl*, bool autoDartScope);
+ static void handleFinalizer(void*, Dart_WeakPersistentHandle, void* peer);
+
+ typedef HashMap<StringImpl*, Dart_WeakPersistentHandle> StringCache;
+ StringCache m_stringCache;
+ Dart_WeakPersistentHandle m_lastDartString;
+ // Note: RefPtr is a must as we cache by StringImpl* equality, not identity
+ // hence lastStringImpl might be not a key of the cache (in sense of identity)
+ // and hence it's not refed on addition.
+ RefPtr<StringImpl> m_lastStringImpl;
};
-} // namespace blink
+}
-#endif // SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSCONTEXTSTATESAVER_H_
+#endif
« no previous file with comments | « sky/engine/bindings-dart/core/dart/DartService.cpp ('k') | sky/engine/bindings-dart/core/dart/DartStringCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698