1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkBBoxRecord.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2012 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 +#ifndef SkBBoxRecord_DEFINED 1.13 +#define SkBBoxRecord_DEFINED 1.14 + 1.15 +#include "SkPictureRecord.h" 1.16 + 1.17 +/** 1.18 + * This is an abstract SkPictureRecord subclass that intercepts draw calls and computes an 1.19 + * axis-aligned bounding box for each draw that it sees, subclasses implement handleBBox() 1.20 + * which will be called every time we get a new bounding box. 1.21 + */ 1.22 +class SkBBoxRecord : public SkPictureRecord { 1.23 +public: 1.24 + 1.25 + SkBBoxRecord(const SkISize& size, uint32_t recordFlags) : INHERITED(size, recordFlags) {} 1.26 + virtual ~SkBBoxRecord() { } 1.27 + 1.28 + /** 1.29 + * This is called each time we get a bounding box, it will be axis-aligned, 1.30 + * in device coordinates, and expanded to include stroking, shadows, etc. 1.31 + */ 1.32 + virtual void handleBBox(const SkRect& bbox) = 0; 1.33 + 1.34 + virtual void drawOval(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE; 1.35 + virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE; 1.36 + virtual void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE; 1.37 + virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE; 1.38 + virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], 1.39 + const SkPaint& paint) SK_OVERRIDE; 1.40 + virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; 1.41 + virtual void clear(SkColor) SK_OVERRIDE; 1.42 + virtual void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, 1.43 + const SkPaint& paint) SK_OVERRIDE; 1.44 + virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 1.45 + const SkPaint* paint = NULL) SK_OVERRIDE; 1.46 + virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 1.47 + const SkRect& dst, const SkPaint* paint, 1.48 + DrawBitmapRectFlags flags) SK_OVERRIDE; 1.49 + virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& mat, 1.50 + const SkPaint* paint) SK_OVERRIDE; 1.51 + virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, 1.52 + const SkRect& dst, const SkPaint* paint) SK_OVERRIDE; 1.53 + virtual void drawPosText(const void* text, size_t byteLength, 1.54 + const SkPoint pos[], const SkPaint& paint) SK_OVERRIDE; 1.55 + virtual void drawPosTextH(const void* text, size_t byteLength, 1.56 + const SkScalar xpos[], SkScalar constY, 1.57 + const SkPaint& paint) SK_OVERRIDE; 1.58 + virtual void drawSprite(const SkBitmap& bitmap, int left, int top, 1.59 + const SkPaint* paint) SK_OVERRIDE; 1.60 + virtual void drawTextOnPath(const void* text, size_t byteLength, 1.61 + const SkPath& path, const SkMatrix* matrix, 1.62 + const SkPaint& paint) SK_OVERRIDE; 1.63 + virtual void drawVertices(VertexMode mode, int vertexCount, 1.64 + const SkPoint vertices[], const SkPoint texs[], 1.65 + const SkColor colors[], SkXfermode* xfer, 1.66 + const uint16_t indices[], int indexCount, 1.67 + const SkPaint& paint) SK_OVERRIDE; 1.68 + virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; 1.69 + 1.70 +protected: 1.71 + virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; 1.72 + 1.73 +private: 1.74 + /** 1.75 + * Takes a bounding box in current canvas view space, accounts for stroking and effects, and 1.76 + * computes an axis-aligned bounding box in device coordinates, then passes it to handleBBox() 1.77 + * returns false if the draw is completely clipped out, and may safely be ignored. 1.78 + **/ 1.79 + bool transformBounds(const SkRect& bounds, const SkPaint* paint); 1.80 + 1.81 + typedef SkPictureRecord INHERITED; 1.82 +}; 1.83 + 1.84 +#endif