gfx/layers/opengl/TextureClientOGL.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/opengl/TextureClientOGL.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,144 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "GLContext.h"                  // for GLContext, etc
    1.10 +#include "SurfaceStream.h"
    1.11 +#include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
    1.12 +#include "mozilla/layers/ISurfaceAllocator.h"
    1.13 +#include "mozilla/layers/TextureClientOGL.h"
    1.14 +#include "nsSize.h"                     // for nsIntSize
    1.15 +
    1.16 +using namespace mozilla::gl;
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace layers {
    1.20 +
    1.21 +class CompositableForwarder;
    1.22 +
    1.23 +SharedTextureClientOGL::SharedTextureClientOGL(TextureFlags aFlags)
    1.24 +  : TextureClient(aFlags)
    1.25 +  , mHandle(0)
    1.26 +  , mInverted(false)
    1.27 +{
    1.28 +  // SharedTextureClient is always owned externally.
    1.29 +  mFlags |= TEXTURE_DEALLOCATE_CLIENT;
    1.30 +}
    1.31 +
    1.32 +SharedTextureClientOGL::~SharedTextureClientOGL()
    1.33 +{
    1.34 +  // the shared data is owned externally.
    1.35 +}
    1.36 +
    1.37 +
    1.38 +bool
    1.39 +SharedTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
    1.40 +{
    1.41 +  MOZ_ASSERT(IsValid());
    1.42 +  if (!IsAllocated()) {
    1.43 +    return false;
    1.44 +  }
    1.45 +  aOutDescriptor = SharedTextureDescriptor(mShareType, mHandle, mSize, mInverted);
    1.46 +  return true;
    1.47 +}
    1.48 +
    1.49 +void
    1.50 +SharedTextureClientOGL::InitWith(gl::SharedTextureHandle aHandle,
    1.51 +                                 gfx::IntSize aSize,
    1.52 +                                 gl::SharedTextureShareType aShareType,
    1.53 +                                 bool aInverted)
    1.54 +{
    1.55 +  MOZ_ASSERT(IsValid());
    1.56 +  MOZ_ASSERT(!IsAllocated());
    1.57 +  mHandle = aHandle;
    1.58 +  mSize = aSize;
    1.59 +  mShareType = aShareType;
    1.60 +  mInverted = aInverted;
    1.61 +  if (mInverted) {
    1.62 +    AddFlags(TEXTURE_NEEDS_Y_FLIP);
    1.63 +  }
    1.64 +}
    1.65 +
    1.66 +bool
    1.67 +SharedTextureClientOGL::Lock(OpenMode mode)
    1.68 +{
    1.69 +  MOZ_ASSERT(!mIsLocked);
    1.70 +  if (!IsValid() || !IsAllocated()) {
    1.71 +    return false;
    1.72 +  }
    1.73 +  mIsLocked = true;
    1.74 +  return true;
    1.75 +}
    1.76 +
    1.77 +void
    1.78 +SharedTextureClientOGL::Unlock()
    1.79 +{
    1.80 +  MOZ_ASSERT(mIsLocked);
    1.81 +  mIsLocked = false;
    1.82 +}
    1.83 +
    1.84 +bool
    1.85 +SharedTextureClientOGL::IsAllocated() const
    1.86 +{
    1.87 +  return mHandle != 0;
    1.88 +}
    1.89 +
    1.90 +StreamTextureClientOGL::StreamTextureClientOGL(TextureFlags aFlags)
    1.91 +  : TextureClient(aFlags)
    1.92 +  , mIsLocked(false)
    1.93 +{
    1.94 +}
    1.95 +
    1.96 +StreamTextureClientOGL::~StreamTextureClientOGL()
    1.97 +{
    1.98 +  // the data is owned externally.
    1.99 +}
   1.100 +
   1.101 +bool
   1.102 +StreamTextureClientOGL::Lock(OpenMode mode)
   1.103 +{
   1.104 +  MOZ_ASSERT(!mIsLocked);
   1.105 +  if (!IsValid() || !IsAllocated()) {
   1.106 +    return false;
   1.107 +  }
   1.108 +  mIsLocked = true;
   1.109 +  return true;
   1.110 +}
   1.111 +
   1.112 +void
   1.113 +StreamTextureClientOGL::Unlock()
   1.114 +{
   1.115 +  MOZ_ASSERT(mIsLocked);
   1.116 +  mIsLocked = false;
   1.117 +}
   1.118 +
   1.119 +bool
   1.120 +StreamTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
   1.121 +{
   1.122 +  if (!IsAllocated()) {
   1.123 +    return false;
   1.124 +  }
   1.125 +
   1.126 +  gfx::SurfaceStreamHandle handle = mStream->GetShareHandle();
   1.127 +  aOutDescriptor = SurfaceStreamDescriptor(handle, false);
   1.128 +  return true;
   1.129 +}
   1.130 +
   1.131 +void
   1.132 +StreamTextureClientOGL::InitWith(gfx::SurfaceStream* aStream)
   1.133 +{
   1.134 +  MOZ_ASSERT(!IsAllocated());
   1.135 +  mStream = aStream;
   1.136 +  mGL = mStream->GLContext();
   1.137 +}
   1.138 +
   1.139 +bool
   1.140 +StreamTextureClientOGL::IsAllocated() const
   1.141 +{
   1.142 +  return mStream != 0;
   1.143 +}
   1.144 +
   1.145 +
   1.146 +} // namespace
   1.147 +} // namespace

mercurial