gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     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 "MacIOSurfaceTextureClientOGL.h"
    1.10 +#include "mozilla/gfx/MacIOSurface.h"
    1.11 +
    1.12 +namespace mozilla {
    1.13 +namespace layers {
    1.14 +
    1.15 +MacIOSurfaceTextureClientOGL::MacIOSurfaceTextureClientOGL(TextureFlags aFlags)
    1.16 +  : TextureClient(aFlags)
    1.17 +  , mIsLocked(false)
    1.18 +{}
    1.19 +
    1.20 +MacIOSurfaceTextureClientOGL::~MacIOSurfaceTextureClientOGL()
    1.21 +{}
    1.22 +
    1.23 +void
    1.24 +MacIOSurfaceTextureClientOGL::InitWith(MacIOSurface* aSurface)
    1.25 +{
    1.26 +  MOZ_ASSERT(IsValid());
    1.27 +  MOZ_ASSERT(!IsAllocated());
    1.28 +  mSurface = aSurface;
    1.29 +}
    1.30 +
    1.31 +bool
    1.32 +MacIOSurfaceTextureClientOGL::Lock(OpenMode aMode)
    1.33 +{
    1.34 +  MOZ_ASSERT(!mIsLocked);
    1.35 +  mIsLocked = true;
    1.36 +  return IsValid() && IsAllocated();
    1.37 +}
    1.38 +
    1.39 +void
    1.40 +MacIOSurfaceTextureClientOGL::Unlock()
    1.41 +{
    1.42 +  MOZ_ASSERT(mIsLocked);
    1.43 +  mIsLocked = false;
    1.44 +}
    1.45 +
    1.46 +bool
    1.47 +MacIOSurfaceTextureClientOGL::IsLocked() const
    1.48 +{
    1.49 +  return mIsLocked;
    1.50 +}
    1.51 +
    1.52 +bool
    1.53 +MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
    1.54 +{
    1.55 +  MOZ_ASSERT(IsValid());
    1.56 +  if (!IsAllocated()) {
    1.57 +    return false;
    1.58 +  }
    1.59 +  aOutDescriptor = SurfaceDescriptorMacIOSurface(mSurface->GetIOSurfaceID(),
    1.60 +                                                 mSurface->GetContentsScaleFactor(),
    1.61 +                                                 mSurface->HasAlpha());
    1.62 +  return true;
    1.63 +}
    1.64 +
    1.65 +gfx::IntSize
    1.66 +MacIOSurfaceTextureClientOGL::GetSize() const
    1.67 +{
    1.68 +  return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight());
    1.69 +}
    1.70 +
    1.71 +class MacIOSurfaceTextureClientData : public TextureClientData
    1.72 +{
    1.73 +public:
    1.74 +  MacIOSurfaceTextureClientData(MacIOSurface* aSurface)
    1.75 +    : mSurface(aSurface)
    1.76 +  {}
    1.77 +
    1.78 +  virtual void DeallocateSharedData(ISurfaceAllocator*) MOZ_OVERRIDE
    1.79 +  {
    1.80 +    mSurface = nullptr;
    1.81 +  }
    1.82 +
    1.83 +private:
    1.84 +  RefPtr<MacIOSurface> mSurface;
    1.85 +};
    1.86 +
    1.87 +TextureClientData*
    1.88 +MacIOSurfaceTextureClientOGL::DropTextureData()
    1.89 +{
    1.90 +  TextureClientData* data = new MacIOSurfaceTextureClientData(mSurface);
    1.91 +  mSurface = nullptr;
    1.92 +  MarkInvalid();
    1.93 +  return data;
    1.94 +}
    1.95 +
    1.96 +}
    1.97 +}

mercurial