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

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

Issue 1409163002: Rewrite GrTextureMaker to disentangle bitmap case from base class and give GPU object a say in what… (Closed) Base URL: https://skia.googlesource.com/skia.git@move
Patch Set: cleanup 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 "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
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* refOriginalTexture(GrContext* ctx) override {
92 return SkRef(fUnstretched); 88 return SkRef(fOriginal);
93 } 89 }
94 90
95 bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKe y) override { 91 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid e {
96 make_raw_texture_stretched_key(fImage->uniqueID(), stretch, stretchedKey ); 92 make_raw_texture_stretched_key(fImage->uniqueID(), copyParams, copyKey);
97 return stretchedKey->isValid();
98 } 93 }
99 94
100 void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override { 95 void didCacheCopy(const GrUniqueKey& copyKey) override {
101 as_IB(fImage)->notifyAddedToCache(); 96 as_IB(fImage)->notifyAddedToCache();
102 } 97 }
103 98
104 bool onGetROBitmap(SkBitmap* bitmap) override { 99 bool getROBitmap(SkBitmap* bitmap) override {
105 return as_IB(fImage)->getROPixels(bitmap); 100 return as_IB(fImage)->getROPixels(bitmap);
106 } 101 }
107 102
108 private: 103 private:
109 const SkImage* fImage; 104 const SkImage* fImage;
110 GrTexture* fUnstretched; 105 GrTexture* fOriginal;
111 106
112 typedef GrTextureMaker INHERITED; 107 typedef GrTextureParamsAdjuster INHERITED;
113 }; 108 };
114 109
115 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para ms) const { 110 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para ms) const {
116 return Texture_GrTextureMaker(this, fTexture).refCachedTexture(ctx, params); 111 return Texture_GrTextureParamsAdjuster(this, fTexture).refTextureForParams(c tx, params);
117 } 112 }
118 113
119 bool SkImage_Gpu::isOpaque() const { 114 bool SkImage_Gpu::isOpaque() const {
120 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk AlphaType; 115 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk AlphaType;
121 } 116 }
122 117
123 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) { 118 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) {
124 switch (info.colorType()) { 119 switch (info.colorType()) {
125 case kRGBA_8888_SkColorType: 120 case kRGBA_8888_SkColorType:
126 case kBGRA_8888_SkColorType: 121 case kBGRA_8888_SkColorType:
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (!dst) { 380 if (!dst) {
386 return nullptr; 381 return nullptr;
387 } 382 }
388 383
389 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 384 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
390 const SkIPoint dstP = SkIPoint::Make(0, 0); 385 const SkIPoint dstP = SkIPoint::Make(0, 0);
391 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); 386 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp);
392 return dst; 387 return dst;
393 } 388 }
394 389
OLDNEW
« include/gpu/SkGr.h ('K') | « src/gpu/SkGrPriv.h ('k') | src/image/SkImage_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698