michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_READBACKMANAGERD3D10_H michael@0: #define GFX_READBACKMANAGERD3D10_H michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "nsTArray.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "gfxPoint.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: DWORD WINAPI StartTaskThread(void *aManager); michael@0: michael@0: struct ReadbackTask; michael@0: michael@0: class ReadbackManagerD3D10 MOZ_FINAL : public IUnknown michael@0: { michael@0: public: michael@0: ReadbackManagerD3D10(); michael@0: ~ReadbackManagerD3D10(); michael@0: michael@0: /** michael@0: * Tell the readback manager to post a readback task. michael@0: * michael@0: * @param aTexture D3D10_USAGE_STAGING texture that will contain the data that michael@0: * was readback. michael@0: * @param aUpdate ReadbackProcessor::Update object. This is a void pointer michael@0: * since we cannot forward declare a nested class, and do not michael@0: * export ReadbackProcessor.h michael@0: * @param aOrigin Origin of the aTexture surface in the ThebesLayer michael@0: * coordinate system. michael@0: */ michael@0: void PostTask(ID3D10Texture2D *aTexture, void *aUpdate, const gfxPoint &aOrigin); michael@0: michael@0: virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, michael@0: void **ppvObject); michael@0: virtual ULONG STDMETHODCALLTYPE AddRef(void); michael@0: virtual ULONG STDMETHODCALLTYPE Release(void); michael@0: michael@0: private: michael@0: friend DWORD WINAPI StartTaskThread(void *aManager); michael@0: michael@0: void ProcessTasks(); michael@0: michael@0: // The invariant maintained by |mTaskSemaphore| is that the readback thread michael@0: // will awaken from WaitForMultipleObjects() at least once per readback michael@0: // task enqueued by the main thread. Since the readback thread processes michael@0: // exactly one task per wakeup (with one exception), no tasks are lost. The michael@0: // exception is when the readback thread is shut down, which orphans the michael@0: // remaining tasks, on purpose. michael@0: HANDLE mTaskSemaphore; michael@0: // Event signaled when the task thread should shutdown michael@0: HANDLE mShutdownEvent; michael@0: // Handle to the task thread michael@0: HANDLE mTaskThread; michael@0: michael@0: // FiFo list of readback tasks that are to be executed. Access is synchronized michael@0: // by mTaskMutex. michael@0: CRITICAL_SECTION mTaskMutex; michael@0: nsTArray> mPendingReadbackTasks; michael@0: michael@0: ULONG mRefCnt; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* GFX_READBACKMANAGERD3D10_H */