michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkPDFShader_DEFINED michael@0: #define SkPDFShader_DEFINED michael@0: michael@0: #include "SkPDFStream.h" michael@0: #include "SkPDFTypes.h" michael@0: #include "SkMatrix.h" michael@0: #include "SkRefCnt.h" michael@0: #include "SkShader.h" michael@0: michael@0: class SkObjRef; michael@0: class SkPDFCatalog; michael@0: michael@0: /** \class SkPDFShader michael@0: michael@0: In PDF parlance, this is a pattern, used in place of a color when the michael@0: pattern color space is selected. michael@0: */ michael@0: michael@0: class SkPDFShader { michael@0: public: michael@0: /** Get the PDF shader for the passed SkShader. If the SkShader is michael@0: * invalid in some way, returns NULL. The reference count of michael@0: * the object is incremented and it is the caller's responsibility to michael@0: * unreference it when done. This is needed to accommodate the weak michael@0: * reference pattern used when the returned object is new and has no michael@0: * other references. michael@0: * @param shader The SkShader to emulate. michael@0: * @param matrix The current transform. (PDF shaders are absolutely michael@0: * positioned, relative to where the page is drawn.) michael@0: * @param surfceBBox The bounding box of the drawing surface (with matrix michael@0: * already applied). michael@0: */ michael@0: static SkPDFObject* GetPDFShader(const SkShader& shader, michael@0: const SkMatrix& matrix, michael@0: const SkIRect& surfaceBBox); michael@0: michael@0: protected: michael@0: class State; michael@0: michael@0: class ShaderCanonicalEntry { michael@0: public: michael@0: ShaderCanonicalEntry(SkPDFObject* pdfShader, const State* state); michael@0: bool operator==(const ShaderCanonicalEntry& b) const; michael@0: michael@0: SkPDFObject* fPDFShader; michael@0: const State* fState; michael@0: }; michael@0: // This should be made a hash table if performance is a problem. michael@0: static SkTDArray& CanonicalShaders(); michael@0: static SkBaseMutex& CanonicalShadersMutex(); michael@0: michael@0: // This is an internal method. michael@0: // CanonicalShadersMutex() should already be acquired. michael@0: // This also takes ownership of shaderState. michael@0: static SkPDFObject* GetPDFShaderByState(State* shaderState); michael@0: static void RemoveShader(SkPDFObject* shader); michael@0: michael@0: SkPDFShader(); michael@0: virtual ~SkPDFShader() {}; michael@0: michael@0: virtual bool isValid() = 0; michael@0: }; michael@0: michael@0: #endif