1c55271f2551533b37043aa2e37f754832a43073cbsalomon/* 2c55271f2551533b37043aa2e37f754832a43073cbsalomon * Copyright 2015 Google Inc. 3c55271f2551533b37043aa2e37f754832a43073cbsalomon * 4c55271f2551533b37043aa2e37f754832a43073cbsalomon * Use of this source code is governed by a BSD-style license that can be 5c55271f2551533b37043aa2e37f754832a43073cbsalomon * found in the LICENSE file. 6c55271f2551533b37043aa2e37f754832a43073cbsalomon */ 7c55271f2551533b37043aa2e37f754832a43073cbsalomon 8c55271f2551533b37043aa2e37f754832a43073cbsalomon#ifndef GrImageIDTextureAdjuster_DEFINED 9c55271f2551533b37043aa2e37f754832a43073cbsalomon#define GrImageIDTextureAdjuster_DEFINED 10c55271f2551533b37043aa2e37f754832a43073cbsalomon 11c55271f2551533b37043aa2e37f754832a43073cbsalomon#include "GrTextureParamsAdjuster.h" 121cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon#include "SkImage.h" 13c55271f2551533b37043aa2e37f754832a43073cbsalomon 14c55271f2551533b37043aa2e37f754832a43073cbsalomonclass SkBitmap; 15c55271f2551533b37043aa2e37f754832a43073cbsalomonclass SkImage_Base; 161cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomonclass SkImageCacherator; 17c55271f2551533b37043aa2e37f754832a43073cbsalomon 18c55271f2551533b37043aa2e37f754832a43073cbsalomon/** Implementation for texture-backed SkBitmaps. The bitmap must stay in scope and unmodified 19c55271f2551533b37043aa2e37f754832a43073cbsalomon while this object exists. */ 20c55271f2551533b37043aa2e37f754832a43073cbsalomonclass GrBitmapTextureAdjuster : public GrTextureAdjuster { 21c55271f2551533b37043aa2e37f754832a43073cbsalomonpublic: 22c55271f2551533b37043aa2e37f754832a43073cbsalomon explicit GrBitmapTextureAdjuster(const SkBitmap* bmp); 23c55271f2551533b37043aa2e37f754832a43073cbsalomon 24c55271f2551533b37043aa2e37f754832a43073cbsalomonprivate: 25c55271f2551533b37043aa2e37f754832a43073cbsalomon void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override; 26c55271f2551533b37043aa2e37f754832a43073cbsalomon 27c55271f2551533b37043aa2e37f754832a43073cbsalomon void didCacheCopy(const GrUniqueKey& copyKey) override; 28c55271f2551533b37043aa2e37f754832a43073cbsalomon 29c55271f2551533b37043aa2e37f754832a43073cbsalomon const SkBitmap* fBmp; 30c55271f2551533b37043aa2e37f754832a43073cbsalomon 31c55271f2551533b37043aa2e37f754832a43073cbsalomon typedef GrTextureAdjuster INHERITED; 32c55271f2551533b37043aa2e37f754832a43073cbsalomon}; 33c55271f2551533b37043aa2e37f754832a43073cbsalomon 34c55271f2551533b37043aa2e37f754832a43073cbsalomon/** Implementation for texture-backed SkImages. The image must stay in scope and unmodified while 35c55271f2551533b37043aa2e37f754832a43073cbsalomon this object exists. */ 36c55271f2551533b37043aa2e37f754832a43073cbsalomonclass GrImageTextureAdjuster : public GrTextureAdjuster { 37c55271f2551533b37043aa2e37f754832a43073cbsalomonpublic: 38c55271f2551533b37043aa2e37f754832a43073cbsalomon explicit GrImageTextureAdjuster(const SkImage_Base* img); 39c55271f2551533b37043aa2e37f754832a43073cbsalomon 40c55271f2551533b37043aa2e37f754832a43073cbsalomonprivate: 41c55271f2551533b37043aa2e37f754832a43073cbsalomon void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override; 42c55271f2551533b37043aa2e37f754832a43073cbsalomon 43c55271f2551533b37043aa2e37f754832a43073cbsalomon void didCacheCopy(const GrUniqueKey& copyKey) override; 44c55271f2551533b37043aa2e37f754832a43073cbsalomon 45c55271f2551533b37043aa2e37f754832a43073cbsalomon const SkImage_Base* fImageBase; 46c55271f2551533b37043aa2e37f754832a43073cbsalomon 47c55271f2551533b37043aa2e37f754832a43073cbsalomon typedef GrTextureAdjuster INHERITED; 48c55271f2551533b37043aa2e37f754832a43073cbsalomon}; 49c55271f2551533b37043aa2e37f754832a43073cbsalomon 50b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon/** This class manages the conversion of SW-backed bitmaps to GrTextures. If the input bitmap is 51b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon non-volatile the texture is cached using a key created from the pixels' image id and the 52b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon subset of the pixelref specified by the bitmap. */ 53b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomonclass GrBitmapTextureMaker : public GrTextureMaker { 54b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomonpublic: 55b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap); 56b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon 57b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomonprotected: 58b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon GrTexture* refOriginalTexture() override; 59b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon 60b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override; 61b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon 62b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon void didCacheCopy(const GrUniqueKey& copyKey) override; 63b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon 64b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomonprivate: 65b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon const SkBitmap fBitmap; 66b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon GrUniqueKey fOriginalKey; 67b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon 68b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon typedef GrTextureMaker INHERITED; 69b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon}; 70b1b019985bee2bcbf35c2fbb4281904d0d3465bbbsalomon 711cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon/** This class manages the conversion of generator-backed images to GrTextures. If the caching hint 721cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon is kAllow the image's ID is used for the cache key. */ 731cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomonclass GrImageTextureMaker : public GrTextureMaker { 741cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomonpublic: 751cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher, const SkImage* client, 761cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon SkImage::CachingHint chint); 771cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon 781cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomonprotected: 791cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon // TODO: consider overriding this, for the case where the underlying generator might be 801cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon // able to efficiently produce a "stretched" texture natively (e.g. picture-backed) 811cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon // GrTexture* generateTextureForParams(const CopyParams&) override; 821cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon 831cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon GrTexture* refOriginalTexture() override; 841cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; 851cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon void didCacheCopy(const GrUniqueKey& copyKey) override; 861cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon 871cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomonprivate: 881cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon SkImageCacherator* fCacher; 891cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon const SkImage* fClient; 901cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon GrUniqueKey fOriginalKey; 911cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon SkImage::CachingHint fCachingHint; 921cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon 931cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon typedef GrTextureMaker INHERITED; 941cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon}; 951cf6f9b6b51bcf09d93142ba40d6c331c21f50a6bsalomon 96c55271f2551533b37043aa2e37f754832a43073cbsalomon#endif 97