2011-06-24 21:41:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
#include "SourceSurfaceD2D.h"
|
2012-06-21 01:41:16 +04:00
|
|
|
#include "DrawTargetD2D.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
#include "Logging.h"
|
2012-06-21 01:41:16 +04:00
|
|
|
#include "Tools.h"
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
SourceSurfaceD2D::SourceSurfaceD2D()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceSurfaceD2D::~SourceSurfaceD2D()
|
|
|
|
{
|
2012-06-21 01:41:16 +04:00
|
|
|
if (mBitmap) {
|
|
|
|
DrawTargetD2D::mVRAMUsageSS -= GetByteSize();
|
|
|
|
}
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
IntSize
|
|
|
|
SourceSurfaceD2D::GetSize() const
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceFormat
|
|
|
|
SourceSurfaceD2D::GetFormat() const
|
|
|
|
{
|
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
|
2012-07-28 04:33:08 +04:00
|
|
|
bool
|
|
|
|
SourceSurfaceD2D::IsValid() const
|
|
|
|
{
|
|
|
|
return mDevice == Factory::GetDirect3D10Device();
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
TemporaryRef<DataSourceSurface>
|
|
|
|
SourceSurfaceD2D::GetDataSurface()
|
|
|
|
{
|
2012-08-15 20:51:33 +04:00
|
|
|
return NULL;
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SourceSurfaceD2D::InitFromData(unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat,
|
|
|
|
ID2D1RenderTarget *aRT)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
mSize = aSize;
|
|
|
|
|
|
|
|
if ((uint32_t)aSize.width > aRT->GetMaximumBitmapSize() ||
|
|
|
|
(uint32_t)aSize.height > aRT->GetMaximumBitmapSize()) {
|
2012-05-21 19:27:30 +04:00
|
|
|
gfxDebug() << "Bitmap does not fit in texture.";
|
|
|
|
return false;
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
D2D1_BITMAP_PROPERTIES props =
|
|
|
|
D2D1::BitmapProperties(D2D1::PixelFormat(DXGIFormat(aFormat), AlphaMode(aFormat)));
|
|
|
|
hr = aRT->CreateBitmap(D2DIntSize(aSize), aData, aStride, props, byRef(mBitmap));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create D2D Bitmap for data. Code: " << hr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-21 01:41:16 +04:00
|
|
|
DrawTargetD2D::mVRAMUsageSS += GetByteSize();
|
2012-07-28 04:33:08 +04:00
|
|
|
mDevice = Factory::GetDirect3D10Device();
|
2012-06-21 01:41:16 +04:00
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SourceSurfaceD2D::InitFromTexture(ID3D10Texture2D *aTexture,
|
|
|
|
SurfaceFormat aFormat,
|
|
|
|
ID2D1RenderTarget *aRT)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
RefPtr<IDXGISurface> surf;
|
|
|
|
|
|
|
|
hr = aTexture->QueryInterface((IDXGISurface**)&surf);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to QI texture to surface. Code: " << hr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_TEXTURE2D_DESC desc;
|
|
|
|
aTexture->GetDesc(&desc);
|
|
|
|
|
|
|
|
mSize = IntSize(desc.Width, desc.Height);
|
|
|
|
mFormat = aFormat;
|
|
|
|
|
|
|
|
D2D1_BITMAP_PROPERTIES props =
|
|
|
|
D2D1::BitmapProperties(D2D1::PixelFormat(DXGIFormat(aFormat), AlphaMode(aFormat)));
|
|
|
|
hr = aRT->CreateSharedBitmap(IID_IDXGISurface, surf, &props, byRef(mBitmap));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxWarning() << "Failed to create SharedBitmap. Code: " << hr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-28 04:33:08 +04:00
|
|
|
aTexture->GetDevice(byRef(mDevice));
|
2012-06-21 01:41:16 +04:00
|
|
|
DrawTargetD2D::mVRAMUsageSS += GetByteSize();
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-21 01:41:16 +04:00
|
|
|
uint32_t
|
|
|
|
SourceSurfaceD2D::GetByteSize() const
|
|
|
|
{
|
|
|
|
return mSize.width * mSize.height * BytesPerPixel(mFormat);
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
}
|