|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef GFX_READBACKMANAGERD3D10_H |
|
7 #define GFX_READBACKMANAGERD3D10_H |
|
8 |
|
9 #include <windows.h> |
|
10 #include <d3d10_1.h> |
|
11 |
|
12 #include "nsTArray.h" |
|
13 #include "nsAutoPtr.h" |
|
14 #include "gfxPoint.h" |
|
15 |
|
16 namespace mozilla { |
|
17 namespace layers { |
|
18 |
|
19 DWORD WINAPI StartTaskThread(void *aManager); |
|
20 |
|
21 struct ReadbackTask; |
|
22 |
|
23 class ReadbackManagerD3D10 MOZ_FINAL : public IUnknown |
|
24 { |
|
25 public: |
|
26 ReadbackManagerD3D10(); |
|
27 ~ReadbackManagerD3D10(); |
|
28 |
|
29 /** |
|
30 * Tell the readback manager to post a readback task. |
|
31 * |
|
32 * @param aTexture D3D10_USAGE_STAGING texture that will contain the data that |
|
33 * was readback. |
|
34 * @param aUpdate ReadbackProcessor::Update object. This is a void pointer |
|
35 * since we cannot forward declare a nested class, and do not |
|
36 * export ReadbackProcessor.h |
|
37 * @param aOrigin Origin of the aTexture surface in the ThebesLayer |
|
38 * coordinate system. |
|
39 */ |
|
40 void PostTask(ID3D10Texture2D *aTexture, void *aUpdate, const gfxPoint &aOrigin); |
|
41 |
|
42 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, |
|
43 void **ppvObject); |
|
44 virtual ULONG STDMETHODCALLTYPE AddRef(void); |
|
45 virtual ULONG STDMETHODCALLTYPE Release(void); |
|
46 |
|
47 private: |
|
48 friend DWORD WINAPI StartTaskThread(void *aManager); |
|
49 |
|
50 void ProcessTasks(); |
|
51 |
|
52 // The invariant maintained by |mTaskSemaphore| is that the readback thread |
|
53 // will awaken from WaitForMultipleObjects() at least once per readback |
|
54 // task enqueued by the main thread. Since the readback thread processes |
|
55 // exactly one task per wakeup (with one exception), no tasks are lost. The |
|
56 // exception is when the readback thread is shut down, which orphans the |
|
57 // remaining tasks, on purpose. |
|
58 HANDLE mTaskSemaphore; |
|
59 // Event signaled when the task thread should shutdown |
|
60 HANDLE mShutdownEvent; |
|
61 // Handle to the task thread |
|
62 HANDLE mTaskThread; |
|
63 |
|
64 // FiFo list of readback tasks that are to be executed. Access is synchronized |
|
65 // by mTaskMutex. |
|
66 CRITICAL_SECTION mTaskMutex; |
|
67 nsTArray<nsAutoPtr<ReadbackTask>> mPendingReadbackTasks; |
|
68 |
|
69 ULONG mRefCnt; |
|
70 }; |
|
71 |
|
72 } |
|
73 } |
|
74 |
|
75 #endif /* GFX_READBACKMANAGERD3D10_H */ |