diff options
author | Steve Block <steveblock@google.com> | 2011-05-06 11:45:16 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-05-12 13:44:10 +0100 |
commit | cad810f21b803229eb11403f9209855525a25d57 (patch) | |
tree | 29a6fd0279be608e0fe9ffe9841f722f0f4e4269 /Source/WebCore/platform/graphics/wince/SharedBitmap.h | |
parent | 121b0cf4517156d0ac5111caf9830c51b69bae8f (diff) | |
download | external_webkit-cad810f21b803229eb11403f9209855525a25d57.zip external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.gz external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.bz2 |
Merge WebKit at r75315: Initial merge by git.
Change-Id: I570314b346ce101c935ed22a626b48c2af266b84
Diffstat (limited to 'Source/WebCore/platform/graphics/wince/SharedBitmap.h')
-rw-r--r-- | Source/WebCore/platform/graphics/wince/SharedBitmap.h | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/Source/WebCore/platform/graphics/wince/SharedBitmap.h b/Source/WebCore/platform/graphics/wince/SharedBitmap.h new file mode 100644 index 0000000..82f5d54 --- /dev/null +++ b/Source/WebCore/platform/graphics/wince/SharedBitmap.h @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2007-2009 Torch Mobile, Inc. All rights reserved. + * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SharedBitmap_h +#define SharedBitmap_h + +#include "AffineTransform.h" +#include "BitmapInfo.h" +#include "ColorSpace.h" +#include "GraphicsTypes.h" +#include <wtf/PassOwnPtr.h> +#include <wtf/PassRefPtr.h> +#include <wtf/OwnArrayPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/Vector.h> +#include <wingdi.h> + +namespace WebCore { + +class FloatPoint; +class FloatRect; +class GraphicsContext; +class IntRect; +class IntSize; +class TransformationMatrix; + +class SharedBitmap: public RefCounted<SharedBitmap> { +public: + ~SharedBitmap(); + static PassRefPtr<SharedBitmap> create(const IntSize&, BitmapInfo::BitCount = BitmapInfo::BitCount32, bool initPixels = true); + static PassRefPtr<SharedBitmap> create(const Vector<unsigned>&, const IntSize&, bool hasAlpha = true); + + const BitmapInfo& bitmapInfo() const { return m_bmpInfo; } + void* bytes() { return m_pixels; } + const void* bytes() const { return m_pixels; } + unsigned width() const { return m_bmpInfo.width(); } + unsigned height() const { return m_bmpInfo.height(); } + unsigned validHeight() const { return m_validHeight; } + void setValidHeight(unsigned validHeight) { m_validHeight = validHeight; } + void resetPixels(bool black = false); + void clearPixels(const IntRect& r); + bool locked() const { return m_locked; } + void lock() { m_locked = true; } + void unlock() { m_locked = false; } + bool freeMemory(); + bool is16bit() const { return m_bmpInfo.is16bit(); } + bool is32bit() const { return m_bmpInfo.is32bit(); } + bool to16bit(); + bool hasAlpha() const { return m_hasAlpha; } + void setHasAlpha(bool alpha) { m_hasAlpha = alpha; } + bool ensureHandle(); + HBITMAP getHandle() { return m_hbitmap.get(); } + PassOwnPtr<HBITMAP> createHandle(void** pixels, BitmapInfo* bmpInfo, int h = -1, bool use16bit = true) const; + bool usesTransparentColor() const { return m_usesTransparentColor; } + COLORREF transparentColor() const { return m_transparentColor; } + void setTransparentColor(COLORREF c) + { + m_usesTransparentColor = true; + m_transparentColor = c; + } + bool canUseDIBits() const { return !hasAlpha() && !usesTransparentColor(); } + + PassOwnPtr<HBITMAP> clipBitmap(const IntRect& rect, bool useAlpha, BitmapInfo& bmpInfo, void*& pixels); + + PassRefPtr<SharedBitmap> clipBitmap(const IntRect& rect, bool useAlpha); + + void draw(GraphicsContext* ctxt, const IntRect& dstRect, const IntRect& srcRect, ColorSpace styleColorSpace, CompositeOperator compositeOp); + void drawPattern(GraphicsContext* ctxt, const FloatRect& tileRectIn, const AffineTransform& patternTransform, + const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect, const IntSize& origSourceSize); + void draw(HDC, const IntRect& dstRect, const IntRect& srcRect, CompositeOperator compositeOp); + void drawPattern(HDC, const AffineTransform&, const FloatRect& tileRectIn, const AffineTransform& patternTransform, + const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect, const IntSize& origSourceSize); + + class DCProvider { + public: + virtual HDC getDC(SharedBitmap*, unsigned*); + virtual void releaseDC(SharedBitmap*, HDC, unsigned); + }; + + static DCProvider* s_dcProvider; + + HDC getDC(unsigned* key1) { return s_dcProvider->getDC(this, key1); } + void releaseDC(HDC hdc, unsigned key1) { s_dcProvider->releaseDC(this, hdc, key1); } + + class DCHolder { + public: + DCHolder(SharedBitmap* bmp = 0) { setInternal(bmp); } + ~DCHolder() { clearInternal(); } + void set(SharedBitmap* bmp = 0) + { + clearInternal(); + setInternal(bmp); + } + HDC get() const { return m_hdc; } + private: + DCHolder& operator=(const DCHolder&); + DCHolder(const DCHolder&); + void clearInternal() + { + if (m_hdc) + m_bitmap->releaseDC(m_hdc, m_key); + } + void setInternal(SharedBitmap* bmp) + { + m_bitmap = bmp; + m_hdc = bmp ? bmp->getDC(&m_key) : 0; + } + SharedBitmap* m_bitmap; + HDC m_hdc; + unsigned m_key; + }; + +private: + SharedBitmap(const IntSize&, BitmapInfo::BitCount, bool initPixels); + BitmapInfo m_bmpInfo; + OwnPtr<HBITMAP> m_hbitmap; + void* m_pixels; + OwnArrayPtr<unsigned> m_pixelData; + COLORREF m_transparentColor; + int m_validHeight; + bool m_locked; + bool m_usesTransparentColor; + bool m_hasAlpha; +}; + +} // namespace WebCore + +#endif // SharedBitmap_h |