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 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 19 | class GrTexturePriv; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
Brian Salomon | 197c586 | 2019-08-21 22:08:36 -0400 | [diff] [blame] | 21 | class GrTexture : virtual public GrSurface { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | public: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | GrTexture* asTexture() override { return this; } |
| 24 | const GrTexture* asTexture() const override { return this; } |
commit-bot@chromium.org | 59e7d23 | 2014-05-09 18:02:51 +0000 | [diff] [blame] | 25 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 26 | virtual GrBackendTexture getBackendTexture() const = 0; |
| 27 | |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 28 | /** |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 29 | * This function indicates that the texture parameters (wrap mode, filtering, ...) have been |
| 30 | * changed externally to Skia. |
junov@chromium.org | 957ebdd | 2012-06-12 13:58:36 +0000 | [diff] [blame] | 31 | */ |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 32 | virtual void textureParamsModified() = 0; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 33 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 34 | /** |
| 35 | * This function steals the backend texture from a uniquely owned GrTexture with no pending |
| 36 | * 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] | 37 | * |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 38 | * Note that if the GrTexture is not uniquely owned (no other refs), or has pending IO, this |
| 39 | * function will fail. |
| 40 | */ |
Brian Salomon | 35ba614 | 2019-01-24 13:08:59 -0500 | [diff] [blame] | 41 | static bool StealBackendTexture(sk_sp<GrTexture>, |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 42 | GrBackendTexture*, |
| 43 | SkImage::BackendTextureReleaseProc*); |
| 44 | |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 45 | /** See addIdleProc. */ |
| 46 | enum class IdleState { |
| 47 | kFlushed, |
| 48 | kFinished |
| 49 | }; |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 50 | /** |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 51 | * Installs a proc on this texture. It will be called when the texture becomes "idle". There |
| 52 | * are two types of idle states as indicated by IdleState. For managed backends (e.g. GL where |
| 53 | * a driver typically handles CPU/GPU synchronization of resource access) there is no difference |
| 54 | * between the two. They both mean "all work related to the resource has been flushed to the |
| 55 | * backend API and the texture is not owned outside the resource cache". |
| 56 | * |
| 57 | * If the API is unmanaged (e.g. Vulkan) then kFinished has the additional constraint that the |
| 58 | * work flushed to the GPU is finished. |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 59 | */ |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 60 | virtual void addIdleProc(sk_sp<GrRefCntedCallback> idleProc, IdleState) { |
| 61 | // This is the default implementation for the managed case where the IdleState can be |
| 62 | // ignored. Unmanaged backends, e.g. Vulkan, must override this to consider IdleState. |
| 63 | fIdleProcs.push_back(std::move(idleProc)); |
| 64 | } |
| 65 | /** Helper version of addIdleProc that creates the ref-counted wrapper. */ |
| 66 | void addIdleProc(GrRefCntedCallback::Callback callback, |
| 67 | GrRefCntedCallback::Context context, |
| 68 | IdleState state) { |
| 69 | this->addIdleProc(sk_make_sp<GrRefCntedCallback>(callback, context), state); |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 70 | } |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 71 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 72 | /** Access methods that are only to be used within Skia code. */ |
| 73 | inline GrTexturePriv texturePriv(); |
| 74 | inline const GrTexturePriv texturePriv() const; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 75 | |
| 76 | protected: |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 77 | GrTexture(GrGpu*, const SkISize&, GrProtected, GrTextureType, GrMipmapStatus); |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 78 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 79 | virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0; |
| 80 | |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 81 | SkTArray<sk_sp<GrRefCntedCallback>> fIdleProcs; |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 82 | |
Robert Phillips | bf8bf83 | 2019-08-30 13:13:44 -0400 | [diff] [blame] | 83 | void willRemoveLastRef() override { |
Brian Salomon | e80b809 | 2019-03-08 13:25:19 -0500 | [diff] [blame] | 84 | // We're about to be idle in the resource cache. Do our part to trigger the idle callbacks. |
| 85 | fIdleProcs.reset(); |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 86 | } |
Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 87 | virtual void callIdleProcsOnBehalfOfResource() {} |
Brian Salomon | 14cb413 | 2019-09-16 13:14:47 -0400 | [diff] [blame] | 88 | void computeScratchKey(GrScratchKey*) const override; |
Brian Salomon | b2c5dae | 2019-03-04 10:25:17 -0500 | [diff] [blame] | 89 | |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 90 | private: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 91 | size_t onGpuMemorySize() const override; |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 92 | void markMipmapsDirty(); |
| 93 | void markMipmapsClean(); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 94 | |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 95 | GrTextureType fTextureType; |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 96 | GrMipmapStatus fMipmapStatus; |
| 97 | int fMaxMipmapLevel; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 98 | friend class GrTexturePriv; |
Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 99 | friend class GrTextureResource; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 100 | |
| 101 | typedef GrSurface INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | #endif |