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 "GrTextureParamsAdjuster.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 "SkGrPriv.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)) |
24 , fAlphaType(at) | 24 , fAlphaType(at) |
25 , fBudgeted(budgeted) | 25 , fBudgeted(budgeted) |
26 , fAddedRasterVersionToCache(false) | 26 , fAddedRasterVersionToCache(false) |
27 { | 27 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 64 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
65 SkBitmapCache::Add(this->uniqueID(), *dst); | 65 SkBitmapCache::Add(this->uniqueID(), *dst); |
66 fAddedRasterVersionToCache.store(true); | 66 fAddedRasterVersionToCache.store(true); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 static void make_raw_texture_stretched_key(uint32_t imageID, | 70 static void make_raw_texture_stretched_key(uint32_t imageID, |
71 const GrTextureParamsAdjuster::CopyPa
rams& params, | 71 const GrTextureAdjuster::CopyParams&
params, |
72 GrUniqueKey* stretchedKey) { | 72 GrUniqueKey* stretchedKey) { |
73 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 73 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
74 GrUniqueKey::Builder builder(stretchedKey, kDomain, 4); | 74 GrUniqueKey::Builder builder(stretchedKey, kDomain, 4); |
75 builder[0] = imageID; | 75 builder[0] = imageID; |
76 builder[1] = params.fFilter; | 76 builder[1] = params.fFilter; |
77 builder[2] = params.fWidth; | 77 builder[2] = params.fWidth; |
78 builder[3] = params.fHeight; | 78 builder[3] = params.fHeight; |
79 } | 79 } |
80 | 80 |
81 class Texture_GrTextureParamsAdjuster : public GrTextureParamsAdjuster { | 81 class GpuImage_GrTextureAdjuster : public GrTextureAdjuster { |
82 public: | 82 public: |
83 Texture_GrTextureParamsAdjuster(const SkImage* image, GrTexture* unstretched
) | 83 GpuImage_GrTextureAdjuster(const SkImage_Gpu* image) |
84 : INHERITED(image->width(), image->height()) | 84 : INHERITED(image->peekTexture()) |
85 , fImage(image) | 85 , fImage(image) |
86 , fOriginal(unstretched) | |
87 {} | 86 {} |
88 | 87 |
89 protected: | 88 protected: |
90 GrTexture* refOriginalTexture(GrContext* ctx) override { | 89 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override { |
91 return SkRef(fOriginal); | 90 GrUniqueKey baseKey; |
| 91 GrMakeKeyFromImageID(&baseKey, fImage->uniqueID(), |
| 92 SkIRect::MakeWH(fImage->width(), fImage->height()))
; |
| 93 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); |
92 } | 94 } |
93 | 95 |
94 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid
e { | 96 void didCacheCopy(const GrUniqueKey& copyKey) override { as_IB(fImage)->noti
fyAddedToCache(); } |
95 make_raw_texture_stretched_key(fImage->uniqueID(), copyParams, copyKey); | |
96 } | |
97 | |
98 void didCacheCopy(const GrUniqueKey& copyKey) override { | |
99 as_IB(fImage)->notifyAddedToCache(); | |
100 } | |
101 | 97 |
102 private: | 98 private: |
103 const SkImage* fImage; | 99 const SkImage* fImage; |
104 GrTexture* fOriginal; | |
105 | 100 |
106 typedef GrTextureParamsAdjuster INHERITED; | 101 typedef GrTextureAdjuster INHERITED; |
107 }; | 102 }; |
108 | 103 |
109 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para
ms) const { | 104 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para
ms) const { |
110 return Texture_GrTextureParamsAdjuster(this, fTexture).refTextureForParams(c
tx, params); | 105 return GpuImage_GrTextureAdjuster(this).refTextureSafeForParams(params, null
ptr); |
111 } | 106 } |
112 | 107 |
113 bool SkImage_Gpu::isOpaque() const { | 108 bool SkImage_Gpu::isOpaque() const { |
114 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk
AlphaType; | 109 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk
AlphaType; |
115 } | 110 } |
116 | 111 |
117 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
{ | 112 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
{ |
118 switch (info.colorType()) { | 113 switch (info.colorType()) { |
119 case kRGBA_8888_SkColorType: | 114 case kRGBA_8888_SkColorType: |
120 case kBGRA_8888_SkColorType: | 115 case kBGRA_8888_SkColorType: |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 if (!dst) { | 394 if (!dst) { |
400 return nullptr; | 395 return nullptr; |
401 } | 396 } |
402 | 397 |
403 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 398 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
404 const SkIPoint dstP = SkIPoint::Make(0, 0); | 399 const SkIPoint dstP = SkIPoint::Make(0, 0); |
405 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 400 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
406 return dst; | 401 return dst; |
407 } | 402 } |
408 | 403 |
OLD | NEW |