blob: a3b86c5d94af01a0ff2e48c08cea1f448088a226 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkImage.h"
12#include "include/core/SkSurface.h"
Mike Klein015c8992018-08-09 12:23:19 -040013#include <atomic>
reed4af267b2014-11-21 08:46:37 -080014
reed0e7bddf2016-08-17 13:24:05 -070015#if SK_SUPPORT_GPU
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/private/GrTextureProxy.h"
17#include "include/private/SkTDArray.h"
Robert Phillips646e4292017-06-13 12:44:56 -040018
Robert Phillips9338c602019-02-19 12:52:29 -050019class GrRecordingContext;
Greg Daniel2ad08202018-09-07 09:13:36 -040020class GrTexture;
reed0e7bddf2016-08-17 13:24:05 -070021#endif
22
bungemanf3c15b72015-08-19 11:56:48 -070023#include <new>
24
Brian Salomon2bbdcc42017-09-07 12:36:34 -040025class GrSamplerState;
Robert Phillipsb4a8eac2018-09-21 08:26:33 -040026class SkCachedData;
Jim Van Verthe24b5872018-10-29 16:26:02 -040027struct SkYUVASizeInfo;
bsalomonafa95e22015-10-12 10:39:46 -070028
reed80c772b2015-07-30 18:58:23 -070029enum {
30 kNeedNewImageUniqueID = 0
31};
32
reed@google.com58b21ec2012-07-30 18:20:12 +000033class SkImage_Base : public SkImage {
34public:
fmalita3b0d5322015-09-18 08:07:31 -070035 virtual ~SkImage_Base();
reed4af267b2014-11-21 08:46:37 -080036
Mike Reedf2c73642018-05-29 15:41:27 -040037 virtual SkIRect onGetSubset() const {
38 return { 0, 0, this->width(), this->height() };
39 }
40
reed6ceeebd2016-03-09 14:26:26 -080041 virtual bool onPeekPixels(SkPixmap*) const { return false; }
reed@google.com4f7c6152014-02-06 14:11:56 +000042
reedf1ac1822016-08-01 11:24:14 -070043 virtual const SkBitmap* onPeekBitmap() const { return nullptr; }
44
reed96472de2014-12-10 09:53:42 -080045 virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
Matt Sarette2609592017-01-10 09:29:04 -050046 int srcX, int srcY, CachingHint) const = 0;
reed86e90fa2015-09-01 12:22:32 -070047
Robert Phillips87444052017-06-23 14:09:30 -040048 virtual GrContext* context() const { return nullptr; }
Robert Phillipsfe0963c2019-02-07 13:25:07 -050049
reed0e7bddf2016-08-17 13:24:05 -070050#if SK_SUPPORT_GPU
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040051 virtual GrSemaphoresSubmitted onFlush(GrContext* context, const GrFlushInfo&) {
52 return GrSemaphoresSubmitted::kNo;
53 }
54
Robert Phillips193c4212019-03-04 12:18:53 -050055 // Return the proxy if this image is backed by a single proxy. For YUVA images, this
56 // will return nullptr unless the YUVA planes have been converted to RGBA in which case
57 // that single backing proxy will be returned.
Robert Phillips0ae6faa2017-03-21 16:22:00 -040058 virtual GrTextureProxy* peekProxy() const { return nullptr; }
Robert Phillips6603a172019-03-05 12:35:44 -050059 virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*) const { return nullptr; }
Robert Phillips9338c602019-02-19 12:52:29 -050060 virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, const GrSamplerState&,
Robert Phillipsb726d582017-03-09 16:36:32 -050061 SkScalar scaleAdjust[2]) const = 0;
Robert Phillips6603a172019-03-05 12:35:44 -050062 virtual sk_sp<GrTextureProxy> refPinnedTextureProxy(GrRecordingContext*,
63 uint32_t* uniqueID) const {
Robert Phillips3798c862017-03-27 11:08:16 -040064 return nullptr;
65 }
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040066 virtual bool isYUVA() const { return false; }
Robert Phillips0ae6faa2017-03-21 16:22:00 -040067 virtual GrTexture* onGetTexture() const { return nullptr; }
reed0e7bddf2016-08-17 13:24:05 -070068#endif
Robert Phillips8caf85f2018-04-05 09:30:38 -040069 virtual GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
70 GrSurfaceOrigin* origin) const;
71
reed@google.com4b0757b2013-05-20 16:33:41 +000072 // return a read-only copy of the pixels. We promise to not modify them,
73 // but only inspect them (or encode them).
Brian Osmane50cdf02018-10-19 13:02:14 -040074 virtual bool getROPixels(SkBitmap*, CachingHint = kAllow_CachingHint) const = 0;
reed746f31f2015-09-16 12:53:29 -070075
Robert Phillips6603a172019-03-05 12:35:44 -050076 virtual sk_sp<SkImage> onMakeSubset(GrRecordingContext*, const SkIRect&) const = 0;
reed856e9d92015-09-30 12:21:45 -070077
Jim Van Verthe24b5872018-10-29 16:26:02 -040078 virtual sk_sp<SkCachedData> getPlanes(SkYUVASizeInfo*, SkYUVAIndex[4],
Jim Van Verth8f11e432018-10-18 14:36:59 -040079 SkYUVColorSpace*, const void* planes[4]);
Ben Wagnerbdf54332018-05-15 14:12:14 -040080 virtual sk_sp<SkData> onRefEncoded() const { return nullptr; }
reedf803da12015-01-23 05:58:07 -080081
Cary Clark4f5a79c2018-02-07 15:51:00 -050082 virtual bool onAsLegacyBitmap(SkBitmap*) const;
reed3c065112015-07-08 12:46:22 -070083
Mike Reed7f1d0202017-05-08 16:13:39 -040084 // True for picture-backed and codec-backed
fmalitaddbbdda2015-08-20 08:47:26 -070085 virtual bool onIsLazyGenerated() const { return false; }
86
Jim Van Verth21bd60d2018-10-12 15:00:20 -040087 // True for images instantiated in GPU memory
88 virtual bool onIsTextureBacked() const { return false; }
89
fmalita3b0d5322015-09-18 08:07:31 -070090 // Call when this image is part of the key to a resourcecache entry. This allows the cache
91 // to know automatically those entries can be purged when this SkImage deleted.
Brian Osman3a160732018-10-15 15:32:06 -040092 virtual void notifyAddedToRasterCache() const {
Mike Reed30301c42018-07-19 09:39:21 -040093 fAddedToRasterCache.store(true);
fmalita3b0d5322015-09-18 08:07:31 -070094 }
95
Brian Osman5bbd0762017-05-08 11:07:42 -040096 virtual bool onIsValid(GrContext*) const = 0;
97
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -050098 virtual bool onPinAsTexture(GrContext*) const { return false; }
reed2d5b7142016-08-17 11:12:33 -070099 virtual void onUnpinAsTexture(GrContext*) const {}
100
Robert Phillips6603a172019-03-05 12:35:44 -0500101 virtual sk_sp<SkImage> onMakeColorTypeAndColorSpace(GrRecordingContext*,
102 SkColorType, sk_sp<SkColorSpace>) const = 0;
Florin Malitaf7beee72017-05-26 12:54:32 -0400103protected:
Brian Salomon5ad6fd32019-03-21 15:30:08 -0400104 SkImage_Base(const SkImageInfo& info, uint32_t uniqueID);
Matt Sarett6de13102017-03-14 14:10:48 -0400105
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000106private:
fmalita3b0d5322015-09-18 08:07:31 -0700107 // Set true by caches when they cache content that's derived from the current pixels.
Mike Klein015c8992018-08-09 12:23:19 -0400108 mutable std::atomic<bool> fAddedToRasterCache;
fmalita3b0d5322015-09-18 08:07:31 -0700109
reed@google.com58b21ec2012-07-30 18:20:12 +0000110 typedef SkImage INHERITED;
111};
112
reed6ceeebd2016-03-09 14:26:26 -0800113static inline SkImage_Base* as_IB(SkImage* image) {
reed4af267b2014-11-21 08:46:37 -0800114 return static_cast<SkImage_Base*>(image);
115}
116
reed9ce9d672016-03-17 10:51:11 -0700117static inline SkImage_Base* as_IB(const sk_sp<SkImage>& image) {
118 return static_cast<SkImage_Base*>(image.get());
119}
120
reed4af267b2014-11-21 08:46:37 -0800121static inline const SkImage_Base* as_IB(const SkImage* image) {
122 return static_cast<const SkImage_Base*>(image);
123}
124
reed@google.com58b21ec2012-07-30 18:20:12 +0000125#endif