/src/mozilla-central/gfx/layers/TextureSourceProvider.cpp
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 | | #include "mozilla/layers/TextureSourceProvider.h" |
8 | | #include "mozilla/layers/TextureHost.h" |
9 | | #include "mozilla/layers/PTextureParent.h" |
10 | | #ifdef XP_DARWIN |
11 | | #include "mozilla/layers/TextureSync.h" |
12 | | #endif |
13 | | |
14 | | namespace mozilla { |
15 | | namespace layers { |
16 | | |
17 | | TextureSourceProvider::~TextureSourceProvider() |
18 | 0 | { |
19 | 0 | ReadUnlockTextures(); |
20 | 0 | } |
21 | | |
22 | | void |
23 | | TextureSourceProvider::ReadUnlockTextures() |
24 | 0 | { |
25 | | #ifdef XP_DARWIN |
26 | | nsClassHashtable<nsUint32HashKey, nsTArray<uint64_t>> texturesIdsToUnlockByPid; |
27 | | for (auto& texture : mUnlockAfterComposition) { |
28 | | auto bufferTexture = texture->AsBufferTextureHost(); |
29 | | if (bufferTexture && bufferTexture->IsDirectMap()) { |
30 | | texture->ReadUnlock(); |
31 | | auto actor = texture->GetIPDLActor(); |
32 | | if (actor) { |
33 | | base::ProcessId pid = actor->OtherPid(); |
34 | | nsTArray<uint64_t>* textureIds = texturesIdsToUnlockByPid.LookupOrAdd(pid); |
35 | | textureIds->AppendElement(TextureHost::GetTextureSerial(actor)); |
36 | | } |
37 | | } else { |
38 | | texture->ReadUnlock(); |
39 | | } |
40 | | } |
41 | | for (auto it = texturesIdsToUnlockByPid.ConstIter(); !it.Done(); it.Next()) { |
42 | | TextureSync::SetTexturesUnlocked(it.Key(), *it.UserData()); |
43 | | } |
44 | | #else |
45 | 0 | for (auto& texture : mUnlockAfterComposition) { |
46 | 0 | texture->ReadUnlock(); |
47 | 0 | } |
48 | 0 | #endif |
49 | 0 | mReferenceUntilAfterComposition.Clear(); |
50 | 0 | mUnlockAfterComposition.Clear(); |
51 | 0 | } |
52 | | |
53 | | void |
54 | | TextureSourceProvider::UnlockAfterComposition(TextureHost* aTexture) |
55 | 0 | { |
56 | 0 | mUnlockAfterComposition.AppendElement(aTexture); |
57 | 0 | } |
58 | | |
59 | | void |
60 | | TextureSourceProvider::ReferenceUntilAfterComposition(DataTextureSource* aTextureSource) |
61 | 0 | { |
62 | 0 | mReferenceUntilAfterComposition.AppendElement(aTextureSource); |
63 | 0 | } |
64 | | |
65 | | bool |
66 | | TextureSourceProvider::NotifyNotUsedAfterComposition(TextureHost* aTextureHost) |
67 | 0 | { |
68 | 0 | mNotifyNotUsedAfterComposition.AppendElement(aTextureHost); |
69 | 0 |
|
70 | 0 | // If Compositor holds many TextureHosts without compositing, |
71 | 0 | // the TextureHosts should be flushed to reduce memory consumption. |
72 | 0 | const int thresholdCount = 5; |
73 | 0 | const double thresholdSec = 2.0f; |
74 | 0 | if (mNotifyNotUsedAfterComposition.Length() > thresholdCount) { |
75 | 0 | TimeStamp lastCompositionEndTime = GetLastCompositionEndTime(); |
76 | 0 | TimeDuration duration = lastCompositionEndTime ? TimeStamp::Now() - lastCompositionEndTime : TimeDuration(); |
77 | 0 | // Check if we could flush |
78 | 0 | if (duration.ToSeconds() > thresholdSec) { |
79 | 0 | FlushPendingNotifyNotUsed(); |
80 | 0 | } |
81 | 0 | } |
82 | 0 | return true; |
83 | 0 | } |
84 | | |
85 | | void |
86 | | TextureSourceProvider::FlushPendingNotifyNotUsed() |
87 | 0 | { |
88 | 0 | for (auto& textureHost : mNotifyNotUsedAfterComposition) { |
89 | 0 | textureHost->CallNotifyNotUsed(); |
90 | 0 | } |
91 | 0 | mNotifyNotUsedAfterComposition.Clear(); |
92 | 0 | } |
93 | | |
94 | | void |
95 | | TextureSourceProvider::Destroy() |
96 | 0 | { |
97 | 0 | ReadUnlockTextures(); |
98 | 0 | FlushPendingNotifyNotUsed(); |
99 | 0 | } |
100 | | |
101 | | } // namespace layers |
102 | | } // namespace mozilla |