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

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

Issue 2250663002: Add alphaType() to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@special-image-alpha-type
Patch Set: Remove virtuals from SkImage, slight cleanup Created 4 years, 4 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
« no previous file with comments | « src/image/SkImage_Base.h ('k') | src/image/SkImage_Gpu.h » ('j') | 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 2015 Google Inc. 2 * Copyright 2015 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 "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkImageCacherator.h" 12 #include "SkImageCacherator.h"
13 #include "SkImagePriv.h" 13 #include "SkImagePriv.h"
14 #include "SkPixelRef.h" 14 #include "SkPixelRef.h"
15 #include "SkSurface.h" 15 #include "SkSurface.h"
16 16
17 class SkImage_Generator : public SkImage_Base { 17 class SkImage_Generator : public SkImage_Base {
18 public: 18 public:
19 SkImage_Generator(SkImageCacherator* cache) 19 SkImage_Generator(SkImageCacherator* cache)
20 : INHERITED(cache->info().width(), cache->info().height(), cache->unique ID()) 20 : INHERITED(cache->info().width(), cache->info().height(), cache->unique ID())
21 , fCache(cache) // take ownership 21 , fCache(cache) // take ownership
22 {} 22 {}
23 23
24 virtual SkImageInfo onImageInfo() const override { 24 virtual SkImageInfo onImageInfo() const override {
25 return fCache->info(); 25 return fCache->info();
26 } 26 }
27 SkAlphaType onAlphaType() const override {
28 return fCache->info().alphaType();
29 }
27 30
28 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, Cac hingHint) const override; 31 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, Cac hingHint) const override;
29 SkImageCacherator* peekCacherator() const override { return fCache; } 32 SkImageCacherator* peekCacherator() const override { return fCache; }
30 SkData* onRefEncoded(GrContext*) const override; 33 SkData* onRefEncoded(GrContext*) const override;
31 bool isOpaque() const override { return fCache->info().isOpaque(); }
32 sk_sp<SkImage> onMakeSubset(const SkIRect&) const override; 34 sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
33 bool getROPixels(SkBitmap*, CachingHint) const override; 35 bool getROPixels(SkBitmap*, CachingHint) const override;
34 GrTexture* asTextureRef(GrContext*, const GrTextureParams&, 36 GrTexture* asTextureRef(GrContext*, const GrTextureParams&,
35 SkSourceGammaTreatment) const override; 37 SkSourceGammaTreatment) const override;
36 bool onIsLazyGenerated() const override { return true; } 38 bool onIsLazyGenerated() const override { return true; }
37 39
38 private: 40 private:
39 SkAutoTDelete<SkImageCacherator> fCache; 41 SkAutoTDelete<SkImageCacherator> fCache;
40 42
41 typedef SkImage_Base INHERITED; 43 typedef SkImage_Base INHERITED;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams & params, 79 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams & params,
78 SkSourceGammaTreatment gammaTreatment ) const { 80 SkSourceGammaTreatment gammaTreatment ) const {
79 return fCache->lockAsTexture(ctx, params, gammaTreatment, this); 81 return fCache->lockAsTexture(ctx, params, gammaTreatment, this);
80 } 82 }
81 83
82 sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const { 84 sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
83 // TODO: make this lazy, by wrapping the subset inside a new generator or so mething 85 // TODO: make this lazy, by wrapping the subset inside a new generator or so mething
84 // For now, we do effectively what we did before, make it a raster 86 // For now, we do effectively what we did before, make it a raster
85 87
86 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height( ), 88 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height( ),
87 this->isOpaque() ? kOpaque_SkAlphaType : k Premul_SkAlphaType); 89 this->alphaType());
88 auto surface(SkSurface::MakeRaster(info)); 90 auto surface(SkSurface::MakeRaster(info));
89 if (!surface) { 91 if (!surface) {
90 return nullptr; 92 return nullptr;
91 } 93 }
92 surface->getCanvas()->clear(0); 94 surface->getCanvas()->clear(0);
93 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca lar(-subset.y()), 95 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca lar(-subset.y()),
94 nullptr); 96 nullptr);
95 return surface->makeImageSnapshot(); 97 return surface->makeImageSnapshot();
96 } 98 }
97 99
98 sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkI Rect* subset) { 100 sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkI Rect* subset) {
99 if (!generator) { 101 if (!generator) {
100 return nullptr; 102 return nullptr;
101 } 103 }
102 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su bset); 104 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su bset);
103 if (!cache) { 105 if (!cache) {
104 return nullptr; 106 return nullptr;
105 } 107 }
106 return sk_make_sp<SkImage_Generator>(cache); 108 return sk_make_sp<SkImage_Generator>(cache);
107 } 109 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Base.h ('k') | src/image/SkImage_Gpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698