1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/SourceSurfaceD2D.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_SOURCESURFACED2D_H_ 1.10 +#define MOZILLA_GFX_SOURCESURFACED2D_H_ 1.11 + 1.12 +#include "2D.h" 1.13 +#include "HelpersD2D.h" 1.14 +#include <vector> 1.15 + 1.16 +namespace mozilla { 1.17 +namespace gfx { 1.18 + 1.19 +class DataSourceSurfaceD2D; 1.20 + 1.21 +class SourceSurfaceD2D : public SourceSurface 1.22 +{ 1.23 +public: 1.24 + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D) 1.25 + SourceSurfaceD2D(); 1.26 + ~SourceSurfaceD2D(); 1.27 + 1.28 + virtual SurfaceType GetType() const { return SurfaceType::D2D1_BITMAP; } 1.29 + virtual IntSize GetSize() const; 1.30 + virtual SurfaceFormat GetFormat() const; 1.31 + virtual bool IsValid() const; 1.32 + 1.33 + virtual TemporaryRef<DataSourceSurface> GetDataSurface(); 1.34 + 1.35 + ID2D1Bitmap *GetBitmap() { return mBitmap; } 1.36 + 1.37 + bool InitFromData(unsigned char *aData, 1.38 + const IntSize &aSize, 1.39 + int32_t aStride, 1.40 + SurfaceFormat aFormat, 1.41 + ID2D1RenderTarget *aRT); 1.42 + bool InitFromTexture(ID3D10Texture2D *aTexture, 1.43 + SurfaceFormat aFormat, 1.44 + ID2D1RenderTarget *aRT); 1.45 +private: 1.46 + friend class DrawTargetD2D; 1.47 + friend class DataSourceSurfaceD2D; 1.48 + 1.49 + uint32_t GetByteSize() const; 1.50 + 1.51 + RefPtr<ID2D1Bitmap> mBitmap; 1.52 + // We need to keep this pointer here to check surface validity. 1.53 + RefPtr<ID3D10Device> mDevice; 1.54 + SurfaceFormat mFormat; 1.55 + IntSize mSize; 1.56 +}; 1.57 + 1.58 + 1.59 +class DataSourceSurfaceD2D : public DataSourceSurface 1.60 +{ 1.61 +public: 1.62 + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D) 1.63 + DataSourceSurfaceD2D(SourceSurfaceD2D* aSourceSurface); 1.64 + virtual ~DataSourceSurfaceD2D(); 1.65 + 1.66 + virtual unsigned char* GetData(); 1.67 + virtual int32_t Stride(); 1.68 + virtual IntSize GetSize() const; 1.69 + virtual SurfaceFormat GetFormat() const; 1.70 + virtual bool Map(MapType, MappedSurface *aMappedSurface); 1.71 + virtual void Unmap(); 1.72 + 1.73 + bool IsValid() 1.74 + { 1.75 + return mTexture; 1.76 + } 1.77 + 1.78 +private: 1.79 + void EnsureMappedTexture(); 1.80 + 1.81 + RefPtr<ID3D10Texture2D> mTexture; 1.82 + 1.83 + D3D10_MAPPED_TEXTURE2D mData; 1.84 + 1.85 + SurfaceFormat mFormat; 1.86 + IntSize mSize; 1.87 + bool mMapped; 1.88 +}; 1.89 + 1.90 +} 1.91 +} 1.92 + 1.93 +#endif /* MOZILLA_GFX_SOURCESURFACED2D_H_ */