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

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

Issue 1420963008: Pull texture-backed bitmap resampler out of GrTextureParamsAdjuster code into its own class. (Closed) Base URL: https://skia.googlesource.com/skia.git@nomin
Patch Set: fix unused var warning Created 5 years, 1 month 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
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 dst->getPixels(), dst->rowBytes())) { 60 dst->getPixels(), dst->rowBytes())) {
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 class GpuImage_GrTextureAdjuster : public GrTextureAdjuster {
71 const GrTextureParamsAdjuster::CopyPa rams& params,
72 GrUniqueKey* stretchedKey) {
73 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
74 GrUniqueKey::Builder builder(stretchedKey, kDomain, 4);
75 builder[0] = imageID;
76 builder[1] = params.fFilter;
77 builder[2] = params.fWidth;
78 builder[3] = params.fHeight;
79 }
80
81 class Texture_GrTextureParamsAdjuster : public GrTextureParamsAdjuster {
82 public: 71 public:
83 Texture_GrTextureParamsAdjuster(const SkImage* image, GrTexture* unstretched ) 72 GpuImage_GrTextureAdjuster(const SkImage_Gpu* image)
84 : INHERITED(image->width(), image->height()) 73 : INHERITED(image->peekTexture())
85 , fImage(image) 74 , fImage(image)
86 , fOriginal(unstretched)
87 {} 75 {}
88 76
89 protected: 77 protected:
90 GrTexture* refOriginalTexture(GrContext* ctx) override { 78 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override {
91 return SkRef(fOriginal); 79 GrUniqueKey baseKey;
80 GrMakeKeyFromImageID(&baseKey, fImage->uniqueID(),
81 SkIRect::MakeWH(fImage->width(), fImage->height())) ;
82 MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
92 } 83 }
93 84
94 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) overrid e { 85 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 86
102 private: 87 private:
103 const SkImage* fImage; 88 const SkImage* fImage;
104 GrTexture* fOriginal;
105 89
106 typedef GrTextureParamsAdjuster INHERITED; 90 typedef GrTextureAdjuster INHERITED;
107 }; 91 };
108 92
109 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para ms) const { 93 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para ms) const {
110 return Texture_GrTextureParamsAdjuster(this, fTexture).refTextureForParams(c tx, params); 94 return GpuImage_GrTextureAdjuster(this).refTextureSafeForParams(params, null ptr);
111 } 95 }
112 96
113 bool SkImage_Gpu::isOpaque() const { 97 bool SkImage_Gpu::isOpaque() const {
114 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk AlphaType; 98 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk AlphaType;
115 } 99 }
116 100
117 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) { 101 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) {
118 switch (info.colorType()) { 102 switch (info.colorType()) {
119 case kRGBA_8888_SkColorType: 103 case kRGBA_8888_SkColorType:
120 case kBGRA_8888_SkColorType: 104 case kBGRA_8888_SkColorType:
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (!dst) { 383 if (!dst) {
400 return nullptr; 384 return nullptr;
401 } 385 }
402 386
403 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 387 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
404 const SkIPoint dstP = SkIPoint::Make(0, 0); 388 const SkIPoint dstP = SkIPoint::Make(0, 0);
405 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); 389 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp);
406 return dst; 390 return dst;
407 } 391 }
408 392
OLDNEW
« no previous file with comments | « src/gpu/SkGr.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698