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