blob: 20df0bca2e168caf3436a6e11e1f4bbb8e0c34d2 [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
reed80c772b2015-07-30 18:58:23 -070017enum {
18 kNeedNewImageUniqueID = 0
19};
20
reed@google.com58b21ec2012-07-30 18:20:12 +000021class SkImage_Base : public SkImage {
22public:
reedaf3fbfc2015-10-04 11:28:36 -070023 SkImage_Base(int width, int height, uint32_t uniqueID);
fmalita3b0d5322015-09-18 08:07:31 -070024 virtual ~SkImage_Base();
reed4af267b2014-11-21 08:46:37 -080025
reedaf3fbfc2015-10-04 11:28:36 -070026 virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const { return nullptr; }
reed@google.com4f7c6152014-02-06 14:11:56 +000027
reed96472de2014-12-10 09:53:42 -080028 // Default impl calls onDraw
29 virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
30 int srcX, int srcY) const;
reed86e90fa2015-09-01 12:22:32 -070031
reed85d91782015-09-10 14:33:38 -070032 virtual GrTexture* peekTexture() const { return nullptr; }
skia.committer@gmail.com3e50e992013-05-21 07:01:40 +000033
reed@google.com4b0757b2013-05-20 16:33:41 +000034 // return a read-only copy of the pixels. We promise to not modify them,
35 // but only inspect them (or encode them).
reed746f31f2015-09-16 12:53:29 -070036 virtual bool getROPixels(SkBitmap*) const = 0;
37
38 // Caller must call unref when they are done.
39 virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0;
reed@google.com58b21ec2012-07-30 18:20:12 +000040
reed476506d2015-09-28 10:26:51 -070041 virtual SkImage* onNewSubset(const SkIRect&) const = 0;
reed856e9d92015-09-30 12:21:45 -070042
halcanary96fcdcc2015-08-27 07:41:13 -070043 virtual SkData* onRefEncoded() const { return nullptr; }
reedf803da12015-01-23 05:58:07 -080044
reed3c065112015-07-08 12:46:22 -070045 virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;
46
fmalitaddbbdda2015-08-20 08:47:26 -070047 virtual bool onIsLazyGenerated() const { return false; }
48
fmalita3b0d5322015-09-18 08:07:31 -070049 // Call when this image is part of the key to a resourcecache entry. This allows the cache
50 // to know automatically those entries can be purged when this SkImage deleted.
51 void notifyAddedToCache() const {
52 fAddedToCache.store(true);
53 }
54
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055private:
fmalita3b0d5322015-09-18 08:07:31 -070056 // Set true by caches when they cache content that's derived from the current pixels.
57 mutable SkAtomic<bool> fAddedToCache;
58
reed@google.com58b21ec2012-07-30 18:20:12 +000059 typedef SkImage INHERITED;
60};
61
reed4af267b2014-11-21 08:46:37 -080062static inline SkImage_Base* as_IB(SkImage* image) {
63 return static_cast<SkImage_Base*>(image);
64}
65
66static inline const SkImage_Base* as_IB(const SkImage* image) {
67 return static_cast<const SkImage_Base*>(image);
68}
69
reed@google.com58b21ec2012-07-30 18:20:12 +000070#endif