blob: f703b1efd44468e119e59ed0e2dfe7fd8343ecba [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
reed@google.comac10a2d2010-12-22 21:39:39 +00009#ifndef GrTexture_DEFINED
10#define GrTexture_DEFINED
11
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkImage.h"
13#include "include/core/SkPoint.h"
14#include "include/core/SkRefCnt.h"
15#include "include/gpu/GrBackendSurface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/private/GrTypesPriv.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000017#include "src/gpu/GrSurface.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018
Brian Salomon197c5862019-08-21 22:08:36 -040019class GrTexture : virtual public GrSurface {
reed@google.comac10a2d2010-12-22 21:39:39 +000020public:
mtklein36352bf2015-03-25 18:17:31 -070021 GrTexture* asTexture() override { return this; }
22 const GrTexture* asTexture() const override { return this; }
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000023
Robert Phillipsb67821d2017-12-13 15:00:45 -050024 virtual GrBackendTexture getBackendTexture() const = 0;
25
junov@chromium.org957ebdd2012-06-12 13:58:36 +000026 /**
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000027 * This function indicates that the texture parameters (wrap mode, filtering, ...) have been
28 * changed externally to Skia.
junov@chromium.org957ebdd2012-06-12 13:58:36 +000029 */
Greg Daniel456f9b52020-03-05 19:14:18 +000030 virtual void textureParamsModified() = 0;
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000031
Eric Karl914a36b2017-10-12 12:44:50 -070032 /**
33 * This function steals the backend texture from a uniquely owned GrTexture with no pending
34 * IO, passing it out to the caller. The GrTexture is deleted in the process.
Greg Daniel6a0176b2018-01-30 09:28:44 -050035 *
Eric Karl914a36b2017-10-12 12:44:50 -070036 * Note that if the GrTexture is not uniquely owned (no other refs), or has pending IO, this
37 * function will fail.
38 */
Brian Salomon35ba6142019-01-24 13:08:59 -050039 static bool StealBackendTexture(sk_sp<GrTexture>,
Eric Karl914a36b2017-10-12 12:44:50 -070040 GrBackendTexture*,
41 SkImage::BackendTextureReleaseProc*);
42
Brian Salomon4cfae3b2020-07-23 10:33:24 -040043 GrTextureType textureType() const { return fTextureType; }
44 bool hasRestrictedSampling() const {
45 return GrTextureTypeHasRestrictedSampling(this->textureType());
46 }
47
48 void markMipmapsDirty();
49 void markMipmapsClean();
50 GrMipmapped mipmapped() const {
51 return GrMipmapped(fMipmapStatus != GrMipmapStatus::kNotAllocated);
52 }
53 bool mipmapsAreDirty() const { return fMipmapStatus != GrMipmapStatus::kValid; }
54 GrMipmapStatus mipmapStatus() const { return fMipmapStatus; }
55 int maxMipmapLevel() const { return fMaxMipmapLevel; }
56
57 static void ComputeScratchKey(const GrCaps& caps,
58 const GrBackendFormat& format,
59 SkISize dimensions,
60 GrRenderable,
61 int sampleCnt,
62 GrMipmapped,
63 GrProtected,
64 GrScratchKey* key);
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000065
66protected:
Brian Salomona6db5102020-07-21 09:56:23 -040067 GrTexture(GrGpu*, const SkISize&, GrProtected, GrTextureType, GrMipmapStatus);
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000068
Eric Karl914a36b2017-10-12 12:44:50 -070069 virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0;
70
Brian Salomon14cb4132019-09-16 13:14:47 -040071 void computeScratchKey(GrScratchKey*) const override;
Brian Salomonb2c5dae2019-03-04 10:25:17 -050072
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000073private:
mtklein36352bf2015-03-25 18:17:31 -070074 size_t onGpuMemorySize() const override;
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000075
Brian Salomon60dd8c72018-07-30 10:24:13 -040076 GrTextureType fTextureType;
Brian Salomon8c82a872020-07-21 12:09:58 -040077 GrMipmapStatus fMipmapStatus;
78 int fMaxMipmapLevel;
Jim Van Verth3e192162020-03-10 16:23:16 -040079 friend class GrTextureResource;
bsalomonafbf2d62014-09-30 12:18:44 -070080
John Stiles7571f9e2020-09-02 22:42:33 -040081 using INHERITED = GrSurface;
reed@google.comac10a2d2010-12-22 21:39:39 +000082};
83
84#endif