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 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 12 | #include "GrBackendSurface.h" |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 13 | #include "GrSamplerState.h" |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 14 | #include "GrSurface.h" |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 15 | #include "SkImage.h" |
bsalomon | c44be0e | 2014-07-25 07:32:33 -0700 | [diff] [blame] | 16 | #include "SkPoint.h" |
| 17 | #include "SkRefCnt.h" |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 18 | #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 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 22 | class 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 | */ |
| 42 | static bool StealBackendTexture(sk_sp<GrTexture>&&, |
| 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 | |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 52 | virtual void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) = 0; |
| 53 | |
| 54 | // These match the definitions in SkImage, from whence they came. |
| 55 | // TODO: Either move Chrome over to new api or remove their need to call this on GrTexture |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 56 | typedef void* ReleaseCtx; |
| 57 | typedef void (*ReleaseProc)(ReleaseCtx); |
Greg Daniel | 6a0176b | 2018-01-30 09:28:44 -0500 | [diff] [blame] | 58 | void setRelease(ReleaseProc proc, ReleaseCtx ctx) { |
| 59 | sk_sp<GrReleaseProcHelper> helper(new GrReleaseProcHelper(proc, ctx)); |
| 60 | this->setRelease(std::move(helper)); |
| 61 | } |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 62 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 63 | /** Access methods that are only to be used within Skia code. */ |
| 64 | inline GrTexturePriv texturePriv(); |
| 65 | inline const GrTexturePriv texturePriv() const; |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 66 | |
| 67 | protected: |
Brian Salomon | e632dfc | 2018-08-01 13:01:16 -0400 | [diff] [blame^] | 68 | GrTexture(GrGpu*, const GrSurfaceDesc&, GrTextureType, GrMipMapsStatus); |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 69 | |
Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 70 | virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0; |
| 71 | |
commit-bot@chromium.org | e49157f | 2014-05-09 20:46:48 +0000 | [diff] [blame] | 72 | private: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 73 | void computeScratchKey(GrScratchKey*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 74 | size_t onGpuMemorySize() const override; |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 75 | void markMipMapsDirty(); |
| 76 | void markMipMapsClean(); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 77 | |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 78 | GrTextureType fTextureType; |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 79 | GrMipMapsStatus fMipMapsStatus; |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 80 | int fMaxMipMapLevel; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 81 | friend class GrTexturePriv; |
| 82 | |
| 83 | typedef GrSurface INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | #endif |