summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-19 21:22:31 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-19 21:22:31 +0000
commit83d36f001d591d153b3442e9d0f3739ee984469a (patch)
tree34b782a4665736d8cc2a11f0806f13aa4c765919 /skia
parent0026e48d1cf39bac65875fba6f5d38eb550a22f9 (diff)
downloadchromium_src-83d36f001d591d153b3442e9d0f3739ee984469a.zip
chromium_src-83d36f001d591d153b3442e9d0f3739ee984469a.tar.gz
chromium_src-83d36f001d591d153b3442e9d0f3739ee984469a.tar.bz2
Reverting 7317.
Review URL: http://codereview.chromium.org/15089 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7318 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/bitmap_platform_device_win.cc66
-rw-r--r--skia/ext/bitmap_platform_device_win.h16
-rw-r--r--skia/ext/platform_canvas_win.cc25
-rw-r--r--skia/ext/platform_canvas_win.h1
-rw-r--r--skia/ext/platform_device_win.cc42
-rw-r--r--skia/ext/skia_utils_win.cc21
-rw-r--r--skia/ext/vector_canvas.cc12
-rw-r--r--skia/ext/vector_canvas.h4
-rw-r--r--skia/ext/vector_device.cc101
-rw-r--r--skia/ext/vector_device.h11
10 files changed, 135 insertions, 164 deletions
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index 1b5c2eb..674a6d9 100644
--- a/skia/ext/bitmap_platform_device_win.cc
+++ b/skia/ext/bitmap_platform_device_win.cc
@@ -4,8 +4,9 @@
#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"
@@ -99,7 +100,8 @@ void FixupAlphaBeforeCompositing(uint32_t* pixel) {
} // namespace
-class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData : public SkRefCnt {
+class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData
+ : public base::RefCounted<BitmapPlatformDeviceWinData> {
public:
explicit BitmapPlatformDeviceWinData(HBITMAP hbitmap);
@@ -142,11 +144,10 @@ class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData : public SkRefCnt {
SkRegion clip_region_;
private:
- virtual ~BitmapPlatformDeviceWinData();
+ friend class base::RefCounted<BitmapPlatformDeviceWinData>;
+ ~BitmapPlatformDeviceWinData();
- // Copy & assign are not supported.
- BitmapPlatformDeviceWinData(const BitmapPlatformDeviceWinData&);
- BitmapPlatformDeviceWinData& operator=(const BitmapPlatformDeviceWinData&);
+ DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceWinData);
};
BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::BitmapPlatformDeviceWinData(
@@ -189,7 +190,7 @@ HDC BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::GetBitmapDC() {
}
void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::ReleaseBitmapDC() {
- SkASSERT(hdc_);
+ DCHECK(hdc_);
DeleteDC(hdc_);
hdc_ = NULL;
}
@@ -226,12 +227,11 @@ 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,17 +242,7 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(
}
BITMAPINFOHEADER hdr = {0};
- 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;
+ gfx::CreateBitmapHeader(width, height, &hdr);
void* data = NULL;
HBITMAP hbitmap = CreateDIBSection(screen_dc,
@@ -266,6 +256,7 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(
// we deliberately crash here, even in release mode.
if (!hbitmap) {
DWORD error = GetLastError();
+ LOG(ERROR) << "CreateDIBSection Failed. Error: " << error << "\n";
return NULL;
}
@@ -286,8 +277,7 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(
width * height);
}
- // 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.
+ // The device object will take ownership of the HBITMAP.
return new BitmapPlatformDeviceWin(new BitmapPlatformDeviceWinData(hbitmap),
bitmap);
}
@@ -296,10 +286,7 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
BitmapPlatformDeviceWin::BitmapPlatformDeviceWin(
BitmapPlatformDeviceWinData* data,
- const SkBitmap& bitmap)
- : PlatformDeviceWin(bitmap),
- data_(data) {
- // The data object is already ref'ed for us by create().
+ const SkBitmap& bitmap) : PlatformDeviceWin(bitmap), data_(data) {
}
// The copy constructor just adds another reference to the underlying data.
@@ -310,17 +297,14 @@ 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;
}
@@ -329,12 +313,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();
@@ -367,7 +351,7 @@ void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y,
src_rect->top,
SRCCOPY);
} else {
- SkASSERT(copy_width != 0 && copy_height != 0);
+ DCHECK(copy_width != 0 && copy_height != 0);
BLENDFUNCTION blend_function = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
GdiAlphaBlend(dc,
x,
@@ -432,11 +416,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);
- SkASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config);
+ DCHECK_EQ(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;
@@ -444,7 +428,7 @@ void BitmapPlatformDeviceWin::processPixels(int x,
if (Constrain(bitmap.width(), &bitmap_start_x, &width) &&
Constrain(bitmap.height(), &bitmap_start_y, &height)) {
SkAutoLockPixels lock(bitmap);
- SkASSERT(bitmap.rowBytes() % sizeof(uint32_t) == 0u);
+ DCHECK_EQ(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 f6e456d..e3b63cb 100644
--- a/skia/ext/bitmap_platform_device_win.h
+++ b/skia/ext/bitmap_platform_device_win.h
@@ -5,6 +5,7 @@
#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 {
@@ -33,10 +34,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
@@ -87,7 +88,7 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin {
// bitmaps used by the base device class are already refcounted and copyable.
class BitmapPlatformDeviceWinData;
- // Private constructor. The data should already be ref'ed for us.
+ // Private constructor.
BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data,
const SkBitmap& bitmap);
@@ -100,9 +101,8 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin {
int width,
int height);
- // Data associated with this device, guaranteed non-null. We hold a reference
- // to this object.
- BitmapPlatformDeviceWinData* data_;
+ // Data associated with this device, guaranteed non-null.
+ scoped_refptr<BitmapPlatformDeviceWinData> data_;
};
} // namespace skia
diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc
index 85a6b6d..4062d7b 100644
--- a/skia/ext/platform_canvas_win.cc
+++ b/skia/ext/platform_canvas_win.cc
@@ -2,17 +2,14 @@
// 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
@@ -26,21 +23,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.
- PROCESS_MEMORY_COUNTERS pmc;
- if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
- CHECK(pmc.PagefileUsage < kLotsOfMem);
+ const int64 kLotsOfMem = 1500000000; // 1.5GB.
+ scoped_ptr<base::ProcessMetrics> process_metrics(
+ base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess()));
+ CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem);
// Everything else.
CHECK(0);
}
+
PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() {
}
@@ -97,7 +94,7 @@ SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config,
int width,
int height,
bool is_opaque, bool isForLayer) {
- SkASSERT(config == SkBitmap::kARGB_8888_Config);
+ DCHECK(config == SkBitmap::kARGB_8888_Config);
return createPlatformDevice(width, height, is_opaque, NULL);
}
@@ -113,7 +110,7 @@ SkDevice* PlatformCanvasWin::createPlatformDevice(int width,
}
SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) {
- SkASSERT(false); // Should not be called.
+ NOTREACHED();
return NULL;
}
diff --git a/skia/ext/platform_canvas_win.h b/skia/ext/platform_canvas_win.h
index e0e6e70..c16fa33 100644
--- a/skia/ext/platform_canvas_win.h
+++ b/skia/ext/platform_canvas_win.h
@@ -7,6 +7,7 @@
#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 8af393d..905e9bf 100644
--- a/skia/ext/platform_device_win.cc
+++ b/skia/ext/platform_device_win.cc
@@ -4,6 +4,7 @@
#include "skia/ext/platform_device_win.h"
+#include "base/logging.h"
#include "skia/ext/skia_utils_win.h"
#include "SkMatrix.h"
#include "SkPath.h"
@@ -25,35 +26,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);
- SkASSERT(res != 0);
+ DCHECK_NE(res, 0);
// Enables dithering.
res = SetStretchBltMode(context, HALFTONE);
- SkASSERT(res != 0);
+ DCHECK_NE(res, 0);
// As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called
// right after.
res = SetBrushOrgEx(context, 0, 0, NULL);
- SkASSERT(res != 0);
+ DCHECK_NE(res, 0);
// Sets up default orientation.
res = SetArcDirection(context, AD_CLOCKWISE);
- SkASSERT(res != 0);
+ DCHECK_NE(res, 0);
// Sets up default colors.
res = SetBkColor(context, RGB(255, 255, 255));
- SkASSERT(res != CLR_INVALID);
+ DCHECK_NE(res, CLR_INVALID);
res = SetTextColor(context, RGB(0, 0, 0));
- SkASSERT(res != CLR_INVALID);
+ DCHECK_NE(res, CLR_INVALID);
res = SetDCBrushColor(context, RGB(255, 255, 255));
- SkASSERT(res != CLR_INVALID);
+ DCHECK_NE(res, CLR_INVALID);
res = SetDCPenColor(context, RGB(0, 0, 0));
- SkASSERT(res != CLR_INVALID);
+ DCHECK_NE(res, CLR_INVALID);
// Sets up default transparency.
res = SetBkMode(context, OPAQUE);
- SkASSERT(res != 0);
+ DCHECK_NE(res, 0);
res = SetROP2(context, R2_COPYPEN);
- SkASSERT(res != 0);
+ DCHECK_NE(res, 0);
}
// static
@@ -61,21 +62,21 @@ void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) {
switch (path.getFillType()) {
case SkPath::kWinding_FillType: {
int res = SetPolyFillMode(context, WINDING);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
break;
}
case SkPath::kEvenOdd_FillType: {
int res = SetPolyFillMode(context, ALTERNATE);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
break;
}
default: {
- SkASSERT(false);
+ NOTREACHED();
break;
}
}
BOOL res = BeginPath(context);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
CubicPaths paths;
if (!SkPathToCubicPaths(&paths, path))
@@ -86,6 +87,7 @@ 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]));
@@ -96,14 +98,14 @@ void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) {
points.push_back(SkPointToPOINT(point->p[2]));
points.push_back(SkPointToPOINT(point->p[3]));
}
- SkASSERT((points.size() - 1) % 3 == 0);
+ DCHECK_EQ((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()));
- SkASSERT(res != 0);
+ DCHECK_NE(res, 0);
if (res == 0)
break;
}
@@ -112,7 +114,7 @@ void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) {
AbortPath(context);
} else {
res = EndPath(context);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
}
}
@@ -181,7 +183,7 @@ bool PlatformDeviceWin::SkPathToCubicPaths(CubicPaths* paths,
break;
}
}
- SkASSERT(current_path);
+ DCHECK(current_path);
if (!current_path) {
paths->clear();
return false;
@@ -218,9 +220,9 @@ void PlatformDeviceWin::LoadClippingRegionToDC(HDC context,
hrgn = PathToRegion(context);
}
int result = SelectClipRgn(context, hrgn);
- SkASSERT(result != ERROR);
+ DCHECK_NE(result, ERROR);
result = DeleteObject(hrgn);
- SkASSERT(result != 0);
+ DCHECK_NE(result, 0);
}
} // namespace skia
diff --git a/skia/ext/skia_utils_win.cc b/skia/ext/skia_utils_win.cc
index 59bef6d..f6c8006 100644
--- a/skia/ext/skia_utils_win.cc
+++ b/skia/ext/skia_utils_win.cc
@@ -2,27 +2,18 @@
// 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 {
-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(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);
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);
@@ -57,7 +48,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.
- SkASSERT((0xFF == SkColorGetA(color)) || (0 == color));
+ DCHECK((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 ea5542f..33ac265 100644
--- a/skia/ext/vector_canvas.cc
+++ b/skia/ext/vector_canvas.cc
@@ -4,6 +4,7 @@
#include "skia/ext/vector_canvas.h"
+#include "base/logging.h"
#include "skia/ext/vector_device.h"
namespace skia {
@@ -13,8 +14,7 @@ VectorCanvas::VectorCanvas() {
VectorCanvas::VectorCanvas(HDC dc, int width, int height) {
bool initialized = initialize(dc, width, height);
- if (!initialized)
- __debugbreak();
+ CHECK(initialized);
}
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.
- SkASSERT(false);
+ NOTREACHED();
return NULL;
}
SkDevice* VectorCanvas::createDevice(SkBitmap::Config config,
int width, int height,
bool is_opaque, bool isForLayer) {
- SkASSERT(config == SkBitmap::kARGB_8888_Config);
+ DCHECK(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.
- SkASSERT(false);
+ NOTREACHED();
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.
- SkASSERT(shared_section);
+ DCHECK(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 897ffd4..6b61b58 100644
--- a/skia/ext/vector_canvas.h
+++ b/skia/ext/vector_canvas.h
@@ -37,9 +37,7 @@ class VectorCanvas : public PlatformCanvasWin {
// Returns true if the top device is vector based and not bitmap based.
bool IsTopDeviceVectorial() const;
- // Copy & assign are not supported.
- VectorCanvas(const VectorCanvas&);
- const VectorCanvas& operator=(const VectorCanvas&);
+ DISALLOW_COPY_AND_ASSIGN(VectorCanvas);
};
} // namespace skia
diff --git a/skia/ext/vector_device.cc b/skia/ext/vector_device.cc
index 295101f..98aaeff 100644
--- a/skia/ext/vector_device.cc
+++ b/skia/ext/vector_device.cc
@@ -5,6 +5,8 @@
#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"
@@ -53,8 +55,8 @@ VectorDevice::VectorDevice(HDC dc, const SkBitmap& bitmap)
}
VectorDevice::~VectorDevice() {
- SkASSERT(previous_brush_ == NULL);
- SkASSERT(previous_pen_ == NULL);
+ DCHECK(previous_brush_ == NULL);
+ DCHECK(previous_pen_ == NULL);
}
@@ -75,7 +77,7 @@ void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
return;
if (mode == SkCanvas::kPoints_PointMode) {
- SkASSERT(false);
+ NOTREACHED();
return;
}
@@ -87,7 +89,7 @@ void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
switch (mode) {
case SkCanvas::kLines_PointMode:
if (count % 2) {
- SkASSERT(false);
+ NOTREACHED();
return;
}
for (size_t i = 0; i < count / 2; ++i) {
@@ -102,7 +104,7 @@ void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
}
break;
default:
- SkASSERT(false);
+ NOTREACHED();
return;
}
// Draw the calculated path.
@@ -137,7 +139,7 @@ void VectorDevice::drawRect(const SkDraw& draw, const SkRect& rect,
SkScalarRound(rect.fTop),
SkScalarRound(rect.fRight),
SkScalarRound(rect.fBottom))) {
- SkASSERT(false);
+ NOTREACHED();
}
Cleanup();
}
@@ -166,21 +168,21 @@ void VectorDevice::drawPath(const SkDraw& draw, const SkPath& path,
switch (paint.getStyle()) {
case SkPaint::kFill_Style: {
BOOL res = StrokeAndFillPath(dc);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
break;
}
case SkPaint::kStroke_Style: {
BOOL res = StrokePath(dc);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
break;
}
case SkPaint::kStrokeAndFill_Style: {
BOOL res = StrokeAndFillPath(dc);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
break;
}
default:
- SkASSERT(false);
+ NOTREACHED();
break;
}
Cleanup();
@@ -215,14 +217,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.
- SkASSERT(false);
+ NOTREACHED();
}
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.
- SkASSERT(false);
+ NOTREACHED();
}
void VectorDevice::drawTextOnPath(const SkDraw& draw, const void* text,
@@ -230,7 +232,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.
- SkASSERT(false);
+ NOTREACHED();
}
void VectorDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
@@ -240,7 +242,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.
- SkASSERT(false);
+ NOTREACHED();
}
void VectorDevice::drawDevice(const SkDraw& draw, SkDevice* device, int x,
@@ -307,25 +309,25 @@ bool VectorDevice::ApplyPaint(const SkPaint& paint) {
// SkShader::CreateBitmapShader
// SkGradientShader::CreateRadial
// SkGradientShader::CreateLinear
- // SkASSERT(!paint.getShader());
+ // DCHECK(!paint.getShader());
// http://b/1106647 Implement loopers and mask filter. Looper currently in
// use:
// SkBlurDrawLooper is used for shadows.
- // SkASSERT(!paint.getLooper());
- // SkASSERT(!paint.getMaskFilter());
+ // DCHECK(!paint.getLooper());
+ // DCHECK(!paint.getMaskFilter());
// http://b/1165900 Implement xfermode.
- // SkASSERT(!paint.getXfermode());
+ // DCHECK(!paint.getXfermode());
// The path effect should be processed before arriving here.
- SkASSERT(!paint.getPathEffect());
+ DCHECK(!paint.getPathEffect());
// These aren't used in the code. Verify this assumption.
- SkASSERT(!paint.getColorFilter());
- SkASSERT(!paint.getRasterizer());
+ DCHECK(!paint.getColorFilter());
+ DCHECK(!paint.getRasterizer());
// Reuse code to load Win32 Fonts.
- SkASSERT(!paint.getTypeface());
+ DCHECK(!paint.getTypeface());
return true;
}
@@ -339,7 +341,7 @@ void VectorDevice::setMatrixClip(const SkMatrix& transform,
}
void VectorDevice::drawToHDC(HDC dc, int x, int y, const RECT* src_rect) {
- SkASSERT(false);
+ NOTREACHED();
}
void VectorDevice::LoadClipRegion() {
@@ -349,7 +351,7 @@ void VectorDevice::LoadClipRegion() {
}
bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) {
- SkASSERT(previous_brush_ == NULL);
+ DCHECK(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.
@@ -357,7 +359,7 @@ bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) {
if (!use_brush) {
// Set the transparency.
if (0 == SetBkMode(hdc_, TRANSPARENT)) {
- SkASSERT(false);
+ NOTREACHED();
return false;
}
@@ -368,7 +370,7 @@ bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) {
// Set the opacity.
if (0 == SetBkMode(hdc_, OPAQUE)) {
- SkASSERT(false);
+ NOTREACHED();
return false;
}
@@ -379,7 +381,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) {
- SkASSERT(previous_pen_ == NULL);
+ DCHECK(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.
@@ -403,13 +405,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);
- SkASSERT(pen != NULL);
+ DCHECK(pen != NULL);
previous_pen_ = SelectObject(pen);
if (previous_pen_ == NULL)
return false;
if (!SetMiterLimit(hdc_, stroke_miter, NULL)) {
- SkASSERT(false);
+ NOTREACHED();
return false;
}
return true;
@@ -421,7 +423,7 @@ void VectorDevice::Cleanup() {
previous_brush_ = NULL;
if (result) {
BOOL res = DeleteObject(result);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
}
}
if (previous_pen_) {
@@ -429,7 +431,7 @@ void VectorDevice::Cleanup() {
previous_pen_ = NULL;
if (result) {
BOOL res = DeleteObject(result);
- SkASSERT(res != 0);
+ DCHECK(res != 0);
}
}
// Remove any loaded path from the context.
@@ -438,7 +440,7 @@ void VectorDevice::Cleanup() {
HGDIOBJ VectorDevice::SelectObject(HGDIOBJ object) {
HGDIOBJ result = ::SelectObject(hdc_, object);
- SkASSERT(result != HGDI_ERROR);
+ DCHECK(result != HGDI_ERROR);
if (result == HGDI_ERROR)
return NULL;
return result;
@@ -448,7 +450,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.
- SkASSERT(false);
+ NOTREACHED();
use_brush = false;
}
@@ -459,7 +461,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.
- SkASSERT(false);
+ NOTREACHED();
use_pen = false;
}
@@ -478,7 +480,7 @@ bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) {
pen_style |= PS_JOIN_BEVEL;
break;
default:
- SkASSERT(false);
+ NOTREACHED();
break;
}
switch (paint.getStrokeCap()) {
@@ -495,7 +497,7 @@ bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) {
pen_style |= PS_ENDCAP_SQUARE;
break;
default:
- SkASSERT(false);
+ NOTREACHED();
break;
}
@@ -508,7 +510,7 @@ bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) {
void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y,
const SkPaint& paint) {
- unsigned char alpha = paint.getAlpha();
+ uint8 alpha = paint.getAlpha();
if (alpha == 0)
return;
@@ -535,10 +537,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);
- SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
+ DCHECK_EQ(bitmap.getConfig(), SkBitmap::kARGB_8888_Config);
const uint32_t* pixels = static_cast<const uint32_t*>(bitmap.getPixels());
if (pixels == NULL) {
- SkASSERT(false);
+ NOTREACHED();
return;
}
@@ -560,14 +562,15 @@ 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.
- HDC bitmap_dc = ::CreateCompatibleDC(dc);
+ ScopedHDC bitmap_dc(::CreateCompatibleDC(dc));
void* bits = NULL;
- HBITMAP hbitmap = ::CreateDIBSection(
+ ScopedBitmap 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());
- SkASSERT(hbitmap);
+ DCHECK(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
@@ -577,7 +580,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);
- SkASSERT(result);
+ DCHECK(result);
// Note that this function expect premultiplied colors (!)
BLENDFUNCTION blend_function = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA};
result = GdiAlphaBlend(dc,
@@ -587,13 +590,9 @@ void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y,
0, 0, // Source origin.
src_size_x, src_size_y, // Source size.
blend_function);
- SkASSERT(result);
+ DCHECK(result);
result = SetStretchBltMode(dc, previous_mode);
- SkASSERT(result);
-
- ::SelectObject(bitmap_dc, static_cast<HBITMAP>(old_bitmap));
- DeleteObject(hbitmap);
- DeleteDC(bitmap_dc);
+ DCHECK(result);
} else {
BOOL result = StretchDIBits(dc,
x, y, // Destination origin.
@@ -604,7 +603,7 @@ void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y,
reinterpret_cast<const BITMAPINFO*>(&hdr),
DIB_RGB_COLORS,
SRCCOPY);
- SkASSERT(result);
+ DCHECK(result);
}
Cleanup();
}
diff --git a/skia/ext/vector_device.h b/skia/ext/vector_device.h
index ccd4333..5fdb9a0 100644
--- a/skia/ext/vector_device.h
+++ b/skia/ext/vector_device.h
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SKIA_EXT_VECTOR_DEVICE_H_
-#define SKIA_EXT_VECTOR_DEVICE_H_
+#ifndef VectorDevice_h
+#define VectorDevice_h
+#include "base/basictypes.h"
#include "skia/ext/platform_device_win.h"
#include "SkMatrix.h"
#include "SkRegion.h"
@@ -109,12 +110,10 @@ class VectorDevice : public PlatformDeviceWin {
// Previously selected pen before the current drawing.
HGDIOBJ previous_pen_;
- // Copy & assign are not supported.
- VectorDevice(const VectorDevice&);
- const VectorDevice& operator=(const VectorDevice&);
+ DISALLOW_COPY_AND_ASSIGN(VectorDevice);
};
} // namespace skia
-#endif // SKIA_EXT_VECTOR_DEVICE_H_
+#endif // VectorDevice_h