diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-19 21:18:21 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-19 21:18:21 +0000 |
commit | 0026e48d1cf39bac65875fba6f5d38eb550a22f9 (patch) | |
tree | b144d2619f68e667f8970c91b72cd2478b9231c3 | |
parent | 28461252ccd08f81ba91e89428fce03f9d66530a (diff) | |
download | chromium_src-0026e48d1cf39bac65875fba6f5d38eb550a22f9.zip chromium_src-0026e48d1cf39bac65875fba6f5d38eb550a22f9.tar.gz chromium_src-0026e48d1cf39bac65875fba6f5d38eb550a22f9.tar.bz2 |
Remove base dependencies in the Windows-specific skia/ext code.
Review URL: http://codereview.chromium.org/14900
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7317 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | skia/ext/bitmap_platform_device_win.cc | 66 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_win.h | 16 | ||||
-rw-r--r-- | skia/ext/platform_canvas_win.cc | 25 | ||||
-rw-r--r-- | skia/ext/platform_canvas_win.h | 1 | ||||
-rw-r--r-- | skia/ext/platform_device_win.cc | 42 | ||||
-rw-r--r-- | skia/ext/skia_utils_win.cc | 21 | ||||
-rw-r--r-- | skia/ext/vector_canvas.cc | 12 | ||||
-rw-r--r-- | skia/ext/vector_canvas.h | 4 | ||||
-rw-r--r-- | skia/ext/vector_device.cc | 101 | ||||
-rw-r--r-- | skia/ext/vector_device.h | 11 |
10 files changed, 164 insertions, 135 deletions
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc index 674a6d9..1b5c2eb 100644 --- a/skia/ext/bitmap_platform_device_win.cc +++ b/skia/ext/bitmap_platform_device_win.cc @@ -4,9 +4,8 @@ #include "skia/ext/bitmap_platform_device_win.h" -#include "base/gfx/gdi_util.h" -#include "base/logging.h" #include "SkMatrix.h" +#include "SkRefCnt.h" #include "SkRegion.h" #include "SkUtils.h" @@ -100,8 +99,7 @@ void FixupAlphaBeforeCompositing(uint32_t* pixel) { } // namespace -class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData - : public base::RefCounted<BitmapPlatformDeviceWinData> { +class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData : public SkRefCnt { public: explicit BitmapPlatformDeviceWinData(HBITMAP hbitmap); @@ -144,10 +142,11 @@ class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData SkRegion clip_region_; private: - friend class base::RefCounted<BitmapPlatformDeviceWinData>; - ~BitmapPlatformDeviceWinData(); + virtual ~BitmapPlatformDeviceWinData(); - DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceWinData); + // Copy & assign are not supported. + BitmapPlatformDeviceWinData(const BitmapPlatformDeviceWinData&); + BitmapPlatformDeviceWinData& operator=(const BitmapPlatformDeviceWinData&); }; BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::BitmapPlatformDeviceWinData( @@ -190,7 +189,7 @@ HDC BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::GetBitmapDC() { } void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::ReleaseBitmapDC() { - DCHECK(hdc_); + SkASSERT(hdc_); DeleteDC(hdc_); hdc_ = NULL; } @@ -227,11 +226,12 @@ 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(HDC screen_dc, - int width, - int height, - bool is_opaque, - HANDLE shared_section) { +BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create( + HDC screen_dc, + int width, + int height, + bool is_opaque, + HANDLE shared_section) { SkBitmap bitmap; // CreateDIBSection appears to get unhappy if we create an empty bitmap, so @@ -242,7 +242,17 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(HDC screen_dc, } BITMAPINFOHEADER hdr = {0}; - gfx::CreateBitmapHeader(width, height, &hdr); + hdr.biSize = sizeof(BITMAPINFOHEADER); + hdr.biWidth = width; + hdr.biHeight = -height; // minus means top-down bitmap + hdr.biPlanes = 1; + hdr.biBitCount = 32; + hdr.biCompression = BI_RGB; // no compression + hdr.biSizeImage = 0; + hdr.biXPelsPerMeter = 1; + hdr.biYPelsPerMeter = 1; + hdr.biClrUsed = 0; + hdr.biClrImportant = 0; void* data = NULL; HBITMAP hbitmap = CreateDIBSection(screen_dc, @@ -256,7 +266,6 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(HDC screen_dc, // we deliberately crash here, even in release mode. if (!hbitmap) { DWORD error = GetLastError(); - LOG(ERROR) << "CreateDIBSection Failed. Error: " << error << "\n"; return NULL; } @@ -277,7 +286,8 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(HDC screen_dc, width * height); } - // The device object will take ownership of the HBITMAP. + // 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); } @@ -286,7 +296,10 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(HDC screen_dc, // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. BitmapPlatformDeviceWin::BitmapPlatformDeviceWin( BitmapPlatformDeviceWinData* data, - const SkBitmap& bitmap) : PlatformDeviceWin(bitmap), data_(data) { + const SkBitmap& bitmap) + : PlatformDeviceWin(bitmap), + data_(data) { + // The data object is already ref'ed for us by create(). } // The copy constructor just adds another reference to the underlying data. @@ -297,14 +310,17 @@ BitmapPlatformDeviceWin::BitmapPlatformDeviceWin( : PlatformDeviceWin( const_cast<BitmapPlatformDeviceWin&>(other).accessBitmap(true)), data_(other.data_) { + data_->ref(); } BitmapPlatformDeviceWin::~BitmapPlatformDeviceWin() { + data_->unref(); } BitmapPlatformDeviceWin& BitmapPlatformDeviceWin::operator=( const BitmapPlatformDeviceWin& other) { data_ = other.data_; + data_->ref(); return *this; } @@ -313,12 +329,12 @@ HDC BitmapPlatformDeviceWin::getBitmapDC() { } void BitmapPlatformDeviceWin::setMatrixClip(const SkMatrix& transform, - const SkRegion& region) { + const SkRegion& region) { data_->SetMatrixClip(transform, region); } void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y, - const RECT* src_rect) { + const RECT* src_rect) { bool created_dc = !data_->IsBitmapDCCreated(); HDC source_dc = getBitmapDC(); @@ -351,7 +367,7 @@ void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y, src_rect->top, SRCCOPY); } else { - DCHECK(copy_width != 0 && copy_height != 0); + SkASSERT(copy_width != 0 && copy_height != 0); BLENDFUNCTION blend_function = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA}; GdiAlphaBlend(dc, x, @@ -416,11 +432,11 @@ void BitmapPlatformDeviceWin::onAccessBitmap(SkBitmap* bitmap) { template<BitmapPlatformDeviceWin::adjustAlpha adjustor> void BitmapPlatformDeviceWin::processPixels(int x, - int y, - int width, - int height) { + int y, + int width, + int height) { const SkBitmap& bitmap = accessBitmap(true); - DCHECK_EQ(bitmap.config(), SkBitmap::kARGB_8888_Config); + SkASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); const SkMatrix& matrix = data_->transform(); int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x; int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y; @@ -428,7 +444,7 @@ void BitmapPlatformDeviceWin::processPixels(int x, if (Constrain(bitmap.width(), &bitmap_start_x, &width) && Constrain(bitmap.height(), &bitmap_start_y, &height)) { SkAutoLockPixels lock(bitmap); - DCHECK_EQ(bitmap.rowBytes() % sizeof(uint32_t), 0u); + SkASSERT(bitmap.rowBytes() % sizeof(uint32_t) == 0u); size_t row_words = bitmap.rowBytes() / sizeof(uint32_t); // Set data to the first pixel to be modified. uint32_t* data = bitmap.getAddr32(0, 0) + (bitmap_start_y * row_words) + diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h index e3b63cb..f6e456d 100644 --- a/skia/ext/bitmap_platform_device_win.h +++ b/skia/ext/bitmap_platform_device_win.h @@ -5,7 +5,6 @@ #ifndef SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_ #define SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_ -#include "base/ref_counted.h" #include "skia/ext/platform_device_win.h" namespace skia { @@ -34,10 +33,10 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin { // If shared_section is non-null, then it must be a handle to a file-mapping // object returned by CreateFileMapping. See CreateDIBSection for details. static BitmapPlatformDeviceWin* create(HDC screen_dc, - int width, - int height, - bool is_opaque, - HANDLE shared_section); + int width, + int height, + bool is_opaque, + HANDLE shared_section); // Copy constructor. When copied, devices duplicate their internal data, so // stay linked. This is because their implementation is very heavyweight @@ -88,7 +87,7 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin { // bitmaps used by the base device class are already refcounted and copyable. class BitmapPlatformDeviceWinData; - // Private constructor. + // Private constructor. The data should already be ref'ed for us. BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data, const SkBitmap& bitmap); @@ -101,8 +100,9 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin { int width, int height); - // Data associated with this device, guaranteed non-null. - scoped_refptr<BitmapPlatformDeviceWinData> data_; + // Data associated with this device, guaranteed non-null. We hold a reference + // to this object. + BitmapPlatformDeviceWinData* data_; }; } // namespace skia diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc index 4062d7b..85a6b6d 100644 --- a/skia/ext/platform_canvas_win.cc +++ b/skia/ext/platform_canvas_win.cc @@ -2,14 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <psapi.h> + #include "skia/ext/platform_canvas_win.h" -#include "base/logging.h" -#include "base/process_util.h" #include "skia/ext/bitmap_platform_device_win.h" namespace skia { +// Crash on failure. +#define CHECK(condition) if (!(condition)) __debugbreak(); + // Crashes the process. This is called when a bitmap allocation fails, and this // function tries to determine why it might have failed, and crash on different // lines. This allows us to see in crash dumps the most likely reason for the @@ -23,21 +26,21 @@ void CrashForBitmapAllocationFailure(int w, int h) { // If the bitmap is ginormous, then we probably can't allocate it. // We use 64M pixels = 256MB @ 4 bytes per pixel. - const int64 kGinormousBitmapPxl = 64000000; - CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl); + const __int64 kGinormousBitmapPxl = 64000000; + CHECK(static_cast<__int64>(w) * static_cast<__int64>(h) < + kGinormousBitmapPxl); // If we're using a crazy amount of virtual address space, then maybe there // isn't enough for our bitmap. - const int64 kLotsOfMem = 1500000000; // 1.5GB. - scoped_ptr<base::ProcessMetrics> process_metrics( - base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess())); - CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem); + const __int64 kLotsOfMem = 1500000000; // 1.5GB. + PROCESS_MEMORY_COUNTERS pmc; + if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) + CHECK(pmc.PagefileUsage < kLotsOfMem); // Everything else. CHECK(0); } - PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() { } @@ -94,7 +97,7 @@ SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config, int width, int height, bool is_opaque, bool isForLayer) { - DCHECK(config == SkBitmap::kARGB_8888_Config); + SkASSERT(config == SkBitmap::kARGB_8888_Config); return createPlatformDevice(width, height, is_opaque, NULL); } @@ -110,7 +113,7 @@ SkDevice* PlatformCanvasWin::createPlatformDevice(int width, } SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) { - NOTREACHED(); + SkASSERT(false); // Should not be called. return NULL; } diff --git a/skia/ext/platform_canvas_win.h b/skia/ext/platform_canvas_win.h index c16fa33..e0e6e70 100644 --- a/skia/ext/platform_canvas_win.h +++ b/skia/ext/platform_canvas_win.h @@ -7,7 +7,6 @@ #include <windows.h> -#include "base/basictypes.h" #include "skia/ext/platform_device_win.h" #include "SkCanvas.h" diff --git a/skia/ext/platform_device_win.cc b/skia/ext/platform_device_win.cc index 905e9bf..8af393d 100644 --- a/skia/ext/platform_device_win.cc +++ b/skia/ext/platform_device_win.cc @@ -4,7 +4,6 @@ #include "skia/ext/platform_device_win.h" -#include "base/logging.h" #include "skia/ext/skia_utils_win.h" #include "SkMatrix.h" #include "SkPath.h" @@ -26,35 +25,35 @@ void PlatformDeviceWin::InitializeDC(HDC context) { // and arcs themselves fully respect the device context's world-to-device // transformation. BOOL res = SetGraphicsMode(context, GM_ADVANCED); - DCHECK_NE(res, 0); + SkASSERT(res != 0); // Enables dithering. res = SetStretchBltMode(context, HALFTONE); - DCHECK_NE(res, 0); + SkASSERT(res != 0); // As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called // right after. res = SetBrushOrgEx(context, 0, 0, NULL); - DCHECK_NE(res, 0); + SkASSERT(res != 0); // Sets up default orientation. res = SetArcDirection(context, AD_CLOCKWISE); - DCHECK_NE(res, 0); + SkASSERT(res != 0); // Sets up default colors. res = SetBkColor(context, RGB(255, 255, 255)); - DCHECK_NE(res, CLR_INVALID); + SkASSERT(res != CLR_INVALID); res = SetTextColor(context, RGB(0, 0, 0)); - DCHECK_NE(res, CLR_INVALID); + SkASSERT(res != CLR_INVALID); res = SetDCBrushColor(context, RGB(255, 255, 255)); - DCHECK_NE(res, CLR_INVALID); + SkASSERT(res != CLR_INVALID); res = SetDCPenColor(context, RGB(0, 0, 0)); - DCHECK_NE(res, CLR_INVALID); + SkASSERT(res != CLR_INVALID); // Sets up default transparency. res = SetBkMode(context, OPAQUE); - DCHECK_NE(res, 0); + SkASSERT(res != 0); res = SetROP2(context, R2_COPYPEN); - DCHECK_NE(res, 0); + SkASSERT(res != 0); } // static @@ -62,21 +61,21 @@ void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) { switch (path.getFillType()) { case SkPath::kWinding_FillType: { int res = SetPolyFillMode(context, WINDING); - DCHECK(res != 0); + SkASSERT(res != 0); break; } case SkPath::kEvenOdd_FillType: { int res = SetPolyFillMode(context, ALTERNATE); - DCHECK(res != 0); + SkASSERT(res != 0); break; } default: { - NOTREACHED(); + SkASSERT(false); break; } } BOOL res = BeginPath(context); - DCHECK(res != 0); + SkASSERT(res != 0); CubicPaths paths; if (!SkPathToCubicPaths(&paths, path)) @@ -87,7 +86,6 @@ void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) { ++path) { if (!path->size()) continue; - // DCHECK_EQ(points.size() % 4, 0); points.resize(0); points.reserve(path->size() * 3 / 4 + 1); points.push_back(SkPointToPOINT(path->front().p[0])); @@ -98,14 +96,14 @@ void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) { points.push_back(SkPointToPOINT(point->p[2])); points.push_back(SkPointToPOINT(point->p[3])); } - DCHECK_EQ((points.size() - 1) % 3, 0); + SkASSERT((points.size() - 1) % 3 == 0); // This is slightly inefficient since all straight line and quadratic lines // are "upgraded" to a cubic line. // TODO(maruel): http://b/1147346 We should use // PolyDraw/PolyBezier/Polyline whenever possible. res = PolyBezier(context, &points.front(), static_cast<DWORD>(points.size())); - DCHECK_NE(res, 0); + SkASSERT(res != 0); if (res == 0) break; } @@ -114,7 +112,7 @@ void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) { AbortPath(context); } else { res = EndPath(context); - DCHECK(res != 0); + SkASSERT(res != 0); } } @@ -183,7 +181,7 @@ bool PlatformDeviceWin::SkPathToCubicPaths(CubicPaths* paths, break; } } - DCHECK(current_path); + SkASSERT(current_path); if (!current_path) { paths->clear(); return false; @@ -220,9 +218,9 @@ void PlatformDeviceWin::LoadClippingRegionToDC(HDC context, hrgn = PathToRegion(context); } int result = SelectClipRgn(context, hrgn); - DCHECK_NE(result, ERROR); + SkASSERT(result != ERROR); result = DeleteObject(hrgn); - DCHECK_NE(result, 0); + SkASSERT(result != 0); } } // namespace skia diff --git a/skia/ext/skia_utils_win.cc b/skia/ext/skia_utils_win.cc index f6c8006..59bef6d 100644 --- a/skia/ext/skia_utils_win.cc +++ b/skia/ext/skia_utils_win.cc @@ -2,18 +2,27 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <windows.h> + #include "skia/ext/skia_utils_win.h" -#include "base/logging.h" #include "SkRect.h" #include "SkGradientShader.h" namespace { -COMPILE_ASSERT(offsetof(RECT, left) == offsetof(SkIRect, fLeft), o1); -COMPILE_ASSERT(offsetof(RECT, top) == offsetof(SkIRect, fTop), o2); -COMPILE_ASSERT(offsetof(RECT, right) == offsetof(SkIRect, fRight), o3); -COMPILE_ASSERT(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), o4); +template <bool> +struct CompileAssert { +}; + +#undef COMPILE_ASSERT +#define COMPILE_ASSERT(expr, msg) \ + typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] + +COMPILE_ASSERT(SK_OFFSETOF(RECT, left) == SK_OFFSETOF(SkIRect, fLeft), o1); +COMPILE_ASSERT(SK_OFFSETOF(RECT, top) == SK_OFFSETOF(SkIRect, fTop), o2); +COMPILE_ASSERT(SK_OFFSETOF(RECT, right) == SK_OFFSETOF(SkIRect, fRight), o3); +COMPILE_ASSERT(SK_OFFSETOF(RECT, bottom) == SK_OFFSETOF(SkIRect, fBottom), o4); COMPILE_ASSERT(sizeof(RECT().left) == sizeof(SkIRect().fLeft), o5); COMPILE_ASSERT(sizeof(RECT().top) == sizeof(SkIRect().fTop), o6); COMPILE_ASSERT(sizeof(RECT().right) == sizeof(SkIRect().fRight), o7); @@ -48,7 +57,7 @@ COLORREF SkColorToCOLORREF(SkColor color) { // Currently, Alpha is always 255 or the color is 0 so there is no need to // demultiply the channels. If this DCHECK() is ever hit, the full // (SkColorGetX(color) * 255 / a) will have to be added in the conversion. - DCHECK((0xFF == SkColorGetA(color)) || (0 == color)); + SkASSERT((0xFF == SkColorGetA(color)) || (0 == color)); #ifndef _MSC_VER return RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color)); #else diff --git a/skia/ext/vector_canvas.cc b/skia/ext/vector_canvas.cc index 33ac265..ea5542f 100644 --- a/skia/ext/vector_canvas.cc +++ b/skia/ext/vector_canvas.cc @@ -4,7 +4,6 @@ #include "skia/ext/vector_canvas.h" -#include "base/logging.h" #include "skia/ext/vector_device.h" namespace skia { @@ -14,7 +13,8 @@ VectorCanvas::VectorCanvas() { VectorCanvas::VectorCanvas(HDC dc, int width, int height) { bool initialized = initialize(dc, width, height); - CHECK(initialized); + if (!initialized) + __debugbreak(); } VectorCanvas::~VectorCanvas() { @@ -35,20 +35,20 @@ SkBounder* VectorCanvas::setBounder(SkBounder* bounder) { return PlatformCanvasWin::setBounder(bounder); // This function isn't used in the code. Verify this assumption. - NOTREACHED(); + SkASSERT(false); return NULL; } SkDevice* VectorCanvas::createDevice(SkBitmap::Config config, int width, int height, bool is_opaque, bool isForLayer) { - DCHECK(config == SkBitmap::kARGB_8888_Config); + SkASSERT(config == SkBitmap::kARGB_8888_Config); return createPlatformDevice(width, height, is_opaque, NULL); } SkDrawFilter* VectorCanvas::setDrawFilter(SkDrawFilter* filter) { // This function isn't used in the code. Verify this assumption. - NOTREACHED(); + SkASSERT(false); return NULL; } @@ -76,7 +76,7 @@ SkDevice* VectorCanvas::createPlatformDevice(int width, // multiply each SkScalar that are passed to SkScalarRound(value) as // SkScalarRound(value * 10). Safari is already doing the same for text // rendering. - DCHECK(shared_section); + SkASSERT(shared_section); PlatformDeviceWin* device = VectorDevice::create( reinterpret_cast<HDC>(shared_section), width, height); return device; diff --git a/skia/ext/vector_canvas.h b/skia/ext/vector_canvas.h index 6b61b58..897ffd4 100644 --- a/skia/ext/vector_canvas.h +++ b/skia/ext/vector_canvas.h @@ -37,7 +37,9 @@ class VectorCanvas : public PlatformCanvasWin { // Returns true if the top device is vector based and not bitmap based. bool IsTopDeviceVectorial() const; - DISALLOW_COPY_AND_ASSIGN(VectorCanvas); + // Copy & assign are not supported. + VectorCanvas(const VectorCanvas&); + const VectorCanvas& operator=(const VectorCanvas&); }; } // namespace skia diff --git a/skia/ext/vector_device.cc b/skia/ext/vector_device.cc index 98aaeff..295101f 100644 --- a/skia/ext/vector_device.cc +++ b/skia/ext/vector_device.cc @@ -5,8 +5,6 @@ #include "skia/ext/vector_device.h" #include "base/gfx/gdi_util.h" -#include "base/logging.h" -#include "base/scoped_handle.h" #include "skia/ext/skia_utils_win.h" #include "SkUtils.h" @@ -55,8 +53,8 @@ VectorDevice::VectorDevice(HDC dc, const SkBitmap& bitmap) } VectorDevice::~VectorDevice() { - DCHECK(previous_brush_ == NULL); - DCHECK(previous_pen_ == NULL); + SkASSERT(previous_brush_ == NULL); + SkASSERT(previous_pen_ == NULL); } @@ -77,7 +75,7 @@ void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, return; if (mode == SkCanvas::kPoints_PointMode) { - NOTREACHED(); + SkASSERT(false); return; } @@ -89,7 +87,7 @@ void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, switch (mode) { case SkCanvas::kLines_PointMode: if (count % 2) { - NOTREACHED(); + SkASSERT(false); return; } for (size_t i = 0; i < count / 2; ++i) { @@ -104,7 +102,7 @@ void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, } break; default: - NOTREACHED(); + SkASSERT(false); return; } // Draw the calculated path. @@ -139,7 +137,7 @@ void VectorDevice::drawRect(const SkDraw& draw, const SkRect& rect, SkScalarRound(rect.fTop), SkScalarRound(rect.fRight), SkScalarRound(rect.fBottom))) { - NOTREACHED(); + SkASSERT(false); } Cleanup(); } @@ -168,21 +166,21 @@ void VectorDevice::drawPath(const SkDraw& draw, const SkPath& path, switch (paint.getStyle()) { case SkPaint::kFill_Style: { BOOL res = StrokeAndFillPath(dc); - DCHECK(res != 0); + SkASSERT(res != 0); break; } case SkPaint::kStroke_Style: { BOOL res = StrokePath(dc); - DCHECK(res != 0); + SkASSERT(res != 0); break; } case SkPaint::kStrokeAndFill_Style: { BOOL res = StrokeAndFillPath(dc); - DCHECK(res != 0); + SkASSERT(res != 0); break; } default: - NOTREACHED(); + SkASSERT(false); break; } Cleanup(); @@ -217,14 +215,14 @@ void VectorDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, void VectorDevice::drawText(const SkDraw& draw, const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { // This function isn't used in the code. Verify this assumption. - NOTREACHED(); + SkASSERT(false); } void VectorDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, const SkScalar pos[], SkScalar constY, int scalarsPerPos, const SkPaint& paint) { // This function isn't used in the code. Verify this assumption. - NOTREACHED(); + SkASSERT(false); } void VectorDevice::drawTextOnPath(const SkDraw& draw, const void* text, @@ -232,7 +230,7 @@ void VectorDevice::drawTextOnPath(const SkDraw& draw, const void* text, const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { // This function isn't used in the code. Verify this assumption. - NOTREACHED(); + SkASSERT(false); } void VectorDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, @@ -242,7 +240,7 @@ void VectorDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, const uint16_t indices[], int indexCount, const SkPaint& paint) { // This function isn't used in the code. Verify this assumption. - NOTREACHED(); + SkASSERT(false); } void VectorDevice::drawDevice(const SkDraw& draw, SkDevice* device, int x, @@ -309,25 +307,25 @@ bool VectorDevice::ApplyPaint(const SkPaint& paint) { // SkShader::CreateBitmapShader // SkGradientShader::CreateRadial // SkGradientShader::CreateLinear - // DCHECK(!paint.getShader()); + // SkASSERT(!paint.getShader()); // http://b/1106647 Implement loopers and mask filter. Looper currently in // use: // SkBlurDrawLooper is used for shadows. - // DCHECK(!paint.getLooper()); - // DCHECK(!paint.getMaskFilter()); + // SkASSERT(!paint.getLooper()); + // SkASSERT(!paint.getMaskFilter()); // http://b/1165900 Implement xfermode. - // DCHECK(!paint.getXfermode()); + // SkASSERT(!paint.getXfermode()); // The path effect should be processed before arriving here. - DCHECK(!paint.getPathEffect()); + SkASSERT(!paint.getPathEffect()); // These aren't used in the code. Verify this assumption. - DCHECK(!paint.getColorFilter()); - DCHECK(!paint.getRasterizer()); + SkASSERT(!paint.getColorFilter()); + SkASSERT(!paint.getRasterizer()); // Reuse code to load Win32 Fonts. - DCHECK(!paint.getTypeface()); + SkASSERT(!paint.getTypeface()); return true; } @@ -341,7 +339,7 @@ void VectorDevice::setMatrixClip(const SkMatrix& transform, } void VectorDevice::drawToHDC(HDC dc, int x, int y, const RECT* src_rect) { - NOTREACHED(); + SkASSERT(false); } void VectorDevice::LoadClipRegion() { @@ -351,7 +349,7 @@ void VectorDevice::LoadClipRegion() { } bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) { - DCHECK(previous_brush_ == NULL); + SkASSERT(previous_brush_ == NULL); // We can't use SetDCBrushColor() or DC_BRUSH when drawing to a EMF buffer. // SetDCBrushColor() calls are not recorded at all and DC_BRUSH will use // WHITE_BRUSH instead. @@ -359,7 +357,7 @@ bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) { if (!use_brush) { // Set the transparency. if (0 == SetBkMode(hdc_, TRANSPARENT)) { - NOTREACHED(); + SkASSERT(false); return false; } @@ -370,7 +368,7 @@ bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) { // Set the opacity. if (0 == SetBkMode(hdc_, OPAQUE)) { - NOTREACHED(); + SkASSERT(false); return false; } @@ -381,7 +379,7 @@ bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) { bool VectorDevice::CreatePen(bool use_pen, COLORREF color, int stroke_width, float stroke_miter, DWORD pen_style) { - DCHECK(previous_pen_ == NULL); + SkASSERT(previous_pen_ == NULL); // We can't use SetDCPenColor() or DC_PEN when drawing to a EMF buffer. // SetDCPenColor() calls are not recorded at all and DC_PEN will use BLACK_PEN // instead. @@ -405,13 +403,13 @@ bool VectorDevice::CreatePen(bool use_pen, COLORREF color, int stroke_width, brush.lbColor = color; brush.lbHatch = 0; HPEN pen = ExtCreatePen(pen_style, stroke_width, &brush, 0, NULL); - DCHECK(pen != NULL); + SkASSERT(pen != NULL); previous_pen_ = SelectObject(pen); if (previous_pen_ == NULL) return false; if (!SetMiterLimit(hdc_, stroke_miter, NULL)) { - NOTREACHED(); + SkASSERT(false); return false; } return true; @@ -423,7 +421,7 @@ void VectorDevice::Cleanup() { previous_brush_ = NULL; if (result) { BOOL res = DeleteObject(result); - DCHECK(res != 0); + SkASSERT(res != 0); } } if (previous_pen_) { @@ -431,7 +429,7 @@ void VectorDevice::Cleanup() { previous_pen_ = NULL; if (result) { BOOL res = DeleteObject(result); - DCHECK(res != 0); + SkASSERT(res != 0); } } // Remove any loaded path from the context. @@ -440,7 +438,7 @@ void VectorDevice::Cleanup() { HGDIOBJ VectorDevice::SelectObject(HGDIOBJ object) { HGDIOBJ result = ::SelectObject(hdc_, object); - DCHECK(result != HGDI_ERROR); + SkASSERT(result != HGDI_ERROR); if (result == HGDI_ERROR) return NULL; return result; @@ -450,7 +448,7 @@ bool VectorDevice::CreateBrush(bool use_brush, const SkPaint& paint) { // Make sure that for transparent color, no brush is used. if (paint.getAlpha() == 0) { // Test if it ever happen. - NOTREACHED(); + SkASSERT(false); use_brush = false; } @@ -461,7 +459,7 @@ bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) { // Make sure that for transparent color, no pen is used. if (paint.getAlpha() == 0) { // Test if it ever happen. - NOTREACHED(); + SkASSERT(false); use_pen = false; } @@ -480,7 +478,7 @@ bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) { pen_style |= PS_JOIN_BEVEL; break; default: - NOTREACHED(); + SkASSERT(false); break; } switch (paint.getStrokeCap()) { @@ -497,7 +495,7 @@ bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) { pen_style |= PS_ENDCAP_SQUARE; break; default: - NOTREACHED(); + SkASSERT(false); break; } @@ -510,7 +508,7 @@ bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) { void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y, const SkPaint& paint) { - uint8 alpha = paint.getAlpha(); + unsigned char alpha = paint.getAlpha(); if (alpha == 0) return; @@ -537,10 +535,10 @@ void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y, gfx::CreateBitmapV4Header(src_size_x, src_size_y, &bitmap_header); HDC dc = getBitmapDC(); SkAutoLockPixels lock(bitmap); - DCHECK_EQ(bitmap.getConfig(), SkBitmap::kARGB_8888_Config); + SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); const uint32_t* pixels = static_cast<const uint32_t*>(bitmap.getPixels()); if (pixels == NULL) { - NOTREACHED(); + SkASSERT(false); return; } @@ -562,15 +560,14 @@ void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y, gfx::CreateBitmapHeader(src_size_x, src_size_y, &hdr); if (is_translucent) { // The image must be loaded as a bitmap inside a device context. - ScopedHDC bitmap_dc(::CreateCompatibleDC(dc)); + HDC bitmap_dc = ::CreateCompatibleDC(dc); void* bits = NULL; - ScopedBitmap hbitmap(::CreateDIBSection( + HBITMAP hbitmap = ::CreateDIBSection( bitmap_dc, reinterpret_cast<const BITMAPINFO*>(&hdr), - DIB_RGB_COLORS, &bits, NULL, 0)); + DIB_RGB_COLORS, &bits, NULL, 0); memcpy(bits, pixels, bitmap.getSize()); - DCHECK(hbitmap); + SkASSERT(hbitmap); HGDIOBJ old_bitmap = ::SelectObject(bitmap_dc, hbitmap); - DeleteObject(old_bitmap); // After some analysis of IE7's behavior, this is the thing to do. I was // sure IE7 was doing so kind of bitmasking due to the way translucent image @@ -580,7 +577,7 @@ void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y, // what the driver expects. DWORD previous_mode = GetStretchBltMode(dc); BOOL result = SetStretchBltMode(dc, COLORONCOLOR); - DCHECK(result); + SkASSERT(result); // Note that this function expect premultiplied colors (!) BLENDFUNCTION blend_function = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA}; result = GdiAlphaBlend(dc, @@ -590,9 +587,13 @@ void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y, 0, 0, // Source origin. src_size_x, src_size_y, // Source size. blend_function); - DCHECK(result); + SkASSERT(result); result = SetStretchBltMode(dc, previous_mode); - DCHECK(result); + SkASSERT(result); + + ::SelectObject(bitmap_dc, static_cast<HBITMAP>(old_bitmap)); + DeleteObject(hbitmap); + DeleteDC(bitmap_dc); } else { BOOL result = StretchDIBits(dc, x, y, // Destination origin. @@ -603,7 +604,7 @@ void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y, reinterpret_cast<const BITMAPINFO*>(&hdr), DIB_RGB_COLORS, SRCCOPY); - DCHECK(result); + SkASSERT(result); } Cleanup(); } diff --git a/skia/ext/vector_device.h b/skia/ext/vector_device.h index 5fdb9a0..ccd4333 100644 --- a/skia/ext/vector_device.h +++ b/skia/ext/vector_device.h @@ -2,10 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef VectorDevice_h -#define VectorDevice_h +#ifndef SKIA_EXT_VECTOR_DEVICE_H_ +#define SKIA_EXT_VECTOR_DEVICE_H_ -#include "base/basictypes.h" #include "skia/ext/platform_device_win.h" #include "SkMatrix.h" #include "SkRegion.h" @@ -110,10 +109,12 @@ class VectorDevice : public PlatformDeviceWin { // Previously selected pen before the current drawing. HGDIOBJ previous_pen_; - DISALLOW_COPY_AND_ASSIGN(VectorDevice); + // Copy & assign are not supported. + VectorDevice(const VectorDevice&); + const VectorDevice& operator=(const VectorDevice&); }; } // namespace skia -#endif // VectorDevice_h +#endif // SKIA_EXT_VECTOR_DEVICE_H_ |