1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkImage_GpuYUVA_DEFINED 9 #define SkImage_GpuYUVA_DEFINED 10 11 #include "include/gpu/GrBackendSurface.h" 12 #include "src/core/SkCachedData.h" 13 #include "src/gpu/GrYUVATextureProxies.h" 14 #include "src/image/SkImage_GpuBase.h" 15 16 class GrDirectContext; 17 class GrRecordingContext; 18 class GrTexture; 19 20 // Wraps the 1 to 4 planes of a YUVA image for consumption by the GPU. 21 // Initially any direct rendering will be done by passing the individual planes to a shader. 22 // Once any method requests a flattened image (e.g., onReadPixels), the flattened RGB 23 // proxy will be stored and used for any future rendering. 24 class SkImage_GpuYUVA final : public SkImage_GpuBase { 25 public: 26 SkImage_GpuYUVA(sk_sp<GrImageContext>, 27 uint32_t uniqueID, 28 GrYUVATextureProxies proxies, 29 sk_sp<SkColorSpace>); 30 31 bool onHasMipmaps() const override; 32 33 GrSemaphoresSubmitted onFlush(GrDirectContext*, const GrFlushInfo&) const override; 34 onIsTextureBacked()35 bool onIsTextureBacked() const override { return true; } 36 37 size_t onTextureSize() const override; 38 39 sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>, 40 GrDirectContext*) const final; 41 42 sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const final; 43 44 public: isYUVA()45 bool isYUVA() const override { return true; } 46 47 bool setupMipmapsForPlanes(GrRecordingContext*) const; 48 49 private: 50 SkImage_GpuYUVA(sk_sp<GrImageContext>, const SkImage_GpuYUVA* image, sk_sp<SkColorSpace>); 51 52 std::tuple<GrSurfaceProxyView, GrColorType> onAsView(GrRecordingContext*, 53 GrMipmapped, 54 GrImageTexGenPolicy) const override; 55 56 std::unique_ptr<GrFragmentProcessor> onAsFragmentProcessor(GrRecordingContext*, 57 SkSamplingOptions, 58 const SkTileMode[], 59 const SkMatrix&, 60 const SkRect*, 61 const SkRect*) const override; 62 63 mutable GrYUVATextureProxies fYUVAProxies; 64 65 // If this is non-null then the planar data should be converted from fFromColorSpace to 66 // this->colorSpace(). Otherwise we assume the planar data (post YUV->RGB conversion) is already 67 // in this->colorSpace(). 68 const sk_sp<SkColorSpace> fFromColorSpace; 69 70 // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and 71 // SkImage_GpuYUVA instances. Cache the result of the last successful onMakeColorSpace call. 72 mutable sk_sp<SkColorSpace> fOnMakeColorSpaceTarget; 73 mutable sk_sp<SkImage> fOnMakeColorSpaceResult; 74 75 using INHERITED = SkImage_GpuBase; 76 }; 77 78 #endif 79