epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #ifndef GrTexture_DEFINED |
| 10 | #define GrTexture_DEFINED |
| 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkImage.h" |
| 13 | #include "include/core/SkPoint.h" |
| 14 | #include "include/core/SkRefCnt.h" |
| 15 | #include "include/gpu/GrBackendSurface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/private/GrTypesPriv.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 17 | #include "src/gpu/GrSurface.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 18 | |
Brian Salomon | 197c586 | 2019-08-21 22:08:36 -0400 | [diff] [blame] | 19 | class GrTexture : virtual public GrSurface { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | public: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 21 | GrTexture* asTexture() override { return this; } |
| 22 | const GrTexture* asTexture() const override { return this; } |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 23 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 24 | virtual GrBackendTexture getBackendTexture() const = 0; |
| 25 | |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 26 | /** |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 27 | * This function indicates that the texture parameters (wrap mode, filtering, ...) have been |
| 28 | * changed externally to Skia. |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 29 | */ |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 30 | virtual void textureParamsModified() = 0; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 31 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 32 | /** |
| 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 Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 35 | * |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 36 | * Note that if the GrTexture is not uniquely owned (no other refs), or has pending IO, this |
| 37 | * function will fail. |
| 38 | */ |
Brian Salomon | 35ba614 | 2019-01-24 13:08:59 -0500 | [diff] [blame] | 39 | static bool StealBackendTexture(sk_sp<GrTexture>, |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 40 | GrBackendTexture*, |
| 41 | SkImage::BackendTextureReleaseProc*); |
| 42 | |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 43 | 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.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 65 | |
| 66 | protected: |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 67 | GrTexture(GrGpu*, const SkISize&, GrProtected, GrTextureType, GrMipmapStatus); |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 68 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 69 | virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0; |
| 70 | |
Brian Salomon | 14cb413 | 2019-09-16 13:14:47 -0400 | [diff] [blame] | 71 | void computeScratchKey(GrScratchKey*) const override; |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 72 | |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 73 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 74 | size_t onGpuMemorySize() const override; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 75 | |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 76 | GrTextureType fTextureType; |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 77 | GrMipmapStatus fMipmapStatus; |
| 78 | int fMaxMipmapLevel; |
Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 79 | friend class GrTextureResource; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 80 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 81 | using INHERITED = GrSurface; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | #endif |