1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/SourceSurfaceD2D1.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 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_SOURCESURFACED2D1_H_ 1.10 +#define MOZILLA_GFX_SOURCESURFACED2D1_H_ 1.11 + 1.12 +#include "2D.h" 1.13 +#include "HelpersD2D.h" 1.14 +#include <vector> 1.15 +#include <d3d11.h> 1.16 +#include <d2d1_1.h> 1.17 + 1.18 +namespace mozilla { 1.19 +namespace gfx { 1.20 + 1.21 +class DrawTargetD2D1; 1.22 + 1.23 +class SourceSurfaceD2D1 : public SourceSurface 1.24 +{ 1.25 +public: 1.26 + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D1) 1.27 + SourceSurfaceD2D1(ID2D1Image* aImage, ID2D1DeviceContext *aDC, 1.28 + SurfaceFormat aFormat, const IntSize &aSize, 1.29 + DrawTargetD2D1 *aDT = nullptr); 1.30 + ~SourceSurfaceD2D1(); 1.31 + 1.32 + virtual SurfaceType GetType() const { return SurfaceType::D2D1_1_IMAGE; } 1.33 + virtual IntSize GetSize() const { return mSize; } 1.34 + virtual SurfaceFormat GetFormat() const { return mFormat; } 1.35 + virtual TemporaryRef<DataSourceSurface> GetDataSurface(); 1.36 + 1.37 + ID2D1Image *GetImage() { return mImage; } 1.38 + 1.39 + void EnsureIndependent() { if (!mDrawTarget) return; DrawTargetWillChange(); } 1.40 + 1.41 +private: 1.42 + friend class DrawTargetD2D1; 1.43 + 1.44 + void EnsureRealizedBitmap(); 1.45 + 1.46 + // This function is called by the draw target this texture belongs to when 1.47 + // it is about to be changed. The texture will be required to make a copy 1.48 + // of itself when this happens. 1.49 + void DrawTargetWillChange(); 1.50 + 1.51 + // This will mark the surface as no longer depending on its drawtarget, 1.52 + // this may happen on destruction or copying. 1.53 + void MarkIndependent(); 1.54 + 1.55 + RefPtr<ID2D1Image> mImage; 1.56 + // This may be null if we were created for a non-bitmap image and have not 1.57 + // had a reason yet to realize ourselves. 1.58 + RefPtr<ID2D1Bitmap1> mRealizedBitmap; 1.59 + RefPtr<ID2D1DeviceContext> mDC; 1.60 + 1.61 + SurfaceFormat mFormat; 1.62 + IntSize mSize; 1.63 + RefPtr<DrawTargetD2D1> mDrawTarget; 1.64 +}; 1.65 + 1.66 +class DataSourceSurfaceD2D1 : public DataSourceSurface 1.67 +{ 1.68 +public: 1.69 + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D1) 1.70 + DataSourceSurfaceD2D1(ID2D1Bitmap1 *aMappableBitmap, SurfaceFormat aFormat); 1.71 + ~DataSourceSurfaceD2D1(); 1.72 + 1.73 + virtual SurfaceType GetType() const { return SurfaceType::DATA; } 1.74 + virtual IntSize GetSize() const; 1.75 + virtual SurfaceFormat GetFormat() const { return mFormat; } 1.76 + virtual uint8_t *GetData(); 1.77 + virtual int32_t Stride(); 1.78 + virtual bool Map(MapType, MappedSurface *aMappedSurface); 1.79 + virtual void Unmap(); 1.80 + 1.81 +private: 1.82 + friend class SourceSurfaceD2DTarget; 1.83 + void EnsureMapped(); 1.84 + 1.85 + mutable RefPtr<ID2D1Bitmap1> mBitmap; 1.86 + SurfaceFormat mFormat; 1.87 + D2D1_MAPPED_RECT mMap; 1.88 + bool mMapped; 1.89 +}; 1.90 + 1.91 +} 1.92 +} 1.93 + 1.94 +#endif /* MOZILLA_GFX_SOURCESURFACED2D2TARGET_H_ */