1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkLayerRasterizer_DEFINED 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkLayerRasterizer_DEFINED 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRasterizer.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDeque.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScalar.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPaint; 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 196806fe87e0b39e283291c1a1c7d1d864230aa2aatfarina@chromium.orgclass SK_API SkLayerRasterizer : public SkRasterizer { 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkLayerRasterizer(); 22fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 23f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org class SK_API Builder { 24f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org public: 25f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org Builder(); 26f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org ~Builder(); 27f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org 28f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org void addLayer(const SkPaint& paint) { 29f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org this->addLayer(paint, 0, 0); 30f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org } 31f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org 32f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org /** 33f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org * Add a new layer (above any previous layers) to the rasterizer. 34f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org * The layer will extract those fields that affect the mask from 35f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org * the specified paint, but will not retain a reference to the paint 36f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org * object itself, so it may be reused without danger of side-effects. 37f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org */ 38f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy); 39f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org 40f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org /** 41f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org * Pass queue of layers on to newly created layer rasterizer and return it. The builder 4265044bfe021e9c0023d78080583e9acb3bdb5ce7scroggo * *cannot* be used any more after calling this function. If no layers have been added, 4365044bfe021e9c0023d78080583e9acb3bdb5ce7scroggo * returns NULL. 446573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * 4565044bfe021e9c0023d78080583e9acb3bdb5ce7scroggo * The caller is responsible for calling unref() on the returned object, if non NULL. 46f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org */ 47f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org SkLayerRasterizer* detachRasterizer(); 48f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org 496573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org /** 506573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * Create and return a new immutable SkLayerRasterizer that contains a shapshot of the 516573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * layers that were added to the Builder, without modifying the Builder. The Builder 526573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * *may* be used after calling this function. It will continue to hold any layers 536573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * previously added, so consecutive calls to this function will return identical objects, 546573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * and objects returned by future calls to this function contain all the layers in 5565044bfe021e9c0023d78080583e9acb3bdb5ce7scroggo * previously returned objects. If no layers have been added, returns NULL. 566573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * 576573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * Future calls to addLayer will not affect rasterizers previously returned by this call. 586573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org * 5965044bfe021e9c0023d78080583e9acb3bdb5ce7scroggo * The caller is responsible for calling unref() on the returned object, if non NULL. 606573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org */ 616573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org SkLayerRasterizer* snapshotRasterizer() const; 626573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org 63f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org private: 64f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org SkDeque* fLayers; 65f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org }; 66f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org 67f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API 686b919c353727f72342a20a7aa4ded9c022f5d816mike@reedtribe.org void addLayer(const SkPaint& paint) { 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->addLayer(paint, 0, 0); 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 72fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com /** Add a new layer (above any previous layers) to the rasterizer. 73fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com The layer will extract those fields that affect the mask from 74fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com the specified paint, but will not retain a reference to the paint 75fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com object itself, so it may be reused without danger of side-effects. 76fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com */ 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addLayer(const SkPaint& paint, SkScalar dx, SkScalar dy); 78f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org#endif 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 80ba28d03e94dc221d6a803bf2a84a420b9159255cdjsollen@google.com SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer) 8143e9f20f4b5eecb2335e26461b5c4c84f2e3bcd2reed@google.com 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 83f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org SkLayerRasterizer(SkDeque* layers); 848b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org SkLayerRasterizer(SkReadBuffer&); 858b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override from SkRasterizer 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix, 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect* clipBounds, 90fdba4041c350b72791a1844ff0bc0af28cbb4199reed@google.com SkMask* mask, SkMask::CreateMode mode) const; 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 92f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API 93f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.orgpublic: 94f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org#endif 95f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org SkLayerRasterizer(); 96f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 98f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API 99f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org SkDeque* fLayers; 100f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org#else 101f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org const SkDeque* const fLayers; 102f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org#endif 103f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org 104f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org static SkDeque* ReadLayers(SkReadBuffer& buffer); 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1066573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org friend class LayerRasterizerTester; 1076573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkRasterizer INHERITED; 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 112