| keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 14 | class SkBitmap; |
| 15 | class SkCanvas; |
| 16 | class SkPicture; |
| 17 | |
| 18 | namespace sk_tools { |
| 19 | |
| 20 | class PictureRenderer : public SkRefCnt { |
| 21 | public: |
| 22 | virtual void init(const SkPicture& pict){} |
| 23 | virtual void render(SkPicture* pict, SkCanvas* canvas) = 0; |
| 24 | }; |
| 25 | |
| 26 | class PipePictureRenderer : public PictureRenderer { |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 27 | public: |
| keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 28 | virtual void render(SkPicture* pict, SkCanvas* canvas); |
| 29 | }; |
| 30 | |
| 31 | class SimplePictureRenderer : public PictureRenderer { |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 32 | public: |
| keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 33 | virtual void render (SkPicture* pict, SkCanvas* canvas); |
| 34 | }; |
| 35 | |
| 36 | class TiledPictureRenderer : public PictureRenderer { |
| 37 | public: |
| 38 | TiledPictureRenderer(); |
| 39 | |
| 40 | virtual void init(const SkPicture& pict); |
| 41 | virtual void render(SkPicture* pict, SkCanvas* canvas); |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 42 | void drawTiles(SkPicture* pict); |
| keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 43 | |
| keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 44 | void setTileWidth(int width) { |
| 45 | fTileWidth = width; |
| 46 | } |
| 47 | |
| 48 | int getTileWidth() const { |
| 49 | return fTileWidth; |
| 50 | } |
| 51 | |
| 52 | void setTileHeight(int height) { |
| 53 | fTileHeight = height; |
| 54 | } |
| 55 | |
| 56 | int getTileHeight() const { |
| 57 | return fTileHeight; |
| 58 | } |
| 59 | |
| 60 | void setTileWidthPercentage(double percentage) { |
| 61 | fTileWidthPercentage = percentage; |
| 62 | } |
| 63 | |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 64 | double getTileWidthPercentage() const { |
| keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 65 | return fTileWidthPercentage; |
| 66 | } |
| 67 | |
| 68 | void setTileHeightPercentage(double percentage) { |
| 69 | fTileHeightPercentage = percentage; |
| 70 | } |
| 71 | |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 72 | double getTileHeightPercentage() const { |
| keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 73 | return fTileHeightPercentage; |
| 74 | } |
| 75 | |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 76 | int numTiles() const { |
| 77 | return fTiles.count(); |
| 78 | } |
| 79 | |
| keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 80 | ~TiledPictureRenderer(); |
| 81 | |
| 82 | private: |
| 83 | struct TileInfo { |
| 84 | SkBitmap* fBitmap; |
| 85 | SkCanvas* fCanvas; |
| 86 | }; |
| 87 | |
| 88 | int fTileWidth; |
| 89 | int fTileHeight; |
| keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 90 | double fTileWidthPercentage; |
| 91 | double fTileHeightPercentage; |
| keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 92 | |
| 93 | SkTDArray<TileInfo> fTiles; |
| 94 | |
| 95 | // Clips the tile to an area that is completely in what the SkPicture says is the |
| 96 | // drawn-to area. This is mostly important for tiles on the right and bottom edges |
| 97 | // as they may go over this area and the picture may have some commands that |
| 98 | // draw outside of this area and so should not actually be written. |
| 99 | static void clipTile(const SkPicture& picture, const TileInfo& tile); |
| 100 | void addTile(const SkPicture& picture, int tile_x_start, int tile_y_start); |
| 101 | void setupTiles(const SkPicture& picture); |
| 102 | // We manually delete the tiles instead of having a destructor on TileInfo as |
| 103 | // the destructor on TileInfo will be during a realloc. This would result in |
| 104 | // the canvases and bitmaps being prematurely deleted. |
| 105 | void deleteTiles(); |
| 106 | void copyTilesToCanvas(const SkPicture& pict, SkCanvas* destination); |
| 107 | }; |
| 108 | |
| 109 | } |
| 110 | |
| 111 | #endif // PictureRenderer_DEFINED |