Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/PaintThread.h
Line
Count
Source (jump to first uncovered line)
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
};
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
0
  PaintTask() {}
39
0
  ~PaintTask() {}
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
{
52
  friend void DestroyPaintThread(UniquePtr<PaintThread>&& aPaintThread);
53
54
public:
55
  static void Start();
56
  static void Shutdown();
57
  static PaintThread* Get();
58
59
  // Helper for asserts.
60
  static bool IsOnPaintThread();
61
  bool IsOnPaintWorkerThread();
62
63
  // This allows external users to run code on the paint thread.
64
  void Dispatch(RefPtr<Runnable>& aRunnable);
65
66
  // This allows the paint thread to dynamically toggle between a paint worker
67
  // thread pool used with tiling, and a single paint thread used with rotated
68
  // buffer.
69
  void UpdateRenderMode();
70
71
  // Must be called on the main thread. Queues an async paint
72
  // task to be completed on the paint thread.
73
  void QueuePaintTask(UniquePtr<PaintTask>&& aTask);
74
75
  // Must be called on the main thread. Signifies that the current
76
  // layer tree transaction has been finished and any async paints
77
  // for it have been queued on the paint thread. This MUST be called
78
  // at the end of a layer transaction as it will be used to do an optional
79
  // texture sync and then unblock the main thread if it is waiting to paint
80
  // a new frame.
81
  void QueueEndLayerTransaction(SyncObjectClient* aSyncObject);
82
83
  // Sync Runnables need threads to be ref counted,
84
  // But this thread lives through the whole process.
85
  // We're only temporarily using sync runnables so
86
  // Override release/addref but don't do anything.
87
  void Release();
88
  void AddRef();
89
90
  static int32_t CalculatePaintWorkerCount();
91
92
private:
93
  PaintThread();
94
95
  bool Init();
96
  void ShutdownOnPaintThread();
97
  void InitOnPaintThread();
98
  void InitPaintWorkers();
99
100
  void AsyncPaintTask(CompositorBridgeChild* aBridge,
101
                      PaintTask* aTask);
102
  void AsyncEndLayerTransaction(CompositorBridgeChild* aBridge);
103
104
  static StaticAutoPtr<PaintThread> sSingleton;
105
  static StaticRefPtr<nsIThread> sThread;
106
  static PlatformThreadId sThreadId;
107
108
  RefPtr<nsIThreadPool> mPaintWorkers;
109
};
110
111
} // namespace layers
112
} // namespace mozilla
113
114
#endif