-
Notifications
You must be signed in to change notification settings - Fork 566
Add CefV8BackingStore for off-thread ArrayBuffer data population #4079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
72b3437
3821412
281062b
1696a9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ | |
| #include "include/cef_frame.h" | ||
| #include "include/cef_task.h" | ||
|
|
||
| class CefV8BackingStore; | ||
| class CefV8Exception; | ||
| class CefV8Handler; | ||
| class CefV8StackFrame; | ||
|
|
@@ -425,6 +426,59 @@ class CefV8ArrayBufferReleaseCallback : public virtual CefBaseRefCounted { | |
| virtual void ReleaseBuffer(void* buffer) = 0; | ||
| }; | ||
|
|
||
| #if CEF_API_ADDED(CEF_NEXT) | ||
| /// | ||
| /// Class representing a V8 ArrayBuffer backing store. The backing store holds | ||
| /// the memory that backs an ArrayBuffer. It must be created on a thread with a | ||
| /// valid V8 isolate (renderer main thread or WebWorker thread). Once created, | ||
| /// the Data() pointer can be safely read/written from any thread. This allows | ||
| /// expensive operations like memcpy to be performed on a background thread | ||
| /// before creating the ArrayBuffer on the V8 thread. | ||
| /// | ||
| /// The backing store is consumed when passed to | ||
| /// CefV8Value::CreateArrayBufferFromBackingStore(), after which IsValid() | ||
| /// returns false. | ||
| /// | ||
| /*--cef(source=library,no_debugct_check,added=next)--*/ | ||
| class CefV8BackingStore : public virtual CefBaseRefCounted { | ||
| public: | ||
| /// | ||
| /// Create a new backing store with allocated memory of |byte_length| bytes. | ||
| /// The memory is uninitialized. This method must be called on a thread with a | ||
| /// valid V8 isolate. The returned object can safely be passed to other | ||
| /// threads. Returns nullptr on failure. | ||
| /// | ||
| /*--cef()--*/ | ||
| static CefRefPtr<CefV8BackingStore> Create(size_t byte_length); | ||
|
|
||
| /// | ||
| /// Returns a pointer to the allocated memory, or nullptr if the backing | ||
| /// store has been consumed or is otherwise invalid. The pointer is safe to | ||
| /// read/write from any thread. The caller must ensure all writes are complete | ||
| /// before passing this object to CreateArrayBufferFromBackingStore(). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a warning here about not keeping a pointer reference after passing to CreateArrayBufferFromBackingStore?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a warning to the Data() doc comment: "Pointers obtained from this method should not be retained after calling CreateArrayBufferFromBackingStore(), as the memory will then be owned by the ArrayBuffer and subject to V8 garbage collection." |
||
| /// Pointers obtained from this method should not be retained after calling | ||
| /// CreateArrayBufferFromBackingStore(), as the memory will then be owned by | ||
| /// the ArrayBuffer and subject to V8 garbage collection. | ||
| /// | ||
| /*--cef()--*/ | ||
| virtual void* Data() = 0; | ||
|
|
||
| /// | ||
| /// Returns the size of the allocated memory in bytes, or 0 if the backing | ||
| /// store has been consumed. | ||
| /// | ||
| /*--cef()--*/ | ||
| virtual size_t ByteLength() = 0; | ||
|
|
||
| /// | ||
| /// Returns true if this backing store has not yet been consumed by | ||
| /// CreateArrayBufferFromBackingStore(). | ||
| /// | ||
| /*--cef()--*/ | ||
| virtual bool IsValid() = 0; | ||
| }; | ||
| #endif | ||
|
|
||
| /// | ||
| /// Class representing a V8 value handle. V8 handles can only be accessed from | ||
| /// the thread on which they are created. Valid threads for creating a V8 handle | ||
|
|
@@ -540,6 +594,22 @@ class CefV8Value : public virtual CefBaseRefCounted { | |
| static CefRefPtr<CefV8Value> CreateArrayBufferWithCopy(void* buffer, | ||
| size_t length); | ||
|
|
||
| #if CEF_API_ADDED(CEF_NEXT) | ||
| /// | ||
| /// Create a new CefV8Value object of type ArrayBuffer from a backing store | ||
| /// previously created with CefV8BackingStore::Create(). This is a zero-copy | ||
| /// operation — the ArrayBuffer uses the memory already allocated by the | ||
| /// backing store. The backing store is consumed and becomes invalid after | ||
| /// this call. This method should only be called from within the scope of a | ||
| /// CefRenderProcessHandler, CefV8Handler or CefV8Accessor callback, or in | ||
| /// combination with calling Enter() and Exit() on a stored CefV8Context | ||
| /// reference. | ||
| /// | ||
| /*--cef(added=next)--*/ | ||
| static CefRefPtr<CefV8Value> CreateArrayBufferFromBackingStore( | ||
| CefRefPtr<CefV8BackingStore> backing_store); | ||
| #endif | ||
|
|
||
| /// | ||
| /// Create a new CefV8Value object of type function. This method should only | ||
| /// be called from within the scope of a CefRenderProcessHandler, CefV8Handler | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New classes/methods need to be protected by
#if CEF_API_ADDED(CEF_NEXT)with appropriate/*--cef(added=next)--*/metadata. See https://bitbucket.org/chromiumembedded/cef/wiki/ApiVersioning.md#markdown-header-usage-in-pull-requestsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed that