blob: 350569c99367bc9f924249fcf3a4ba2874b13514 [file] [log] [blame]
vandebo@chromium.orgda912d62011-03-08 18:31:02 +00001/*
2 * Copyright (C) 2011 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkPDFShader_DEFINED
18#define SkPDFShader_DEFINED
19
20#include "SkPDFStream.h"
21#include "SkPDFTypes.h"
22#include "SkMatrix.h"
23#include "SkRefCnt.h"
24#include "SkShader.h"
25
26class SkObjRef;
27class SkPDFCatalog;
28
29/** \class SkPDFShader
30
31 In PDF parlance, this is a pattern, used in place of a color when the
32 pattern color space is selected.
33*/
34
vandebo@chromium.org421d6442011-07-20 17:39:01 +000035class SkPDFShader {
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000036public:
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000037 /** Get the PDF shader for the passed SkShader. If the SkShader is
38 * invalid in some way, returns NULL. The reference count of
39 * the object is incremented and it is the caller's responsibility to
40 * unreference it when done. This is needed to accommodate the weak
41 * reference pattern used when the returned object is new and has no
42 * other references.
43 * @param shader The SkShader to emulate.
44 * @param matrix The current transform. (PDF shaders are absolutely
45 * positioned, relative to where the page is drawn.)
46 * @param surfceBBox The bounding box of the drawing surface (with matrix
47 * already applied).
48 */
vandebo@chromium.org421d6442011-07-20 17:39:01 +000049 static SkPDFObject* GetPDFShader(const SkShader& shader,
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000050 const SkMatrix& matrix,
51 const SkIRect& surfaceBBox);
52
vandebo@chromium.org421d6442011-07-20 17:39:01 +000053protected:
54 class State;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000055
56 class ShaderCanonicalEntry {
57 public:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000058 ShaderCanonicalEntry(SkPDFObject* pdfShader, const State* state);
59 bool operator==(const ShaderCanonicalEntry& b) const;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000060
vandebo@chromium.org421d6442011-07-20 17:39:01 +000061 SkPDFObject* fPDFShader;
62 const State* fState;
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000063 };
64 // This should be made a hash table if performance is a problem.
vandebo@chromium.orgb88cfe52011-07-18 18:40:32 +000065 static SkTDArray<ShaderCanonicalEntry>& CanonicalShaders();
66 static SkMutex& CanonicalShadersMutex();
vandebo@chromium.org421d6442011-07-20 17:39:01 +000067 static void RemoveShader(SkPDFObject* shader);
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000068
vandebo@chromium.org421d6442011-07-20 17:39:01 +000069 SkPDFShader();
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000070};
71
72#endif