1 : /*
2 : * Copyright 2011 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 SkImageFilter_DEFINED
9 : #define SkImageFilter_DEFINED
10 :
11 : #include "SkFlattenable.h"
12 :
13 : class SkBitmap;
14 : class SkDevice;
15 : class SkMatrix;
16 : struct SkPoint;
17 :
18 : /**
19 : * Experimental.
20 : *
21 : * Base class for image filters. If one is installed in the paint, then
22 : * all drawing occurs as usual, but it is as if the drawing happened into an
23 : * offscreen (before the xfermode is applied). This offscreen bitmap will
24 : * then be handed to the imagefilter, who in turn creates a new bitmap which
25 : * is what will finally be drawn to the device (using the original xfermode).
26 : *
27 : * THIS SIGNATURE IS TEMPORARY
28 : *
29 : * There are several weaknesses in this function signature:
30 : * 1. Does not expose the destination/target device, so filters that can draw
31 : * directly to it are unable to take advantage of that optimization.
32 : * 2. Does not expose a way to create a "compabitible" image (i.e. gpu -> gpu)
33 : * 3. As with #1, the filter is unable to "read" the dest (which would be slow)
34 : *
35 : * Therefore, we should not create any real dependencies on this API yet -- it
36 : * is being checked in as a check-point so we can explore these and other
37 : * considerations.
38 : */
39 0 : class SK_API SkImageFilter : public SkFlattenable {
40 : public:
41 0 : class Proxy {
42 : public:
43 : virtual SkDevice* createDevice(int width, int height) = 0;
44 :
45 : // returns true if the proxy handled the filter itself. if this returns
46 : // false then the filter's code will be called.
47 : virtual bool filterImage(SkImageFilter*, const SkBitmap& src,
48 : const SkMatrix& ctm,
49 : SkBitmap* result, SkIPoint* offset) = 0;
50 : };
51 :
52 : /**
53 : * Request a new (result) image to be created from the src image.
54 : * If the src has no pixels (isNull()) then the request just wants to
55 : * receive the config and width/height of the result.
56 : *
57 : * The matrix is the current matrix on the canvas.
58 : *
59 : * Offset is the amount to translate the resulting image relative to the
60 : * src when it is drawn.
61 : *
62 : * If the result image cannot be created, return false, in which case both
63 : * the result and offset parameters will be ignored by the caller.
64 : */
65 : bool filterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
66 : SkBitmap* result, SkIPoint* offset);
67 :
68 : /**
69 : * Given the src bounds of an image, this returns the bounds of the result
70 : * image after the filter has been applied.
71 : */
72 : bool filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst);
73 :
74 : /**
75 : * Experimental.
76 : *
77 : * If the filter can be expressed as a gaussian-blur, return true and
78 : * set the sigma to the values for horizontal and vertical.
79 : */
80 : virtual bool asABlur(SkSize* sigma) const;
81 :
82 : protected:
83 : SkImageFilter() {}
84 : explicit SkImageFilter(SkFlattenableReadBuffer& rb) : INHERITED(rb) {}
85 :
86 : // Default impl returns false
87 : virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
88 : SkBitmap* result, SkIPoint* offset);
89 : // Default impl copies src into dst and returns true
90 : virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*);
91 :
92 : private:
93 : typedef SkFlattenable INHERITED;
94 : };
95 :
96 : #endif
|