1
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef SkBBoxRecord_DEFINED
10#define SkBBoxRecord_DEFINED
11
12#include "SkPictureRecord.h"
13
14/**
15  * This is an abstract SkPictureRecord subclass that intercepts draw calls and computes an
16  * axis-aligned bounding box for each draw that it sees, subclasses implement handleBBox()
17  * which will be called every time we get a new bounding box.
18  */
19class SkBBoxRecord : public SkPictureRecord {
20public:
21
22    SkBBoxRecord(const SkISize& size, uint32_t recordFlags)
23        : INHERITED(size, recordFlags) {
24    }
25    virtual ~SkBBoxRecord() { }
26
27    /**
28     * This is called each time we get a bounding box, it will be axis-aligned,
29     * in device coordinates, and expanded to include stroking, shadows, etc.
30     */
31    virtual void handleBBox(const SkRect& bbox) = 0;
32
33    virtual void drawOval(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
34    virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
35    virtual void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
36    virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
37    virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
38                            const SkPaint& paint) SK_OVERRIDE;
39    virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
40    virtual void clear(SkColor) SK_OVERRIDE;
41    virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
42                            const SkPaint* paint = NULL) SK_OVERRIDE;
43    virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
44                                      const SkRect& dst, const SkPaint* paint,
45                                      DrawBitmapRectFlags flags) SK_OVERRIDE;
46    virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& mat,
47                                  const SkPaint* paint) SK_OVERRIDE;
48    virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
49                                const SkRect& dst, const SkPaint* paint) SK_OVERRIDE;
50    virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
51                            const SkPaint* paint) SK_OVERRIDE;
52    virtual void drawVertices(VertexMode mode, int vertexCount,
53                              const SkPoint vertices[], const SkPoint texs[],
54                              const SkColor colors[], SkXfermode* xfer,
55                              const uint16_t indices[], int indexCount,
56                              const SkPaint& paint) SK_OVERRIDE;
57
58protected:
59    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
60    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
61                            const SkPaint&) SK_OVERRIDE;
62    virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
63                               const SkPaint&) SK_OVERRIDE;
64    virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
65                                SkScalar constY, const SkPaint&) SK_OVERRIDE;
66    virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
67                                  const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
68    virtual void onDrawPicture(const SkPicture* picture) SK_OVERRIDE;
69
70private:
71    /**
72     * Takes a bounding box in current canvas view space, accounts for stroking and effects, and
73     * computes an axis-aligned bounding box in device coordinates, then passes it to handleBBox()
74     * returns false if the draw is completely clipped out, and may safely be ignored.
75     **/
76    bool transformBounds(const SkRect& bounds, const SkPaint* paint);
77
78    typedef SkPictureRecord INHERITED;
79};
80
81#endif
82