blob: 5fa53c1a7c7f8f6c37baa0db61011ce473c1131d [file] [log] [blame]
keyar@chromium.org451bb9f2012-07-26 17:27:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef PictureRenderer_DEFINED
9#define PictureRenderer_DEFINED
10#include "SkTypes.h"
11#include "SkTDArray.h"
12#include "SkRefCnt.h"
13
14class SkBitmap;
15class SkCanvas;
16class SkPicture;
17
18namespace sk_tools {
19
20class PictureRenderer : public SkRefCnt {
21public:
22 virtual void init(const SkPicture& pict){}
23 virtual void render(SkPicture* pict, SkCanvas* canvas) = 0;
24};
25
26class PipePictureRenderer : public PictureRenderer {
27 virtual void render(SkPicture* pict, SkCanvas* canvas);
28};
29
30class SimplePictureRenderer : public PictureRenderer {
31 virtual void render (SkPicture* pict, SkCanvas* canvas);
32};
33
34class TiledPictureRenderer : public PictureRenderer {
35public:
36 TiledPictureRenderer();
37
38 virtual void init(const SkPicture& pict);
39 virtual void render(SkPicture* pict, SkCanvas* canvas);
40
41 ~TiledPictureRenderer();
42
43private:
44 struct TileInfo {
45 SkBitmap* fBitmap;
46 SkCanvas* fCanvas;
47 };
48
49 int fTileWidth;
50 int fTileHeight;
51
52 SkTDArray<TileInfo> fTiles;
53
54 // Clips the tile to an area that is completely in what the SkPicture says is the
55 // drawn-to area. This is mostly important for tiles on the right and bottom edges
56 // as they may go over this area and the picture may have some commands that
57 // draw outside of this area and so should not actually be written.
58 static void clipTile(const SkPicture& picture, const TileInfo& tile);
59 void addTile(const SkPicture& picture, int tile_x_start, int tile_y_start);
60 void setupTiles(const SkPicture& picture);
61 // We manually delete the tiles instead of having a destructor on TileInfo as
62 // the destructor on TileInfo will be during a realloc. This would result in
63 // the canvases and bitmaps being prematurely deleted.
64 void deleteTiles();
65 void copyTilesToCanvas(const SkPicture& pict, SkCanvas* destination);
66};
67
68}
69
70#endif // PictureRenderer_DEFINED