Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "GLContext.h" // for GLContext, etc |
michael@0 | 7 | #include "SurfaceStream.h" |
michael@0 | 8 | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
michael@0 | 9 | #include "mozilla/layers/ISurfaceAllocator.h" |
michael@0 | 10 | #include "mozilla/layers/TextureClientOGL.h" |
michael@0 | 11 | #include "nsSize.h" // for nsIntSize |
michael@0 | 12 | |
michael@0 | 13 | using namespace mozilla::gl; |
michael@0 | 14 | |
michael@0 | 15 | namespace mozilla { |
michael@0 | 16 | namespace layers { |
michael@0 | 17 | |
michael@0 | 18 | class CompositableForwarder; |
michael@0 | 19 | |
michael@0 | 20 | SharedTextureClientOGL::SharedTextureClientOGL(TextureFlags aFlags) |
michael@0 | 21 | : TextureClient(aFlags) |
michael@0 | 22 | , mHandle(0) |
michael@0 | 23 | , mInverted(false) |
michael@0 | 24 | { |
michael@0 | 25 | // SharedTextureClient is always owned externally. |
michael@0 | 26 | mFlags |= TEXTURE_DEALLOCATE_CLIENT; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | SharedTextureClientOGL::~SharedTextureClientOGL() |
michael@0 | 30 | { |
michael@0 | 31 | // the shared data is owned externally. |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | bool |
michael@0 | 36 | SharedTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) |
michael@0 | 37 | { |
michael@0 | 38 | MOZ_ASSERT(IsValid()); |
michael@0 | 39 | if (!IsAllocated()) { |
michael@0 | 40 | return false; |
michael@0 | 41 | } |
michael@0 | 42 | aOutDescriptor = SharedTextureDescriptor(mShareType, mHandle, mSize, mInverted); |
michael@0 | 43 | return true; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | void |
michael@0 | 47 | SharedTextureClientOGL::InitWith(gl::SharedTextureHandle aHandle, |
michael@0 | 48 | gfx::IntSize aSize, |
michael@0 | 49 | gl::SharedTextureShareType aShareType, |
michael@0 | 50 | bool aInverted) |
michael@0 | 51 | { |
michael@0 | 52 | MOZ_ASSERT(IsValid()); |
michael@0 | 53 | MOZ_ASSERT(!IsAllocated()); |
michael@0 | 54 | mHandle = aHandle; |
michael@0 | 55 | mSize = aSize; |
michael@0 | 56 | mShareType = aShareType; |
michael@0 | 57 | mInverted = aInverted; |
michael@0 | 58 | if (mInverted) { |
michael@0 | 59 | AddFlags(TEXTURE_NEEDS_Y_FLIP); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | bool |
michael@0 | 64 | SharedTextureClientOGL::Lock(OpenMode mode) |
michael@0 | 65 | { |
michael@0 | 66 | MOZ_ASSERT(!mIsLocked); |
michael@0 | 67 | if (!IsValid() || !IsAllocated()) { |
michael@0 | 68 | return false; |
michael@0 | 69 | } |
michael@0 | 70 | mIsLocked = true; |
michael@0 | 71 | return true; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | void |
michael@0 | 75 | SharedTextureClientOGL::Unlock() |
michael@0 | 76 | { |
michael@0 | 77 | MOZ_ASSERT(mIsLocked); |
michael@0 | 78 | mIsLocked = false; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | bool |
michael@0 | 82 | SharedTextureClientOGL::IsAllocated() const |
michael@0 | 83 | { |
michael@0 | 84 | return mHandle != 0; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | StreamTextureClientOGL::StreamTextureClientOGL(TextureFlags aFlags) |
michael@0 | 88 | : TextureClient(aFlags) |
michael@0 | 89 | , mIsLocked(false) |
michael@0 | 90 | { |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | StreamTextureClientOGL::~StreamTextureClientOGL() |
michael@0 | 94 | { |
michael@0 | 95 | // the data is owned externally. |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | bool |
michael@0 | 99 | StreamTextureClientOGL::Lock(OpenMode mode) |
michael@0 | 100 | { |
michael@0 | 101 | MOZ_ASSERT(!mIsLocked); |
michael@0 | 102 | if (!IsValid() || !IsAllocated()) { |
michael@0 | 103 | return false; |
michael@0 | 104 | } |
michael@0 | 105 | mIsLocked = true; |
michael@0 | 106 | return true; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | void |
michael@0 | 110 | StreamTextureClientOGL::Unlock() |
michael@0 | 111 | { |
michael@0 | 112 | MOZ_ASSERT(mIsLocked); |
michael@0 | 113 | mIsLocked = false; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | bool |
michael@0 | 117 | StreamTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) |
michael@0 | 118 | { |
michael@0 | 119 | if (!IsAllocated()) { |
michael@0 | 120 | return false; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | gfx::SurfaceStreamHandle handle = mStream->GetShareHandle(); |
michael@0 | 124 | aOutDescriptor = SurfaceStreamDescriptor(handle, false); |
michael@0 | 125 | return true; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | void |
michael@0 | 129 | StreamTextureClientOGL::InitWith(gfx::SurfaceStream* aStream) |
michael@0 | 130 | { |
michael@0 | 131 | MOZ_ASSERT(!IsAllocated()); |
michael@0 | 132 | mStream = aStream; |
michael@0 | 133 | mGL = mStream->GLContext(); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | bool |
michael@0 | 137 | StreamTextureClientOGL::IsAllocated() const |
michael@0 | 138 | { |
michael@0 | 139 | return mStream != 0; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | |
michael@0 | 143 | } // namespace |
michael@0 | 144 | } // namespace |