Skip to content

Commit

Permalink
Add an API for posting external tasks to compositor thread. Contribut…
Browse files Browse the repository at this point in the history
…es to JB#30162.

This is a generic API similar to already available EmbedLiteApp::PostTask.
The main difference is, as the function name suggests,
EmbedLiteApp::PostCompostiorTask schedules the callback function to be
executed on gecko compositor thread. In case the compositor was not yet
created by the engine the function returns nullptr.
  • Loading branch information
tworaz committed Jun 26, 2015
1 parent 872de3f commit 699e260
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions embedding/embedlite/EmbedLiteApp.cpp
Expand Up @@ -13,6 +13,7 @@
#include "base/message_loop.h" // for MessageLoop

#include "mozilla/embedlite/EmbedLiteAPI.h"
#include "mozilla/layers/CompositorParent.h"

#include "EmbedLiteUILoop.h"
#include "EmbedLiteSubThread.h"
Expand Down Expand Up @@ -118,6 +119,27 @@ EmbedLiteApp::PostTask(EMBEDTaskCallback callback, void* userData, int timeout)
return (void*)newTask;
}

void*
EmbedLiteApp::PostCompositorTask(EMBEDTaskCallback callback, void* userData, int timeout)
{
if (!mozilla::layers::CompositorParent::CompositorLoop()) {
// Can't post compositor task if gecko compositor thread has not been initialized, yet.
return nullptr;
}

CancelableTask* newTask = NewRunnableFunction(callback, userData);
MessageLoop* compositorLoop = mozilla::layers::CompositorParent::CompositorLoop();
MOZ_ASSERT(compositorLoop);

if (timeout) {
compositorLoop->PostDelayedTask(FROM_HERE, newTask, timeout);
} else {
compositorLoop->PostTask(FROM_HERE, newTask);
}

return (void*)newTask;
}

void
EmbedLiteApp::CancelTask(void* aTask)
{
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/EmbedLiteApp.h
Expand Up @@ -80,6 +80,7 @@ class EmbedLiteApp

// Delayed post task helper for delayed functions call in main thread
virtual void* PostTask(EMBEDTaskCallback callback, void* userData, int timeout = 0);
virtual void* PostCompositorTask(EMBEDTaskCallback callback, void* userData, int timeout = 0);
virtual void CancelTask(void* aTask);

// Setup profile path for embedding, or null if embedding supposed to be profile-less
Expand Down

0 comments on commit 699e260

Please sign in to comment.