158b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com/*
258b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com * Copyright 2012 Google Inc.
358b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com *
458b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com * Use of this source code is governed by a BSD-style license that can be
558b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com * found in the LICENSE file.
658b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com */
758b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
858b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com#ifndef GrSWMaskHelper_DEFINED
958b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com#define GrSWMaskHelper_DEFINED
1058b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
1139ef7fb885d7be648b9f0ecd027bc400d1213cecbsalomon#include "SkAutoPixmapStorage.h"
1258b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com#include "SkDraw.h"
13a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "SkMatrix.h"
1458b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com#include "SkRasterClip.h"
1558b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com#include "SkRegion.h"
16a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org#include "SkTypes.h"
1758b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
188acedde5970ce70de6d9791ffeda87a65af4ed07bsalomonclass GrShape;
19f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osmanclass GrTextureProxy;
2058b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
2158b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com/**
2258b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com * The GrSWMaskHelper helps generate clip masks using the software rendering
23366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com * path. It is intended to be used as:
24366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com *
25366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com *   GrSWMaskHelper helper(context);
26366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com *   helper.init(...);
27366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com *
28366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com *      draw one or more paths/rects specifying the required boolean ops
29366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com *
30f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osman *   toTextureProxy();   // to get it from the internal bitmap to the GPU
31366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com *
32366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com * The result of this process will be the final mask (on the GPU) in the
33366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com * upper left hand corner of the texture.
3458b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com */
35e3beb6bd7de7fa211681abbb0be58e80b19885e0commit-bot@chromium.orgclass GrSWMaskHelper : SkNoncopyable {
3658b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.compublic:
37f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osman    GrSWMaskHelper(SkAutoPixmapStorage* pixels = nullptr)
38f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osman            : fPixels(pixels ? pixels : &fPixelsStorage) { }
3958b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
40366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com    // set up the internal state in preparation for draws. Since many masks
41d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    // may be accumulated in the helper during creation, "resultBounds"
42d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    // allows the caller to specify the region of interest - to limit the
439837740dd59fa2461e5d6e6cd36cdc93567b5717robertphillips    // amount of work.
44740775606d0af0a03ceebba7428d88fb279c5d94Brian Salomon    bool init(const SkIRect& resultBounds);
4558b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
46366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com    // Draw a single rect into the accumulation bitmap using the specified op
47740775606d0af0a03ceebba7428d88fb279c5d94Brian Salomon    void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
4858b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
49366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com    // Draw a single path into the accumuation bitmap using the specified op
50740775606d0af0a03ceebba7428d88fb279c5d94Brian Salomon    void drawShape(const GrShape&, const SkMatrix& matrix, SkRegion::Op op, GrAA, uint8_t alpha);
5158b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
52d3749485db2de966a80e39669a49192fc7c0bd9dRobert Phillips    sk_sp<GrTextureProxy> toTextureProxy(GrContext*, SkBackingFit fit);
5358b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
54366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com    // Reset the internal bitmap
55366f1c6a09f63c76e78145cb08028f66062f31fdrobertphillips@google.com    void clear(uint8_t alpha) {
56f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osman        fPixels->erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF));
5758b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com    }
5858b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
5958b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.comprivate:
60740775606d0af0a03ceebba7428d88fb279c5d94Brian Salomon    SkVector             fTranslate;
61f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osman    SkAutoPixmapStorage* fPixels;
62f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osman    SkAutoPixmapStorage  fPixelsStorage;
63f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osman    SkDraw               fDraw;
64f9810666bd40db8fb1650e6c727c1a83b8090136Brian Osman    SkRasterClip         fRasterClip;
6558b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
66a0b40280a49a8a43af7929ead3b3489951c58501commit-bot@chromium.org    typedef SkNoncopyable INHERITED;
6758b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com};
6858b20215f6d88b7e1cacae0b76226fced5109293robertphillips@google.com
69fe65943d309dc687f618d16e394dff3baa526426robertphillips@google.com#endif // GrSWMaskHelper_DEFINED
70