Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: src/image/SkImage_Gpu.cpp

Issue 1370223002: Revert[4] of add ImageShader, sharing code with its Bitmap cousin (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "GrContext.h" 11 #include "GrContext.h"
11 #include "GrDrawContext.h" 12 #include "GrDrawContext.h"
13 #include "GrTextureMaker.h"
12 #include "effects/GrYUVtoRGBEffect.h" 14 #include "effects/GrYUVtoRGBEffect.h"
13 #include "SkCanvas.h" 15 #include "SkCanvas.h"
14 #include "SkGpuDevice.h" 16 #include "SkGpuDevice.h"
17 #include "SkGrPriv.h"
15 #include "SkPixelRef.h" 18 #include "SkPixelRef.h"
16 19
17 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,
18 SkSurface::Budgeted budgeted) 21 SkSurface::Budgeted budgeted)
19 : INHERITED(w, h, uniqueID, nullptr) 22 : INHERITED(w, h, uniqueID, nullptr)
20 , fTexture(SkRef(tex)) 23 , fTexture(SkRef(tex))
21 , fAlphaType(at) 24 , fAlphaType(at)
22 , fBudgeted(budgeted) 25 , fBudgeted(budgeted)
23 , fAddedRasterVersionToCache(false) 26 , fAddedRasterVersionToCache(false)
24 {} 27 {}
25 28
26 SkImage_Gpu::~SkImage_Gpu() { 29 SkImage_Gpu::~SkImage_Gpu() {
27 if (fAddedRasterVersionToCache.load()) { 30 if (fAddedRasterVersionToCache.load()) {
28 SkNotifyBitmapGenIDIsStale(this->uniqueID()); 31 SkNotifyBitmapGenIDIsStale(this->uniqueID());
29 } 32 }
30 } 33 }
31 34
32 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { 35 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
33 if (as_IB(image)->getTexture()) { 36 if (as_IB(image)->getTexture()) {
34 ((SkImage_Gpu*)image)->applyBudgetDecision(); 37 ((SkImage_Gpu*)image)->applyBudgetDecision();
35 } 38 }
36 } 39 }
37 40
38 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
39 const SkMatrix* localMatrix) const {
40 SkBitmap bm;
41 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu e(), &bm);
42 return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix);
43 }
44
45 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { 41 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
46 if (SkBitmapCache::Find(this->uniqueID(), dst)) { 42 if (SkBitmapCache::Find(this->uniqueID(), dst)) {
47 SkASSERT(dst->getGenerationID() == this->uniqueID()); 43 SkASSERT(dst->getGenerationID() == this->uniqueID());
48 SkASSERT(dst->isImmutable()); 44 SkASSERT(dst->isImmutable());
49 SkASSERT(dst->getPixels()); 45 SkASSERT(dst->getPixels());
50 return true; 46 return true;
51 } 47 }
52 48
53 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e; 49 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e;
54 if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(), at))) { 50 if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(), at))) {
55 return false; 51 return false;
56 } 52 }
57 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix elConfig, 53 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix elConfig,
58 dst->getPixels(), dst->rowBytes())) { 54 dst->getPixels(), dst->rowBytes())) {
59 return false; 55 return false;
60 } 56 }
61 57
62 dst->pixelRef()->setImmutableWithID(this->uniqueID()); 58 dst->pixelRef()->setImmutableWithID(this->uniqueID());
63 SkBitmapCache::Add(this->uniqueID(), *dst); 59 SkBitmapCache::Add(this->uniqueID(), *dst);
64 fAddedRasterVersionToCache.store(true); 60 fAddedRasterVersionToCache.store(true);
65 return true; 61 return true;
66 } 62 }
67 63
robertphillips 2015/09/30 19:25:56 It seems odd that this has a different domain from
64 static void make_raw_texture_stretched_key(uint32_t imageID, const SkGrStretch& stretch,
65 GrUniqueKey* stretchedKey) {
66 SkASSERT(SkGrStretch::kNone_Type != stretch.fType);
67
68 uint32_t width = SkToU16(stretch.fWidth);
69 uint32_t height = SkToU16(stretch.fHeight);
70
71 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
72 GrUniqueKey::Builder builder(stretchedKey, kDomain, 3);
73 builder[0] = imageID;
74 builder[1] = stretch.fType;
75 builder[2] = width | (height << 16);
76 builder.finish();
77 }
78
79 class Texture_GrTextureMaker : public GrTextureMaker {
80 public:
robertphillips 2015/09/30 19:25:56 unstretched can't be const ?
81 Texture_GrTextureMaker(const SkImage* image, GrTexture* unstretched)
82 : INHERITED(image->width(), image->height())
83 , fImage(image)
84 , fUnstretched(unstretched)
85 {}
86
87 protected:
88 GrTexture* onRefUnstretchedTexture(GrContext* ctx) override {
89 return SkRef(fUnstretched);
90 }
91
92 bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKe y) override {
93 make_raw_texture_stretched_key(fImage->uniqueID(), stretch, stretchedKey );
94 return stretchedKey->isValid();
95 }
96
97 void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override {
98 as_IB(fImage)->notifyAddedToCache();
99 }
100
101 bool onGetROBitmap(SkBitmap* bitmap) override {
102 return as_IB(fImage)->getROPixels(bitmap);
103 }
104
105 private:
106 const SkImage* fImage;
107 GrTexture* fUnstretched;
108
109 typedef GrTextureMaker INHERITED;
110 };
111
68 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, SkImageUsageType usage) con st { 112 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, SkImageUsageType usage) con st {
69 fTexture->ref(); 113 return Texture_GrTextureMaker(this, fTexture).refCachedTexture(ctx, usage);
70 return fTexture;
71 } 114 }
72 115
73 bool SkImage_Gpu::isOpaque() const { 116 bool SkImage_Gpu::isOpaque() const {
74 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk AlphaType; 117 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk AlphaType;
75 } 118 }
76 119
77 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) {
78 switch (info.colorType()) { 121 switch (info.colorType()) {
79 case kRGBA_8888_SkColorType: 122 case kRGBA_8888_SkColorType:
80 case kBGRA_8888_SkColorType: 123 case kBGRA_8888_SkColorType:
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 if (!dst) { 324 if (!dst) {
282 return nullptr; 325 return nullptr;
283 } 326 }
284 327
285 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 328 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
286 const SkIPoint dstP = SkIPoint::Make(0, 0); 329 const SkIPoint dstP = SkIPoint::Make(0, 0);
287 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); 330 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp);
288 return dst; 331 return dst;
289 } 332 }
290 333
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698