skia2/include/images/SkImageRef.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

107 lines
3.5 KiB
C++

/*
* Copyright 2008 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 SkImageRef_DEFINED
#define SkImageRef_DEFINED
#include "SkPixelRef.h"
#include "SkBitmap.h"
#include "SkImageDecoder.h"
#include "SkString.h"
class SkImageRefPool;
class SkStream;
// define this to enable dumping whenever we add/remove/purge an imageref
//#define DUMP_IMAGEREF_LIFECYCLE
class SkImageRef : public SkPixelRef {
public:
/** Create a new imageref from a stream. NOTE: the stream is not copied, but
since it may be accessed from another thread, the caller must ensure
that this imageref is the only owner of the stream. i.e. - sole
ownership of the stream object is transferred to this imageref object.
@param stream The stream containing the encoded image data. This may be
retained (by calling ref()), so the caller should not
explicitly delete it.
@param config The preferred config of the decoded bitmap.
@param sampleSize Requested sampleSize for decoding. Defaults to 1.
*/
SkImageRef(SkStream*, SkBitmap::Config config, int sampleSize = 1);
virtual ~SkImageRef();
/** this value is passed onto the decoder. Default is true
*/
void setDitherImage(bool dither) { fDoDither = dither; }
/** Return true if the image can be decoded. If so, and bitmap is non-null,
call its setConfig() with the corresponding values, but explicitly will
not set its pixels or colortable. Use SkPixelRef::lockPixels() for that.
If there has been an error decoding the bitmap, this will return false
and ignore the bitmap parameter.
*/
bool getInfo(SkBitmap* bm);
/** Return true if the image can be decoded and is opaque. Calling this
method will decode and set the pixels in the specified bitmap and
sets the isOpaque flag.
*/
bool isOpaque(SkBitmap* bm);
SkImageDecoderFactory* getDecoderFactory() const { return fFactory; }
// returns the factory parameter
SkImageDecoderFactory* setDecoderFactory(SkImageDecoderFactory*);
// overrides
virtual void flatten(SkFlattenableWriteBuffer&) const;
protected:
/** Override if you want to install a custom allocator.
When this is called we will have already acquired the mutex!
*/
virtual bool onDecode(SkImageDecoder* codec, SkStream*, SkBitmap*,
SkBitmap::Config, SkImageDecoder::Mode);
/* Overrides from SkPixelRef
When these are called, we will have already acquired the mutex!
*/
virtual void* onLockPixels(SkColorTable**);
// override this in your subclass to clean up when we're unlocking pixels
virtual void onUnlockPixels();
SkImageRef(SkFlattenableReadBuffer&);
SkBitmap fBitmap;
private:
SkStream* setStream(SkStream*);
// called with mutex already held. returns true if the bitmap is in the
// requested state (or further, i.e. has pixels)
bool prepareBitmap(SkImageDecoder::Mode);
SkImageDecoderFactory* fFactory; // may be null
SkStream* fStream;
SkBitmap::Config fConfig;
int fSampleSize;
bool fDoDither;
bool fErrorInDecoding;
friend class SkImageRefPool;
SkImageRef* fPrev, *fNext;
size_t ramUsed() const;
typedef SkPixelRef INHERITED;
};
#endif