gfx/layers/opengl/TextureClientOGL.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/opengl/TextureClientOGL.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     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 +#ifndef MOZILLA_GFX_TEXTURECLIENTOGL_H
    1.10 +#define MOZILLA_GFX_TEXTURECLIENTOGL_H
    1.11 +
    1.12 +#include "GLContextTypes.h"             // for SharedTextureHandle, etc
    1.13 +#include "gfxTypes.h"
    1.14 +#include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
    1.15 +#include "mozilla/gfx/Point.h"          // for IntSize
    1.16 +#include "mozilla/layers/CompositorTypes.h"
    1.17 +#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
    1.18 +#include "mozilla/layers/TextureClient.h"  // for TextureClient, etc
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace gfx {
    1.22 +class SurfaceStream;
    1.23 +}
    1.24 +}
    1.25 +
    1.26 +namespace mozilla {
    1.27 +namespace layers {
    1.28 +
    1.29 +class CompositableForwarder;
    1.30 +
    1.31 +/**
    1.32 + * A TextureClient implementation to share TextureMemory that is already
    1.33 + * on the GPU, for the OpenGL backend.
    1.34 + */
    1.35 +class SharedTextureClientOGL : public TextureClient
    1.36 +{
    1.37 +public:
    1.38 +  SharedTextureClientOGL(TextureFlags aFlags);
    1.39 +
    1.40 +  ~SharedTextureClientOGL();
    1.41 +
    1.42 +  virtual bool IsAllocated() const MOZ_OVERRIDE;
    1.43 +
    1.44 +  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
    1.45 +
    1.46 +  virtual bool Lock(OpenMode mode) MOZ_OVERRIDE;
    1.47 +
    1.48 +  virtual void Unlock() MOZ_OVERRIDE;
    1.49 +
    1.50 +  virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
    1.51 +
    1.52 +  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
    1.53 +
    1.54 +  void InitWith(gl::SharedTextureHandle aHandle,
    1.55 +                gfx::IntSize aSize,
    1.56 +                gl::SharedTextureShareType aShareType,
    1.57 +                bool aInverted = false);
    1.58 +
    1.59 +  virtual gfx::IntSize GetSize() const { return mSize; }
    1.60 +
    1.61 +  virtual TextureClientData* DropTextureData() MOZ_OVERRIDE
    1.62 +  {
    1.63 +    // XXX - right now the code paths using this are managing the shared texture
    1.64 +    // data, although they should use a TextureClientData for this to ensure that
    1.65 +    // the destruction sequence is race-free.
    1.66 +    MarkInvalid();
    1.67 +    return nullptr;
    1.68 +  }
    1.69 +
    1.70 +  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
    1.71 +  {
    1.72 +    return gfx::SurfaceFormat::UNKNOWN;
    1.73 +  }
    1.74 +
    1.75 +  virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
    1.76 +  {
    1.77 +    return false;
    1.78 +  }
    1.79 +
    1.80 +protected:
    1.81 +  gl::SharedTextureHandle mHandle;
    1.82 +  gfx::IntSize mSize;
    1.83 +  gl::SharedTextureShareType mShareType;
    1.84 +  bool mInverted;
    1.85 +  bool mIsLocked;
    1.86 +};
    1.87 +
    1.88 +/**
    1.89 + * A TextureClient implementation to share SurfaceStream.
    1.90 + */
    1.91 +class StreamTextureClientOGL : public TextureClient
    1.92 +{
    1.93 +public:
    1.94 +  StreamTextureClientOGL(TextureFlags aFlags);
    1.95 +
    1.96 +  ~StreamTextureClientOGL();
    1.97 +
    1.98 +  virtual bool IsAllocated() const MOZ_OVERRIDE;
    1.99 +
   1.100 +  virtual bool Lock(OpenMode mode) MOZ_OVERRIDE;
   1.101 +
   1.102 +  virtual void Unlock() MOZ_OVERRIDE;
   1.103 +
   1.104 +  virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
   1.105 +
   1.106 +  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
   1.107 +
   1.108 +  virtual TextureClientData* DropTextureData() MOZ_OVERRIDE { return nullptr; }
   1.109 +
   1.110 +  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
   1.111 +
   1.112 +  void InitWith(gfx::SurfaceStream* aStream);
   1.113 +
   1.114 +  virtual gfx::IntSize GetSize() const { return gfx::IntSize(); }
   1.115 +
   1.116 +  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
   1.117 +  {
   1.118 +    return gfx::SurfaceFormat::UNKNOWN;
   1.119 +  }
   1.120 +
   1.121 +  virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) MOZ_OVERRIDE
   1.122 +  {
   1.123 +    return false;
   1.124 +  }
   1.125 +
   1.126 +protected:
   1.127 +  bool mIsLocked;
   1.128 +  RefPtr<gfx::SurfaceStream> mStream;
   1.129 +  RefPtr<gl::GLContext> mGL;
   1.130 +};
   1.131 +
   1.132 +} // namespace
   1.133 +} // namespace
   1.134 +
   1.135 +#endif

mercurial