blob: 9cc28c317a73e37cc426edfabcd08e0d85e3bac5 [file] [log] [blame]
bsalomoneaaaf0b2015-01-23 08:08:04 -08001/*
2 * Copyright 2015 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_Gpu_DEFINED
9#define SkImage_Gpu_DEFINED
10
Brian Salomonc65aec92017-03-09 09:03:58 -050011#include "GrClip.h"
Hal Canary271d4952017-02-15 11:21:32 -050012#include "GrContext.h"
bsalomon3582d3e2015-02-13 14:20:05 -080013#include "GrGpuResourcePriv.h"
Robert Phillipsb726d582017-03-09 16:36:32 -050014#include "GrSurfaceProxyPriv.h"
Brian Salomonc65aec92017-03-09 09:03:58 -050015#include "SkAtomics.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -080016#include "SkBitmap.h"
herba7c9d632016-04-19 12:30:22 -070017#include "SkGr.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -080018#include "SkImagePriv.h"
Brian Salomonc65aec92017-03-09 09:03:58 -050019#include "SkImage_Base.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -080020#include "SkSurface.h"
21
Robert Phillips646e4292017-06-13 12:44:56 -040022class GrTexture;
23
bsalomoneaaaf0b2015-01-23 08:08:04 -080024class SkImage_Gpu : public SkImage_Base {
25public:
Robert Phillipsb726d582017-03-09 16:36:32 -050026 SkImage_Gpu(GrContext*, uint32_t uniqueID, SkAlphaType, sk_sp<GrTextureProxy>,
27 sk_sp<SkColorSpace>, SkBudgeted);
reed6f1216a2015-08-04 08:10:13 -070028 ~SkImage_Gpu() override;
bsalomoneaaaf0b2015-01-23 08:08:04 -080029
brianosman396fcdb2016-07-22 06:26:11 -070030 SkImageInfo onImageInfo() const override;
brianosman69c166d2016-08-17 14:01:05 -070031 SkAlphaType onAlphaType() const override { return fAlphaType; }
herba7c9d632016-04-19 12:30:22 -070032
Brian Osman61624f02016-12-09 14:51:59 -050033 bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
reed7fb4f8b2016-03-11 04:33:52 -080034 sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
reed85d91782015-09-10 14:33:38 -070035
Robert Phillips87444052017-06-23 14:09:30 -040036 GrContext* context() const override { return fContext; }
Robert Phillips0ae6faa2017-03-21 16:22:00 -040037 GrTextureProxy* peekProxy() const override {
38 return fProxy.get();
39 }
Robert Phillipsb726d582017-03-09 16:36:32 -050040 sk_sp<GrTextureProxy> asTextureProxyRef() const override {
41 return fProxy;
42 }
Brian Salomon2bbdcc42017-09-07 12:36:34 -040043 sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerState&, SkColorSpace*,
Robert Phillipsb726d582017-03-09 16:36:32 -050044 sk_sp<SkColorSpace>*,
45 SkScalar scaleAdjust[2]) const override;
Robert Phillips0ae6faa2017-03-21 16:22:00 -040046
Robert Phillips3798c862017-03-27 11:08:16 -040047 sk_sp<GrTextureProxy> refPinnedTextureProxy(uint32_t* uniqueID) const override {
reed2d5b7142016-08-17 11:12:33 -070048 *uniqueID = this->uniqueID();
Robert Phillips3798c862017-03-27 11:08:16 -040049 return fProxy;
reed2d5b7142016-08-17 11:12:33 -070050 }
Robert Phillips0ae6faa2017-03-21 16:22:00 -040051 GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO,
52 GrSurfaceOrigin* origin) const override;
53 GrTexture* onGetTexture() const override;
Robert Phillips538f1a32017-03-08 14:32:55 -050054
reed8b26b992015-05-07 15:36:17 -070055 bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
reed09553032015-11-23 12:32:16 -080056 int srcX, int srcY, CachingHint) const override;
reed88d064d2015-10-12 11:30:02 -070057
Robert Phillips2c862492017-01-18 10:08:39 -050058 sk_sp<SkColorSpace> refColorSpace() { return fColorSpace; }
59
Matt Sarett9f3dcb32017-05-04 08:53:32 -040060 sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, SkColorType,
61 SkTransferFunctionBehavior) const override;
Brian Osman63954c92017-03-14 12:07:12 -040062
Brian Osman5bbd0762017-05-08 11:07:42 -040063 bool onIsValid(GrContext*) const override;
64
bsalomoneaaaf0b2015-01-23 08:08:04 -080065private:
Robert Phillipsb726d582017-03-09 16:36:32 -050066 GrContext* fContext;
67 sk_sp<GrTextureProxy> fProxy;
bungeman6bd52842016-10-27 09:30:08 -070068 const SkAlphaType fAlphaType;
69 const SkBudgeted fBudgeted;
70 sk_sp<SkColorSpace> fColorSpace;
71 mutable SkAtomic<bool> fAddedRasterVersionToCache;
reed6f1216a2015-08-04 08:10:13 -070072
bsalomoneaaaf0b2015-01-23 08:08:04 -080073
74 typedef SkImage_Base INHERITED;
75};
76
77#endif