blob: ebf1891bed527e0cf5a7847bd2f713b6351db49f [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
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +000041 void setTileWidth(int width) {
42 fTileWidth = width;
43 }
44
45 int getTileWidth() const {
46 return fTileWidth;
47 }
48
49 void setTileHeight(int height) {
50 fTileHeight = height;
51 }
52
53 int getTileHeight() const {
54 return fTileHeight;
55 }
56
57 void setTileWidthPercentage(double percentage) {
58 fTileWidthPercentage = percentage;
59 }
60
61 double getTileWidthPercentage() {
62 return fTileWidthPercentage;
63 }
64
65 void setTileHeightPercentage(double percentage) {
66 fTileHeightPercentage = percentage;
67 }
68
69 double getTileHeightPercentage() {
70 return fTileHeightPercentage;
71 }
72
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000073 ~TiledPictureRenderer();
74
75private:
76 struct TileInfo {
77 SkBitmap* fBitmap;
78 SkCanvas* fCanvas;
79 };
80
81 int fTileWidth;
82 int fTileHeight;
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +000083 double fTileWidthPercentage;
84 double fTileHeightPercentage;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000085
86 SkTDArray<TileInfo> fTiles;
87
88 // Clips the tile to an area that is completely in what the SkPicture says is the
89 // drawn-to area. This is mostly important for tiles on the right and bottom edges
90 // as they may go over this area and the picture may have some commands that
91 // draw outside of this area and so should not actually be written.
92 static void clipTile(const SkPicture& picture, const TileInfo& tile);
93 void addTile(const SkPicture& picture, int tile_x_start, int tile_y_start);
94 void setupTiles(const SkPicture& picture);
95 // We manually delete the tiles instead of having a destructor on TileInfo as
96 // the destructor on TileInfo will be during a realloc. This would result in
97 // the canvases and bitmaps being prematurely deleted.
98 void deleteTiles();
99 void copyTilesToCanvas(const SkPicture& pict, SkCanvas* destination);
100};
101
102}
103
104#endif // PictureRenderer_DEFINED