Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef MOZILLA_LAYERS_PAINTTHREAD_H
8
#define MOZILLA_LAYERS_PAINTTHREAD_H
9
10
#include "base/platform_thread.h"
11
#include "mozilla/RefPtr.h"
12
#include "mozilla/StaticPtr.h"
13
#include "mozilla/UniquePtr.h"
14
#include "mozilla/layers/TextureClient.h"
15
#include "RotatedBuffer.h"
16
#include "nsThreadUtils.h"
17
18
class nsIThreadPool;
19
20
namespace mozilla {
21
namespace gfx {
22
class DrawTarget;
23
class DrawTargetCapture;
24
}; // namespace gfx
25
26
namespace layers {
27
28
// A paint task contains a description of a rasterization work to be done
29
// on the paint thread or paint worker pool.
30
//
31
// More specifically it contains:
32
// 1. A capture command list of drawing commands
33
// 2. A destination draw target to replay the draw commands upon
34
// 3. A list of dependent texture clients that must be kept alive for the
35
// task's duration, and then destroyed on the main thread
36
class PaintTask {
37
public:
38
PaintTask() = default;
39
~PaintTask() = default;
40
41
void DropTextureClients();
42
43
RefPtr<gfx::DrawTarget> mTarget;
44
RefPtr<gfx::DrawTargetCapture> mCapture;
45
AutoTArray<RefPtr<TextureClient>, 4> mClients;
46
};
47
48
class CompositorBridgeChild;
49
50
class PaintThread final {
51
friend void DestroyPaintThread(UniquePtr<PaintThread>&& aPaintThread);
52
53
public:
54
static void Start();
55
static void Shutdown();
56
static PaintThread* Get();
57
58
// Helper for asserts.
59
static bool IsOnPaintThread();
60
bool IsOnPaintWorkerThread();
61
62
// This allows external users to run code on the paint thread.
63
void Dispatch(RefPtr<Runnable>& aRunnable);
64
65
// This allows the paint thread to dynamically toggle between a paint worker
66
// thread pool used with tiling, and a single paint thread used with rotated
67
// buffer.
68
void UpdateRenderMode();
69
70
// Must be called on the main thread. Queues an async paint
71
// task to be completed on the paint thread.
72
void QueuePaintTask(UniquePtr<PaintTask>&& aTask);
73
74
// Must be called on the main thread. Signifies that the current
75
// layer tree transaction has been finished and any async paints
76
// for it have been queued on the paint thread. This MUST be called
77
// at the end of a layer transaction as it will be used to do an optional
78
// texture sync and then unblock the main thread if it is waiting to paint
79
// a new frame.
80
void QueueEndLayerTransaction(SyncObjectClient* aSyncObject);
81
82
// Sync Runnables need threads to be ref counted,
83
// But this thread lives through the whole process.
84
// We're only temporarily using sync runnables so
85
// Override release/addref but don't do anything.
86
void Release();
87
void AddRef();
88
89
static int32_t CalculatePaintWorkerCount();
90
91
private:
92
PaintThread();
93
94
bool Init();
95
void ShutdownOnPaintThread();
96
void InitOnPaintThread();
97
void InitPaintWorkers();
98
99
void AsyncPaintTask(CompositorBridgeChild* aBridge, PaintTask* aTask);
100
void AsyncEndLayerTransaction(CompositorBridgeChild* aBridge);
101
102
static StaticAutoPtr<PaintThread> sSingleton;
103
static StaticRefPtr<nsIThread> sThread;
104
static PlatformThreadId sThreadId;
105
106
RefPtr<nsIThreadPool> mPaintWorkers;
107
};
108
109
} // namespace layers
110
} // namespace mozilla
111
112
#endif