gfx/2d/SourceSurfaceD2DTarget.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/SourceSurfaceD2DTarget.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     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_SOURCESURFACED2DTARGET_H_
    1.10 +#define MOZILLA_GFX_SOURCESURFACED2DTARGET_H_
    1.11 +
    1.12 +#include "2D.h"
    1.13 +#include "HelpersD2D.h"
    1.14 +#include <vector>
    1.15 +#include <d3d10_1.h>
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace gfx {
    1.19 +
    1.20 +class DrawTargetD2D;
    1.21 +
    1.22 +class SourceSurfaceD2DTarget : public SourceSurface
    1.23 +{
    1.24 +public:
    1.25 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2DTarget)
    1.26 +  SourceSurfaceD2DTarget(DrawTargetD2D* aDrawTarget, ID3D10Texture2D* aTexture,
    1.27 +                         SurfaceFormat aFormat);
    1.28 +  ~SourceSurfaceD2DTarget();
    1.29 +
    1.30 +  virtual SurfaceType GetType() const { return SurfaceType::D2D1_DRAWTARGET; }
    1.31 +  virtual IntSize GetSize() const;
    1.32 +  virtual SurfaceFormat GetFormat() const;
    1.33 +  virtual TemporaryRef<DataSourceSurface> GetDataSurface();
    1.34 +  virtual void *GetNativeSurface(NativeSurfaceType aType);
    1.35 +
    1.36 +  DrawTargetD2D* GetDT() { return mDrawTarget; }
    1.37 +  ID2D1Bitmap *GetBitmap(ID2D1RenderTarget *aRT);
    1.38 +
    1.39 +private:
    1.40 +  friend class DrawTargetD2D;
    1.41 +
    1.42 +  ID3D10ShaderResourceView *GetSRView();
    1.43 +
    1.44 +  // This function is called by the draw target this texture belongs to when
    1.45 +  // it is about to be changed. The texture will be required to make a copy
    1.46 +  // of itself when this happens.
    1.47 +  void DrawTargetWillChange();
    1.48 +
    1.49 +  // This will mark the surface as no longer depending on its drawtarget,
    1.50 +  // this may happen on destruction or copying.
    1.51 +  void MarkIndependent();
    1.52 +
    1.53 +  RefPtr<ID3D10ShaderResourceView> mSRView;
    1.54 +  RefPtr<ID2D1Bitmap> mBitmap;
    1.55 +  // Non-null if this is a "lazy copy" of the given draw target.
    1.56 +  // Null if we've made a copy. The target is not kept alive, otherwise we'd
    1.57 +  // have leaks since it might keep us alive. If the target is destroyed, it
    1.58 +  // will notify us.
    1.59 +  DrawTargetD2D* mDrawTarget;
    1.60 +  mutable RefPtr<ID3D10Texture2D> mTexture;
    1.61 +  SurfaceFormat mFormat;
    1.62 +  bool mOwnsCopy;
    1.63 +};
    1.64 +
    1.65 +class DataSourceSurfaceD2DTarget : public DataSourceSurface
    1.66 +{
    1.67 +public:
    1.68 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2DTarget)
    1.69 +  DataSourceSurfaceD2DTarget(SurfaceFormat aFormat);
    1.70 +  ~DataSourceSurfaceD2DTarget();
    1.71 +
    1.72 +  virtual SurfaceType GetType() const { return SurfaceType::DATA; }
    1.73 +  virtual IntSize GetSize() const;
    1.74 +  virtual SurfaceFormat GetFormat() const;
    1.75 +  virtual uint8_t *GetData();
    1.76 +  virtual int32_t Stride();
    1.77 +  virtual bool Map(MapType, MappedSurface *aMappedSurface);
    1.78 +  virtual void Unmap();
    1.79 +
    1.80 +private:
    1.81 +  friend class SourceSurfaceD2DTarget;
    1.82 +  void EnsureMapped();
    1.83 +
    1.84 +  mutable RefPtr<ID3D10Texture2D> mTexture;
    1.85 +  SurfaceFormat mFormat;
    1.86 +  D3D10_MAPPED_TEXTURE2D mMap;
    1.87 +  bool mMapped;
    1.88 +};
    1.89 +
    1.90 +}
    1.91 +}
    1.92 +
    1.93 +#endif /* MOZILLA_GFX_SOURCESURFACED2DTARGET_H_ */

mercurial