blob: c91430e5bd4ca88b9dfcbb414bb09ec85ea6cb29 [file] [log] [blame]
reed@google.com58b21ec2012-07-30 18:20:12 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkImage_Base_DEFINED
9#define SkImage_Base_DEFINED
10
herbb906daf2015-09-29 09:37:59 -070011#include "SkAtomics.h"
reed@google.com58b21ec2012-07-30 18:20:12 +000012#include "SkImage.h"
reed4af267b2014-11-21 08:46:37 -080013#include "SkSurface.h"
14
bungemanf3c15b72015-08-19 11:56:48 -070015#include <new>
16
bsalomonafa95e22015-10-12 10:39:46 -070017class GrTextureParams;
18
reed80c772b2015-07-30 18:58:23 -070019enum {
20 kNeedNewImageUniqueID = 0
21};
22
reed@google.com58b21ec2012-07-30 18:20:12 +000023class SkImage_Base : public SkImage {
24public:
reedaf3fbfc2015-10-04 11:28:36 -070025 SkImage_Base(int width, int height, uint32_t uniqueID);
fmalita3b0d5322015-09-18 08:07:31 -070026 virtual ~SkImage_Base();
reed4af267b2014-11-21 08:46:37 -080027
reedaf3fbfc2015-10-04 11:28:36 -070028 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const { return nullptr; }
reed@google.com4f7c6152014-02-06 14:11:56 +000029
reed96472de2014-12-10 09:53:42 -080030 // Default impl calls onDraw
31 virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
reed09553032015-11-23 12:32:16 -080032 int srcX, int srcY, CachingHint) const;
reed86e90fa2015-09-01 12:22:32 -070033
reed85d91782015-09-10 14:33:38 -070034 virtual GrTexture* peekTexture() const { return nullptr; }
skia.committer@gmail.com3e50e992013-05-21 07:01:40 +000035
reed@google.com4b0757b2013-05-20 16:33:41 +000036 // return a read-only copy of the pixels. We promise to not modify them,
37 // but only inspect them (or encode them).
reed09553032015-11-23 12:32:16 -080038 virtual bool getROPixels(SkBitmap*, CachingHint = kAllow_CachingHint) const = 0;
reed746f31f2015-09-16 12:53:29 -070039
reed88d064d2015-10-12 11:30:02 -070040 virtual SkImage* onApplyFilter(SkImageFilter*, SkIPoint* offset,
41 bool forceResultToOriginalSize) const;
42
43 virtual SkSurface* onNewSurface(const SkImageInfo& info) const {
44 return SkSurface::NewRaster(info);
45 }
46
reed746f31f2015-09-16 12:53:29 -070047 // Caller must call unref when they are done.
bsalomonafa95e22015-10-12 10:39:46 -070048 virtual GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const = 0;
reed@google.com58b21ec2012-07-30 18:20:12 +000049
reed476506d2015-09-28 10:26:51 -070050 virtual SkImage* onNewSubset(const SkIRect&) const = 0;
reed856e9d92015-09-30 12:21:45 -070051
halcanary96fcdcc2015-08-27 07:41:13 -070052 virtual SkData* onRefEncoded() const { return nullptr; }
reedf803da12015-01-23 05:58:07 -080053
reed3c065112015-07-08 12:46:22 -070054 virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;
55
fmalitaddbbdda2015-08-20 08:47:26 -070056 virtual bool onIsLazyGenerated() const { return false; }
57
fmalita3b0d5322015-09-18 08:07:31 -070058 // Call when this image is part of the key to a resourcecache entry. This allows the cache
59 // to know automatically those entries can be purged when this SkImage deleted.
60 void notifyAddedToCache() const {
61 fAddedToCache.store(true);
62 }
63
rmistry@google.comfbfcd562012-08-23 18:09:54 +000064private:
fmalita3b0d5322015-09-18 08:07:31 -070065 // Set true by caches when they cache content that's derived from the current pixels.
66 mutable SkAtomic<bool> fAddedToCache;
67
reed@google.com58b21ec2012-07-30 18:20:12 +000068 typedef SkImage INHERITED;
69};
70
reed4af267b2014-11-21 08:46:37 -080071static inline SkImage_Base* as_IB(SkImage* image) {
72 return static_cast<SkImage_Base*>(image);
73}
74
75static inline const SkImage_Base* as_IB(const SkImage* image) {
76 return static_cast<const SkImage_Base*>(image);
77}
78
reed@google.com58b21ec2012-07-30 18:20:12 +000079#endif