19f0147143fbedba10bdae496d812a14995304924reed
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
99f0147143fbedba10bdae496d812a14995304924reed
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
67ba28d03e94dc221d6a803bf2a84a420b9159255cdjsollen@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerRasterizer)
6843e9f20f4b5eecb2335e26461b5c4c84f2e3bcd2reed@google.com
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
701bd6f7de5273f56a361a5b29ac9b448a525f0b9bdominikg    SkLayerRasterizer();
719f0147143fbedba10bdae496d812a14995304924reed    SkLayerRasterizer(SkDeque* layers);
729fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
739f0147143fbedba10bdae496d812a14995304924reed    SkLayerRasterizer(SkReadBuffer&);
749fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#endif
758b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // override from SkRasterizer
788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onRasterize(const SkPath& path, const SkMatrix& matrix,
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             const SkIRect* clipBounds,
80fdba4041c350b72791a1844ff0bc0af28cbb4199reed@google.com                             SkMask* mask, SkMask::CreateMode mode) const;
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
83f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org    const SkDeque* const fLayers;
84f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org
85f792a1b20747f769b28906a4b00fd67691ce8d0bcommit-bot@chromium.org    static SkDeque* ReadLayers(SkReadBuffer& buffer);
868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
876573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org    friend class LayerRasterizerTester;
886573ce70e609f19923cea401d4ca3ea1528a78f1commit-bot@chromium.org
898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    typedef SkRasterizer INHERITED;
908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
93