diff options
Diffstat (limited to 'skia/ext/bitmap_platform_device_win.cc')
-rw-r--r-- | skia/ext/bitmap_platform_device_win.cc | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc index ecd609f..646692d 100644 --- a/skia/ext/bitmap_platform_device_win.cc +++ b/skia/ext/bitmap_platform_device_win.cc @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <windows.h> +#include <psapi.h> + #include "skia/ext/bitmap_platform_device_win.h" #include "third_party/skia/include/core/SkMatrix.h" @@ -42,9 +45,9 @@ bool Constrain(int available_size, int* position, int *size) { } // namespace -class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData : public SkRefCnt { +class BitmapPlatformDevice::BitmapPlatformDeviceData : public SkRefCnt { public: - explicit BitmapPlatformDeviceWinData(HBITMAP hbitmap); + explicit BitmapPlatformDeviceData(HBITMAP hbitmap); // Create/destroy hdc_, which is the memory DC for our bitmap data. HDC GetBitmapDC(); @@ -85,14 +88,14 @@ class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData : public SkRefCnt { SkRegion clip_region_; private: - virtual ~BitmapPlatformDeviceWinData(); + virtual ~BitmapPlatformDeviceData(); // Copy & assign are not supported. - BitmapPlatformDeviceWinData(const BitmapPlatformDeviceWinData&); - BitmapPlatformDeviceWinData& operator=(const BitmapPlatformDeviceWinData&); + BitmapPlatformDeviceData(const BitmapPlatformDeviceData&); + BitmapPlatformDeviceData& operator=(const BitmapPlatformDeviceData&); }; -BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::BitmapPlatformDeviceWinData( +BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData( HBITMAP hbitmap) : hbitmap_(hbitmap), hdc_(NULL), @@ -108,7 +111,7 @@ BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::BitmapPlatformDeviceWinDat transform_.reset(); } -BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::~BitmapPlatformDeviceWinData() { +BitmapPlatformDevice::BitmapPlatformDeviceData::~BitmapPlatformDeviceData() { if (hdc_) ReleaseBitmapDC(); @@ -116,7 +119,7 @@ BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::~BitmapPlatformDeviceWinDa DeleteObject(hbitmap_); } -HDC BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::GetBitmapDC() { +HDC BitmapPlatformDevice::BitmapPlatformDeviceData::GetBitmapDC() { if (!hdc_) { hdc_ = CreateCompatibleDC(NULL); InitializeDC(hdc_); @@ -131,19 +134,19 @@ HDC BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::GetBitmapDC() { return hdc_; } -void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::ReleaseBitmapDC() { +void BitmapPlatformDevice::BitmapPlatformDeviceData::ReleaseBitmapDC() { SkASSERT(hdc_); DeleteDC(hdc_); hdc_ = NULL; } -bool BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::IsBitmapDCCreated() +bool BitmapPlatformDevice::BitmapPlatformDeviceData::IsBitmapDCCreated() const { return hdc_ != NULL; } -void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::SetMatrixClip( +void BitmapPlatformDevice::BitmapPlatformDeviceData::SetMatrixClip( const SkMatrix& transform, const SkRegion& region) { transform_ = transform; @@ -151,7 +154,7 @@ void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::SetMatrixClip( config_dirty_ = true; } -void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::LoadConfig() { +void BitmapPlatformDevice::BitmapPlatformDeviceData::LoadConfig() { if (!config_dirty_ || !hdc_) return; // Nothing to do. config_dirty_ = false; @@ -166,7 +169,7 @@ void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::LoadConfig() { // that we can create the pixel data before calling the constructor. This is // required so that we can call the base class' constructor with the pixel // data. -BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create( +BitmapPlatformDevice* BitmapPlatformDevice::create( HDC screen_dc, int width, int height, @@ -219,16 +222,28 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create( // The device object will take ownership of the HBITMAP. The initial refcount // of the data object will be 1, which is what the constructor expects. - return new BitmapPlatformDeviceWin(new BitmapPlatformDeviceWinData(hbitmap), - bitmap); + return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), + bitmap); +} + +// static +BitmapPlatformDevice* BitmapPlatformDevice::create(int width, + int height, + bool is_opaque, + HANDLE shared_section) { + HDC screen_dc = GetDC(NULL); + BitmapPlatformDevice* device = BitmapPlatformDevice::create( + screen_dc, width, height, is_opaque, shared_section); + ReleaseDC(NULL, screen_dc); + return device; } // The device will own the HBITMAP, which corresponds to also owning the pixel // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. -BitmapPlatformDeviceWin::BitmapPlatformDeviceWin( - BitmapPlatformDeviceWinData* data, +BitmapPlatformDevice::BitmapPlatformDevice( + BitmapPlatformDeviceData* data, const SkBitmap& bitmap) - : PlatformDeviceWin(bitmap), + : PlatformDevice(bitmap), data_(data) { // The data object is already ref'ed for us by create(). } @@ -236,36 +251,36 @@ BitmapPlatformDeviceWin::BitmapPlatformDeviceWin( // The copy constructor just adds another reference to the underlying data. // We use a const cast since the default Skia definitions don't define the // proper constedness that we expect (accessBitmap should really be const). -BitmapPlatformDeviceWin::BitmapPlatformDeviceWin( - const BitmapPlatformDeviceWin& other) - : PlatformDeviceWin( - const_cast<BitmapPlatformDeviceWin&>(other).accessBitmap(true)), +BitmapPlatformDevice::BitmapPlatformDevice( + const BitmapPlatformDevice& other) + : PlatformDevice( + const_cast<BitmapPlatformDevice&>(other).accessBitmap(true)), data_(other.data_) { data_->ref(); } -BitmapPlatformDeviceWin::~BitmapPlatformDeviceWin() { +BitmapPlatformDevice::~BitmapPlatformDevice() { data_->unref(); } -BitmapPlatformDeviceWin& BitmapPlatformDeviceWin::operator=( - const BitmapPlatformDeviceWin& other) { +BitmapPlatformDevice& BitmapPlatformDevice::operator=( + const BitmapPlatformDevice& other) { data_ = other.data_; data_->ref(); return *this; } -HDC BitmapPlatformDeviceWin::getBitmapDC() { +HDC BitmapPlatformDevice::getBitmapDC() { return data_->GetBitmapDC(); } -void BitmapPlatformDeviceWin::setMatrixClip(const SkMatrix& transform, - const SkRegion& region) { +void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, + const SkRegion& region) { data_->SetMatrixClip(transform, region); } -void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y, - const RECT* src_rect) { +void BitmapPlatformDevice::drawToHDC(HDC dc, int x, int y, + const RECT* src_rect) { bool created_dc = !data_->IsBitmapDCCreated(); HDC source_dc = getBitmapDC(); @@ -318,7 +333,7 @@ void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y, data_->ReleaseBitmapDC(); } -void BitmapPlatformDeviceWin::makeOpaque(int x, int y, int width, int height) { +void BitmapPlatformDevice::makeOpaque(int x, int y, int width, int height) { const SkBitmap& bitmap = accessBitmap(true); SkASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); @@ -347,14 +362,14 @@ void BitmapPlatformDeviceWin::makeOpaque(int x, int y, int width, int height) { } // Returns the color value at the specified location. -SkColor BitmapPlatformDeviceWin::getColorAt(int x, int y) { +SkColor BitmapPlatformDevice::getColorAt(int x, int y) { const SkBitmap& bitmap = accessBitmap(false); SkAutoLockPixels lock(bitmap); uint32_t* data = bitmap.getAddr32(0, 0); return static_cast<SkColor>(data[x + y * width()]); } -void BitmapPlatformDeviceWin::onAccessBitmap(SkBitmap* bitmap) { +void BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI // operation has occurred on our DC. if (data_->IsBitmapDCCreated()) |