skia2/include/pdf/SkPDFGraphicState.h
epoger@google.com ec3ed6a5eb Automatic update of all copyright notices to reflect new license terms.
I have manually examined all of these diffs and restored a few files that
seem to require manual adjustment.

The following files still need to be modified manually, in a separate CL:

android_sample/SampleApp/AndroidManifest.xml
android_sample/SampleApp/res/layout/layout.xml
android_sample/SampleApp/res/menu/sample.xml
android_sample/SampleApp/res/values/strings.xml
android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java
android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java
experimental/CiCarbonSampleMain.c
experimental/CocoaDebugger/main.m
experimental/FileReaderApp/main.m
experimental/SimpleCocoaApp/main.m
experimental/iOSSampleApp/Shared/SkAlertPrompt.h
experimental/iOSSampleApp/Shared/SkAlertPrompt.m
experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig
experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig
experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig
gpu/src/android/GrGLDefaultInterface_android.cpp
gyp/common.gypi
gyp_skia
include/ports/SkHarfBuzzFont.h
include/views/SkOSWindow_wxwidgets.h
make.bat
make.py
src/opts/memset.arm.S
src/opts/memset16_neon.S
src/opts/memset32_neon.S
src/opts/opts_check_arm.cpp
src/ports/SkDebug_brew.cpp
src/ports/SkMemory_brew.cpp
src/ports/SkOSFile_brew.cpp
src/ports/SkXMLParser_empty.cpp
src/utils/ios/SkImageDecoder_iOS.mm
src/utils/ios/SkOSFile_iOS.mm
src/utils/ios/SkStream_NSData.mm
tests/FillPathTest.cpp
Review URL: http://codereview.appspot.com/4816058

git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00

102 lines
3.4 KiB
C++

/*
* Copyright 2010 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkPDFGraphicState_DEFINED
#define SkPDFGraphicState_DEFINED
#include "SkPaint.h"
#include "SkPDFTypes.h"
#include "SkTemplates.h"
#include "SkThread.h"
class SkPDFFormXObject;
/** \class SkPDFGraphicState
SkPaint objects roughly correspond to graphic state dictionaries that can
be installed. So that a given dictionary is only output to the pdf file
once, we want to canonicalize them. Static methods in this class manage
a weakly referenced set of SkPDFGraphicState objects: when the last
reference to a SkPDFGraphicState is removed, it removes itself from the
static set of objects.
*/
class SkPDFGraphicState : public SkPDFDict {
public:
virtual ~SkPDFGraphicState();
virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
// Override emitObject and getOutputSize so that we can populate
// the dictionary on demand.
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect);
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
/** Get the graphic state for the passed SkPaint. The reference count of
* the object is incremented and it is the caller's responsibility to
* unreference it when done. This is needed to accommodate the weak
* reference pattern used when the returned object is new and has no
* other references.
* @param paint The SkPaint to emulate.
*/
static SkPDFGraphicState* GetGraphicStateForPaint(const SkPaint& paint);
/** Make a graphic state that only sets the passed soft mask. The
* reference count of the object is incremented and it is the caller's
* responsibility to unreference it when done.
* @param sMask The form xobject to use as a soft mask.
* @param invert Indicates if the alpha of the sMask should be inverted.
*/
static SkPDFGraphicState* GetSMaskGraphicState(SkPDFFormXObject* sMask,
bool invert);
/** Get a graphic state that only unsets the soft mask. The reference
* count of the object is incremented and it is the caller's responsibility
* to unreference it when done. This is needed to accommodate the weak
* reference pattern used when the returned object is new and has no
* other references.
*/
static SkPDFGraphicState* GetNoSMaskGraphicState();
private:
const SkPaint fPaint;
SkTDArray<SkPDFObject*> fResources;
bool fPopulated;
bool fSMask;
class GSCanonicalEntry {
public:
SkPDFGraphicState* fGraphicState;
const SkPaint* fPaint;
bool operator==(const GSCanonicalEntry& b) const;
explicit GSCanonicalEntry(SkPDFGraphicState* gs)
: fGraphicState(gs),
fPaint(&gs->fPaint) {}
explicit GSCanonicalEntry(const SkPaint* paint)
: fGraphicState(NULL),
fPaint(paint) {}
};
// This should be made a hash table if performance is a problem.
static SkTDArray<GSCanonicalEntry>& CanonicalPaints();
static SkMutex& CanonicalPaintsMutex();
SkPDFGraphicState();
explicit SkPDFGraphicState(const SkPaint& paint);
void populateDict();
static SkPDFObject* GetInvertFunction();
static int Find(const SkPaint& paint);
};
#endif