/src/mozilla-central/gfx/layers/client/TextureClientSharedSurface.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 "TextureClientSharedSurface.h" |
8 | | |
9 | | #include "GLContext.h" |
10 | | #include "mozilla/gfx/2D.h" |
11 | | #include "mozilla/gfx/Logging.h" // for gfxDebug |
12 | | #include "mozilla/layers/ISurfaceAllocator.h" |
13 | | #include "mozilla/Unused.h" |
14 | | #include "nsThreadUtils.h" |
15 | | #include "SharedSurface.h" |
16 | | |
17 | | using namespace mozilla::gl; |
18 | | |
19 | | namespace mozilla { |
20 | | namespace layers { |
21 | | |
22 | | |
23 | | SharedSurfaceTextureData::SharedSurfaceTextureData(UniquePtr<gl::SharedSurface> surf) |
24 | | : mSurf(std::move(surf)) |
25 | 0 | {} |
26 | | |
27 | | SharedSurfaceTextureData::~SharedSurfaceTextureData() |
28 | 0 | {} |
29 | | |
30 | | void |
31 | | SharedSurfaceTextureData::Deallocate(LayersIPCChannel*) |
32 | 0 | {} |
33 | | |
34 | | void |
35 | | SharedSurfaceTextureData::FillInfo(TextureData::Info& aInfo) const |
36 | 0 | { |
37 | 0 | aInfo.size = mSurf->mSize; |
38 | 0 | aInfo.format = gfx::SurfaceFormat::UNKNOWN; |
39 | 0 | aInfo.hasIntermediateBuffer = false; |
40 | 0 | aInfo.hasSynchronization = false; |
41 | 0 | aInfo.supportsMoz2D = false; |
42 | 0 | aInfo.canExposeMappedData = false; |
43 | 0 | } |
44 | | |
45 | | bool |
46 | | SharedSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) |
47 | 0 | { |
48 | 0 | return mSurf->ToSurfaceDescriptor(&aOutDescriptor); |
49 | 0 | } |
50 | | |
51 | | |
52 | | SharedSurfaceTextureClient::SharedSurfaceTextureClient(SharedSurfaceTextureData* aData, |
53 | | TextureFlags aFlags, |
54 | | LayersIPCChannel* aAllocator) |
55 | | : TextureClient(aData, aFlags, aAllocator) |
56 | 0 | { |
57 | 0 | mWorkaroundAnnoyingSharedSurfaceLifetimeIssues = true; |
58 | 0 | } |
59 | | |
60 | | already_AddRefed<SharedSurfaceTextureClient> |
61 | | SharedSurfaceTextureClient::Create(UniquePtr<gl::SharedSurface> surf, gl::SurfaceFactory* factory, |
62 | | LayersIPCChannel* aAllocator, TextureFlags aFlags) |
63 | 0 | { |
64 | 0 | if (!surf) { |
65 | 0 | return nullptr; |
66 | 0 | } |
67 | 0 | TextureFlags flags = aFlags | TextureFlags::RECYCLE | surf->GetTextureFlags(); |
68 | 0 | SharedSurfaceTextureData* data = new SharedSurfaceTextureData(std::move(surf)); |
69 | 0 | return MakeAndAddRef<SharedSurfaceTextureClient>(data, flags, aAllocator); |
70 | 0 | } |
71 | | |
72 | | SharedSurfaceTextureClient::~SharedSurfaceTextureClient() |
73 | 0 | { |
74 | 0 | // XXX - Things break when using the proper destruction handshake with |
75 | 0 | // SharedSurfaceTextureData because the TextureData outlives its gl |
76 | 0 | // context. Having a strong reference to the gl context creates a cycle. |
77 | 0 | // This needs to be fixed in a better way, though, because deleting |
78 | 0 | // the TextureData here can race with the compositor and cause flashing. |
79 | 0 | TextureData* data = mData; |
80 | 0 | mData = nullptr; |
81 | 0 |
|
82 | 0 | Destroy(); |
83 | 0 |
|
84 | 0 | if (data) { |
85 | 0 | // Destroy mData right away without doing the proper deallocation handshake, |
86 | 0 | // because SharedSurface depends on things that may not outlive the texture's |
87 | 0 | // destructor so we can't wait until we know the compositor isn't using the |
88 | 0 | // texture anymore. |
89 | 0 | // It goes without saying that this is really bad and we should fix the bugs |
90 | 0 | // that block doing the right thing such as bug 1224199 sooner rather than |
91 | 0 | // later. |
92 | 0 | delete data; |
93 | 0 | } |
94 | 0 | } |
95 | | |
96 | | } // namespace layers |
97 | | } // namespace mozilla |