gecko-dev/gfx/thebes/gfxWindowsSurface.cpp

170 строки
5.2 KiB
C++
Исходник Обычный вид История

2005-04-06 05:54:26 +04:00
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/. */
2005-04-06 05:54:26 +04:00
2005-04-07 23:12:19 +04:00
#include "gfxWindowsSurface.h"
#include "gfxContext.h"
#include "gfxPlatform.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/HelpersCairo.h"
#include "mozilla/gfx/Logging.h"
#include "cairo.h"
#include "cairo-win32.h"
#include "nsString.h"
gfxWindowsSurface::gfxWindowsSurface(HDC dc, uint32_t flags) :
mOwnsDC(false), mDC(dc), mWnd(nullptr)
2005-04-06 05:54:26 +04:00
{
InitWithDC(flags);
2005-08-20 09:36:47 +04:00
}
gfxWindowsSurface::gfxWindowsSurface(IDirect3DSurface9 *surface, uint32_t flags) :
mOwnsDC(false), mDC(0), mWnd(nullptr)
{
cairo_surface_t *surf = cairo_win32_surface_create_with_d3dsurface9(surface);
Init(surf);
}
void
gfxWindowsSurface::MakeInvalid(mozilla::gfx::IntSize& size)
{
size = mozilla::gfx::IntSize(-1, -1);
}
gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize, gfxImageFormat imageFormat) :
mOwnsDC(false), mWnd(nullptr)
{
mozilla::gfx::IntSize size(realSize);
if (!mozilla::gfx::Factory::CheckSurfaceSize(size))
MakeInvalid(size);
cairo_format_t cformat = GfxFormatToCairoFormat(imageFormat);
cairo_surface_t *surf =
cairo_win32_surface_create_with_dib(cformat, size.width, size.height);
Init(surf);
if (CairoStatus() == CAIRO_STATUS_SUCCESS) {
mDC = cairo_win32_surface_get_dc(CairoSurface());
RecordMemoryUsed(size.width * size.height * 4 + sizeof(gfxWindowsSurface));
} else {
mDC = nullptr;
}
}
gfxWindowsSurface::gfxWindowsSurface(cairo_surface_t *csurf) :
mOwnsDC(false), mWnd(nullptr)
{
if (cairo_surface_status(csurf) == 0)
mDC = cairo_win32_surface_get_dc(csurf);
else
mDC = nullptr;
MOZ_ASSERT(cairo_surface_get_type(csurf) != CAIRO_SURFACE_TYPE_WIN32_PRINTING);
Init(csurf, true);
}
void
gfxWindowsSurface::InitWithDC(uint32_t flags)
{
if (flags & FLAG_IS_TRANSPARENT) {
Init(cairo_win32_surface_create_with_alpha(mDC));
} else {
Init(cairo_win32_surface_create(mDC));
}
}
already_AddRefed<gfxASurface>
gfxWindowsSurface::CreateSimilarSurface(gfxContentType aContent,
const mozilla::gfx::IntSize& aSize)
{
if (!mSurface || !mSurfaceValid) {
return nullptr;
}
cairo_surface_t *surface;
if (GetContentType() == gfxContentType::COLOR_ALPHA) {
// When creating a similar surface to a transparent surface, ensure
// the new surface uses a DIB. cairo_surface_create_similar won't
// use a DIB for a gfxContentType::COLOR surface if this surface doesn't
// have a DIB (e.g. if we're a transparent window surface). But
// we need a DIB to perform well if the new surface is composited into
// a surface that's the result of create_similar(gfxContentType::COLOR_ALPHA)
// (e.g. a backbuffer for the window) --- that new surface *would*
// have a DIB.
gfxImageFormat gformat =
gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
cairo_format_t cformat = GfxFormatToCairoFormat(gformat);
surface = cairo_win32_surface_create_with_dib(cformat, aSize.width,
aSize.height);
} else {
surface =
cairo_surface_create_similar(mSurface, (cairo_content_t)(int)aContent,
aSize.width, aSize.height);
}
if (cairo_surface_status(surface)) {
cairo_surface_destroy(surface);
return nullptr;
}
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<gfxASurface> result = Wrap(surface, aSize);
cairo_surface_destroy(surface);
return result.forget();
}
2005-04-07 23:12:19 +04:00
gfxWindowsSurface::~gfxWindowsSurface()
2005-04-06 05:54:26 +04:00
{
if (mOwnsDC) {
if (mWnd)
::ReleaseDC(mWnd, mDC);
else
::DeleteDC(mDC);
}
2005-04-06 05:54:26 +04:00
}
2006-02-01 08:21:59 +03:00
HDC
gfxWindowsSurface::GetDC()
{
return cairo_win32_surface_get_dc (CairoSurface());
}
already_AddRefed<gfxImageSurface>
gfxWindowsSurface::GetAsImageSurface()
{
if (!mSurfaceValid) {
NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?");
return nullptr;
}
NS_ASSERTION(CairoSurface() != nullptr, "CairoSurface() shouldn't be nullptr when mSurfaceValid is TRUE!");
cairo_surface_t *isurf = cairo_win32_surface_get_image(CairoSurface());
if (!isurf)
return nullptr;
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<gfxImageSurface> result = gfxASurface::Wrap(isurf).downcast<gfxImageSurface>();
result->SetOpaqueRect(GetOpaqueRect());
return result.forget();
}
const mozilla::gfx::IntSize
gfxWindowsSurface::GetSize() const
{
if (!mSurfaceValid) {
NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?");
return mozilla::gfx::IntSize(-1, -1);
}
NS_ASSERTION(mSurface != nullptr, "CairoSurface() shouldn't be nullptr when mSurfaceValid is TRUE!");
return mozilla::gfx::IntSize(cairo_win32_surface_get_width(mSurface),
cairo_win32_surface_get_height(mSurface));
}