epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 10 | #ifndef SkPDFShader_DEFINED |
| 11 | #define SkPDFShader_DEFINED |
| 12 | |
| 13 | #include "SkPDFStream.h" |
| 14 | #include "SkPDFTypes.h" |
| 15 | #include "SkMatrix.h" |
| 16 | #include "SkRefCnt.h" |
| 17 | #include "SkShader.h" |
| 18 | |
| 19 | class SkObjRef; |
| 20 | class SkPDFCatalog; |
| 21 | |
| 22 | /** \class SkPDFShader |
| 23 | |
| 24 | In PDF parlance, this is a pattern, used in place of a color when the |
| 25 | pattern color space is selected. |
| 26 | */ |
| 27 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 28 | class SkPDFShader { |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 29 | public: |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 30 | /** Get the PDF shader for the passed SkShader. If the SkShader is |
| 31 | * invalid in some way, returns NULL. The reference count of |
| 32 | * the object is incremented and it is the caller's responsibility to |
| 33 | * unreference it when done. This is needed to accommodate the weak |
| 34 | * reference pattern used when the returned object is new and has no |
| 35 | * other references. |
| 36 | * @param shader The SkShader to emulate. |
| 37 | * @param matrix The current transform. (PDF shaders are absolutely |
| 38 | * positioned, relative to where the page is drawn.) |
| 39 | * @param surfceBBox The bounding box of the drawing surface (with matrix |
| 40 | * already applied). |
| 41 | */ |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 42 | static SkPDFObject* GetPDFShader(const SkShader& shader, |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 43 | const SkMatrix& matrix, |
| 44 | const SkIRect& surfaceBBox); |
| 45 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 46 | protected: |
| 47 | class State; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 48 | |
| 49 | class ShaderCanonicalEntry { |
| 50 | public: |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 51 | ShaderCanonicalEntry(SkPDFObject* pdfShader, const State* state); |
| 52 | bool operator==(const ShaderCanonicalEntry& b) const; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 53 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 54 | SkPDFObject* fPDFShader; |
| 55 | const State* fState; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 56 | }; |
| 57 | // This should be made a hash table if performance is a problem. |
vandebo@chromium.org | b88cfe5 | 2011-07-18 18:40:32 +0000 | [diff] [blame] | 58 | static SkTDArray<ShaderCanonicalEntry>& CanonicalShaders(); |
digit@google.com | 1771cbf | 2012-01-26 21:26:40 +0000 | [diff] [blame] | 59 | static SkBaseMutex& CanonicalShadersMutex(); |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 60 | |
| 61 | // This is an internal method. |
| 62 | // CanonicalShadersMutex() should already be acquired. |
| 63 | // This also takes ownership of shaderState. |
| 64 | static SkPDFObject* GetPDFShaderByState(State* shaderState); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 65 | static void RemoveShader(SkPDFObject* shader); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 66 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 67 | SkPDFShader(); |
robertphillips@google.com | 05141c2 | 2012-04-27 12:54:01 +0000 | [diff] [blame] | 68 | virtual ~SkPDFShader() {}; |
vandebo@chromium.org | 386dfc0 | 2012-04-17 22:31:52 +0000 | [diff] [blame] | 69 | |
| 70 | virtual bool isValid() = 0; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | #endif |