Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: src/core/SkBBoxRecord.cpp

Issue 12545009: Adding option in SkPicture to record device-space bounds of draw commands. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkBBoxRecord.cpp
===================================================================
--- src/core/SkBBoxRecord.cpp (revision 9110)
+++ src/core/SkBBoxRecord.cpp (working copy)
@@ -9,24 +9,47 @@
#include "SkBBoxRecord.h"
void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawOval(rect, paint);
+ this->handleBBox(offset);
+#else
if (this->transformBounds(rect, &paint)) {
INHERITED::drawOval(rect, paint);
}
+#endif
}
void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawRRect(rrect, paint);
+ this->handleBBox(offset);
+#else
if (this->transformBounds(rrect.rect(), &paint)) {
INHERITED::drawRRect(rrect, paint);
}
+#endif
}
void SkBBoxRecord::drawRect(const SkRect& rect, const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawRect(rect, paint);
+ this->handleBBox(offset);
+#else
if (this->transformBounds(rect, &paint)) {
INHERITED::drawRect(rect, paint);
}
+#endif
}
void SkBBoxRecord::drawPath(const SkPath& path, const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawPath(path, paint);
+ this->handleBBox(offset);
+#else
if (path.isInverseFillType()) {
// If path is inverse filled, use the current clip bounds as the
// path's device-space bounding box.
@@ -38,10 +61,16 @@
} else if (this->transformBounds(path.getBounds(), &paint)) {
INHERITED::drawPath(path, paint);
}
+#endif
}
void SkBBoxRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawPoints(mode, count, pts, paint);
Tom Hudson 2013/05/14 17:00:49 I like the way this file starts losing special cas
+ this->handleBBox(offset);
+#else
SkRect bbox;
bbox.set(pts, count);
// Small min width value, just to ensure hairline point bounding boxes aren't empty.
@@ -59,26 +88,44 @@
if (this->transformBounds(bbox, &paint)) {
INHERITED::drawPoints(mode, count, pts, paint);
}
+#endif
}
void SkBBoxRecord::drawPaint(const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawPaint(paint);
+ this->handleBBox(offset);
+#else
SkRect bbox;
if (this->getClipBounds(&bbox)) {
if (this->transformBounds(bbox, &paint)) {
INHERITED::drawPaint(paint);
}
}
+#endif
}
void SkBBoxRecord::clear(SkColor color) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::clear(color);
+ this->handleBBox(offset);
+#else
SkISize size = this->getDeviceSize();
SkRect bbox = {0, 0, SkIntToScalar(size.width()), SkIntToScalar(size.height())};
this->handleBBox(bbox);
INHERITED::clear(color);
+#endif
}
void SkBBoxRecord::drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawText(text, byteLength, x, y, paint);
+ this->handleBBox(offset);
+#else
SkRect bbox;
paint.measureText(text, byteLength, &bbox);
SkPaint::FontMetrics metrics;
@@ -123,42 +170,72 @@
if (this->transformBounds(bbox, &paint)) {
INHERITED::drawText(text, byteLength, x, y, paint);
}
+#endif
}
void SkBBoxRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawBitmap(bitmap, left, top, paint);
+ this->handleBBox(offset);
+#else
SkRect bbox = {left, top, left + bitmap.width(), top + bitmap.height()};
if (this->transformBounds(bbox, paint)) {
INHERITED::drawBitmap(bitmap, left, top, paint);
}
+#endif
}
void SkBBoxRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
const SkRect& dst, const SkPaint* paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawBitmapRectToRect(bitmap, src, dst, paint);
+ this->handleBBox(offset);
+#else
if (this->transformBounds(dst, paint)) {
INHERITED::drawBitmapRectToRect(bitmap, src, dst, paint);
}
+#endif
}
void SkBBoxRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& mat,
const SkPaint* paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawBitmapMatrix(bitmap, mat, paint);
+ this->handleBBox(offset);
+#else
SkMatrix m = mat;
SkRect bbox = {0, 0, SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())};
m.mapRect(&bbox);
if (this->transformBounds(bbox, paint)) {
INHERITED::drawBitmapMatrix(bitmap, mat, paint);
}
+#endif
}
void SkBBoxRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawBitmapNine(bitmap, center, dst, paint);
+ this->handleBBox(offset);
+#else
if (this->transformBounds(dst, paint)) {
INHERITED::drawBitmapNine(bitmap, center, dst, paint);
}
+#endif
}
void SkBBoxRecord::drawPosText(const void* text, size_t byteLength,
const SkPoint pos[], const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawPosText(text, byteLength, pos, paint);
+ this->handleBBox(offset);
+#else
SkRect bbox;
bbox.set(pos, paint.countText(text, byteLength));
SkPaint::FontMetrics metrics;
@@ -174,10 +251,16 @@
if (this->transformBounds(bbox, &paint)) {
INHERITED::drawPosText(text, byteLength, pos, paint);
}
+#endif
}
void SkBBoxRecord::drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
SkScalar constY, const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint);
+ this->handleBBox(offset);
+#else
SkRect bbox;
size_t numChars = paint.countText(text, byteLength);
if (numChars > 0) {
@@ -207,19 +290,31 @@
}
}
INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint);
+#endif
}
void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
const SkPaint* paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawSprite(bitmap, left, top, paint);
+ this->handleBBox(offset);
+#else
SkRect bbox;
bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height()));
this->handleBBox(bbox); // directly call handleBBox, matrix is ignored
INHERITED::drawSprite(bitmap, left, top, paint);
+#endif
}
void SkBBoxRecord::drawTextOnPath(const void* text, size_t byteLength,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawTextOnPath(text, byteLength, path, matrix, paint);
+ this->handleBBox(offset);
+#else
SkRect bbox = path.getBounds();
SkPaint::FontMetrics metrics;
paint.getFontMetrics(&metrics);
@@ -234,6 +329,7 @@
if (this->transformBounds(bbox, &paint)) {
INHERITED::drawTextOnPath(text, byteLength, path, matrix, paint);
}
+#endif
}
void SkBBoxRecord::drawVertices(VertexMode mode, int vertexCount,
@@ -241,22 +337,36 @@
const SkColor colors[], SkXfermode* xfer,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawVertices(mode, vertexCount, vertices, texs,
+ colors, xfer, indices, indexCount, paint);
+ this->handleBBox(offset);
+#else
SkRect bbox;
bbox.set(vertices, vertexCount);
if (this->transformBounds(bbox, &paint)) {
INHERITED::drawVertices(mode, vertexCount, vertices, texs,
colors, xfer, indices, indexCount, paint);
}
+#endif
}
void SkBBoxRecord::drawPicture(SkPicture& picture) {
+#if SK_RECORD_BOUNDS_IN_PICTURE
+ uint32_t offset = this->writeStream().size();
+ INHERITED::drawPicture(picture);
+ this->handleBBox(offset);
+#else
if (picture.width() > 0 && picture.height() > 0 &&
this->transformBounds(SkRect::MakeWH(picture.width(), picture.height()), NULL)) {
INHERITED::drawPicture(picture);
}
+#endif
}
bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) {
+#if !(SK_RECORD_BOUNDS_IN_PICTURE)
SkRect outBounds = bounds;
outBounds.sort();
@@ -279,6 +389,8 @@
this->handleBBox(outBounds);
return true;
}
-
+#else
+ SkASSERT(0);
+#endif
return false;
}
« no previous file with comments | « src/core/SkBBoxRecord.h ('k') | src/core/SkCanvas.cpp » ('j') | src/core/SkCanvas.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698