| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
| 9 #include "SkImage_Gpu.h" | 9 #include "SkImage_Gpu.h" |
| 10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
| 13 #include "GrTextureMaker.h" | 13 #include "GrTextureParamsAdjuster.h" |
| 14 #include "effects/GrYUVtoRGBEffect.h" | 14 #include "effects/GrYUVtoRGBEffect.h" |
| 15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
| 16 #include "SkGpuDevice.h" | 16 #include "SkGpuDevice.h" |
| 17 #include "SkGr.h" | 17 #include "SkGr.h" |
| 18 #include "SkPixelRef.h" | 18 #include "SkPixelRef.h" |
| 19 | 19 |
| 20 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, | 20 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, |
| 21 SkSurface::Budgeted budgeted) | 21 SkSurface::Budgeted budgeted) |
| 22 : INHERITED(w, h, uniqueID) | 22 : INHERITED(w, h, uniqueID) |
| 23 , fTexture(SkRef(tex)) | 23 , fTexture(SkRef(tex)) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 dst->getPixels(), dst->rowBytes())) { | 57 dst->getPixels(), dst->rowBytes())) { |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 61 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
| 62 SkBitmapCache::Add(this->uniqueID(), *dst); | 62 SkBitmapCache::Add(this->uniqueID(), *dst); |
| 63 fAddedRasterVersionToCache.store(true); | 63 fAddedRasterVersionToCache.store(true); |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 | 66 |
| 67 static void make_raw_texture_stretched_key(uint32_t imageID, const SkGrStretch&
stretch, | 67 static void make_raw_texture_stretched_key(uint32_t imageID, |
| 68 const GrTextureParamsAdjuster::CopyPa
rams& params, |
| 68 GrUniqueKey* stretchedKey) { | 69 GrUniqueKey* stretchedKey) { |
| 69 SkASSERT(SkGrStretch::kNone_Type != stretch.fType); | |
| 70 | |
| 71 uint32_t width = SkToU16(stretch.fWidth); | |
| 72 uint32_t height = SkToU16(stretch.fHeight); | |
| 73 | |
| 74 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 70 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 75 GrUniqueKey::Builder builder(stretchedKey, kDomain, 3); | 71 GrUniqueKey::Builder builder(stretchedKey, kDomain, 4); |
| 76 builder[0] = imageID; | 72 builder[0] = imageID; |
| 77 builder[1] = stretch.fType; | 73 builder[1] = params.fFilter; |
| 78 builder[2] = width | (height << 16); | 74 builder[2] = params.fWidth; |
| 79 builder.finish(); | 75 builder[3] = params.fHeight; |
| 80 } | 76 } |
| 81 | 77 |
| 82 class Texture_GrTextureMaker : public GrTextureMaker { | 78 class Texture_GrTextureParamsAdjuster : public GrTextureParamsAdjuster { |
| 83 public: | 79 public: |
| 84 Texture_GrTextureMaker(const SkImage* image, GrTexture* unstretched) | 80 Texture_GrTextureParamsAdjuster(const SkImage* image, GrTexture* unstretched
) |
| 85 : INHERITED(image->width(), image->height()) | 81 : INHERITED(image->width(), image->height()) |
| 86 , fImage(image) | 82 , fImage(image) |
| 87 , fUnstretched(unstretched) | 83 , fOriginal(unstretched) |
| 88 {} | 84 {} |
| 89 | 85 |
| 90 protected: | 86 protected: |
| 91 GrTexture* onRefUnstretchedTexture(GrContext* ctx) override { | 87 GrTexture* peekOriginalTexture() override { return fOriginal; } |
| 92 return SkRef(fUnstretched); | 88 |
| 89 GrTexture* refOriginalTexture(GrContext* ctx) override { |
| 90 return SkRef(fOriginal); |
| 93 } | 91 } |
| 94 | 92 |
| 95 bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKe
y) override { | 93 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid
e { |
| 96 make_raw_texture_stretched_key(fImage->uniqueID(), stretch, stretchedKey
); | 94 make_raw_texture_stretched_key(fImage->uniqueID(), copyParams, copyKey); |
| 97 return stretchedKey->isValid(); | |
| 98 } | 95 } |
| 99 | 96 |
| 100 void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override { | 97 void didCacheCopy(const GrUniqueKey& copyKey) override { |
| 101 as_IB(fImage)->notifyAddedToCache(); | 98 as_IB(fImage)->notifyAddedToCache(); |
| 102 } | 99 } |
| 103 | 100 |
| 104 bool onGetROBitmap(SkBitmap* bitmap) override { | 101 bool getROBitmap(SkBitmap* bitmap) override { |
| 105 return as_IB(fImage)->getROPixels(bitmap); | 102 return as_IB(fImage)->getROPixels(bitmap); |
| 106 } | 103 } |
| 107 | 104 |
| 108 private: | 105 private: |
| 109 const SkImage* fImage; | 106 const SkImage* fImage; |
| 110 GrTexture* fUnstretched; | 107 GrTexture* fOriginal; |
| 111 | 108 |
| 112 typedef GrTextureMaker INHERITED; | 109 typedef GrTextureParamsAdjuster INHERITED; |
| 113 }; | 110 }; |
| 114 | 111 |
| 115 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para
ms) const { | 112 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para
ms) const { |
| 116 return Texture_GrTextureMaker(this, fTexture).refCachedTexture(ctx, params); | 113 return Texture_GrTextureParamsAdjuster(this, fTexture).refTextureForParams(c
tx, params); |
| 117 } | 114 } |
| 118 | 115 |
| 119 bool SkImage_Gpu::isOpaque() const { | 116 bool SkImage_Gpu::isOpaque() const { |
| 120 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk
AlphaType; | 117 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk
AlphaType; |
| 121 } | 118 } |
| 122 | 119 |
| 123 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
{ | 120 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
{ |
| 124 switch (info.colorType()) { | 121 switch (info.colorType()) { |
| 125 case kRGBA_8888_SkColorType: | 122 case kRGBA_8888_SkColorType: |
| 126 case kBGRA_8888_SkColorType: | 123 case kBGRA_8888_SkColorType: |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 if (!dst) { | 401 if (!dst) { |
| 405 return nullptr; | 402 return nullptr; |
| 406 } | 403 } |
| 407 | 404 |
| 408 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 405 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 409 const SkIPoint dstP = SkIPoint::Make(0, 0); | 406 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 410 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 407 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 411 return dst; | 408 return dst; |
| 412 } | 409 } |
| 413 | 410 |
| OLD | NEW |