1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/pdf/SkPDFShader.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkPDFShader_DEFINED 1.14 +#define SkPDFShader_DEFINED 1.15 + 1.16 +#include "SkPDFStream.h" 1.17 +#include "SkPDFTypes.h" 1.18 +#include "SkMatrix.h" 1.19 +#include "SkRefCnt.h" 1.20 +#include "SkShader.h" 1.21 + 1.22 +class SkObjRef; 1.23 +class SkPDFCatalog; 1.24 + 1.25 +/** \class SkPDFShader 1.26 + 1.27 + In PDF parlance, this is a pattern, used in place of a color when the 1.28 + pattern color space is selected. 1.29 +*/ 1.30 + 1.31 +class SkPDFShader { 1.32 +public: 1.33 + /** Get the PDF shader for the passed SkShader. If the SkShader is 1.34 + * invalid in some way, returns NULL. The reference count of 1.35 + * the object is incremented and it is the caller's responsibility to 1.36 + * unreference it when done. This is needed to accommodate the weak 1.37 + * reference pattern used when the returned object is new and has no 1.38 + * other references. 1.39 + * @param shader The SkShader to emulate. 1.40 + * @param matrix The current transform. (PDF shaders are absolutely 1.41 + * positioned, relative to where the page is drawn.) 1.42 + * @param surfceBBox The bounding box of the drawing surface (with matrix 1.43 + * already applied). 1.44 + */ 1.45 + static SkPDFObject* GetPDFShader(const SkShader& shader, 1.46 + const SkMatrix& matrix, 1.47 + const SkIRect& surfaceBBox); 1.48 + 1.49 +protected: 1.50 + class State; 1.51 + 1.52 + class ShaderCanonicalEntry { 1.53 + public: 1.54 + ShaderCanonicalEntry(SkPDFObject* pdfShader, const State* state); 1.55 + bool operator==(const ShaderCanonicalEntry& b) const; 1.56 + 1.57 + SkPDFObject* fPDFShader; 1.58 + const State* fState; 1.59 + }; 1.60 + // This should be made a hash table if performance is a problem. 1.61 + static SkTDArray<ShaderCanonicalEntry>& CanonicalShaders(); 1.62 + static SkBaseMutex& CanonicalShadersMutex(); 1.63 + 1.64 + // This is an internal method. 1.65 + // CanonicalShadersMutex() should already be acquired. 1.66 + // This also takes ownership of shaderState. 1.67 + static SkPDFObject* GetPDFShaderByState(State* shaderState); 1.68 + static void RemoveShader(SkPDFObject* shader); 1.69 + 1.70 + SkPDFShader(); 1.71 + virtual ~SkPDFShader() {}; 1.72 + 1.73 + virtual bool isValid() = 0; 1.74 +}; 1.75 + 1.76 +#endif