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_Generator.cpp

Issue 1783063002: Revert of add Make variations to return SkImage by sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, Cac hingHint) const override; 24 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, Cac hingHint) const override;
25 SkImageCacherator* peekCacherator() const override { return fCache; } 25 SkImageCacherator* peekCacherator() const override { return fCache; }
26 SkData* onRefEncoded(GrContext*) const override; 26 SkData* onRefEncoded(GrContext*) const override;
27 bool isOpaque() const override { return fCache->info().isOpaque(); } 27 bool isOpaque() const override { return fCache->info().isOpaque(); }
28 sk_sp<SkImage> onMakeSubset(const SkIRect&) const override; 28 SkImage* onNewSubset(const SkIRect&) const override;
29 bool getROPixels(SkBitmap*, CachingHint) const override; 29 bool getROPixels(SkBitmap*, CachingHint) const override;
30 GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override; 30 GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override;
31 bool onIsLazyGenerated() const override { return true; } 31 bool onIsLazyGenerated() const override { return true; }
32 32
33 private: 33 private:
34 SkAutoTDelete<SkImageCacherator> fCache; 34 SkAutoTDelete<SkImageCacherator> fCache;
35 35
36 typedef SkImage_Base INHERITED; 36 typedef SkImage_Base INHERITED;
37 }; 37 };
38 38
(...skipping 27 matching lines...) Expand all
66 } 66 }
67 67
68 bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const { 68 bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const {
69 return fCache->lockAsBitmap(bitmap, this, chint); 69 return fCache->lockAsBitmap(bitmap, this, chint);
70 } 70 }
71 71
72 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams & params) const { 72 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams & params) const {
73 return fCache->lockAsTexture(ctx, params, this); 73 return fCache->lockAsTexture(ctx, params, this);
74 } 74 }
75 75
76 sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const { 76 SkImage* SkImage_Generator::onNewSubset(const SkIRect& subset) const {
77 // TODO: make this lazy, by wrapping the subset inside a new generator or so mething 77 // TODO: make this lazy, by wrapping the subset inside a new generator or so mething
78 // For now, we do effectively what we did before, make it a raster 78 // For now, we do effectively what we did before, make it a raster
79 79
80 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height( ), 80 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height( ),
81 this->isOpaque() ? kOpaque_SkAlphaType : k Premul_SkAlphaType); 81 this->isOpaque() ? kOpaque_SkAlphaType : k Premul_SkAlphaType);
82 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 82 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
83 if (!surface) { 83 if (!surface) {
84 return nullptr; 84 return nullptr;
85 } 85 }
86 surface->getCanvas()->clear(0); 86 surface->getCanvas()->clear(0);
87 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca lar(-subset.y()), 87 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca lar(-subset.y()),
88 nullptr); 88 nullptr);
89 return sk_sp<SkImage>(surface->newImageSnapshot()); 89 return surface->newImageSnapshot();
90 } 90 }
91 91
92 sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkI Rect* subset) { 92 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* s ubset) {
93 if (!generator) {
94 return nullptr;
95 }
96 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su bset); 93 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su bset);
97 if (!cache) { 94 if (!cache) {
98 return nullptr; 95 return nullptr;
99 } 96 }
100 return sk_make_sp<SkImage_Generator>(cache); 97 return new SkImage_Generator(cache);
101 } 98 }
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