OLD | NEW |
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) con
st override; | 24 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con
st override; |
25 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; | 25 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; |
26 SkData* onRefEncoded() const override; | 26 SkData* onRefEncoded() const override; |
27 bool isOpaque() const override { return fCache->info().isOpaque(); } | 27 bool isOpaque() const override { return fCache->info().isOpaque(); } |
28 SkImage* onNewSubset(const SkIRect&) const override; | 28 SkImage* onNewSubset(const SkIRect&) const override; |
29 bool getROPixels(SkBitmap*) const override; | 29 bool getROPixels(SkBitmap*) const override; |
30 GrTexture* asTextureRef(GrContext*, SkImageUsageType) 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 |
39 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
40 | 40 |
(...skipping 11 matching lines...) Expand all Loading... |
52 } | 52 } |
53 | 53 |
54 SkData* SkImage_Generator::onRefEncoded() const { | 54 SkData* SkImage_Generator::onRefEncoded() const { |
55 return fCache->refEncoded(); | 55 return fCache->refEncoded(); |
56 } | 56 } |
57 | 57 |
58 bool SkImage_Generator::getROPixels(SkBitmap* bitmap) const { | 58 bool SkImage_Generator::getROPixels(SkBitmap* bitmap) const { |
59 return fCache->lockAsBitmap(bitmap, this); | 59 return fCache->lockAsBitmap(bitmap, this); |
60 } | 60 } |
61 | 61 |
62 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, SkImageUsageType usag
e) const { | 62 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams
& params) const { |
63 return fCache->lockAsTexture(ctx, usage, this); | 63 return fCache->lockAsTexture(ctx, params, this); |
64 } | 64 } |
65 | 65 |
66 SkImage* SkImage_Generator::onNewSubset(const SkIRect& subset) const { | 66 SkImage* SkImage_Generator::onNewSubset(const SkIRect& subset) const { |
67 // TODO: make this lazy, by wrapping the subset inside a new generator or so
mething | 67 // TODO: make this lazy, by wrapping the subset inside a new generator or so
mething |
68 // For now, we do effectively what we did before, make it a raster | 68 // For now, we do effectively what we did before, make it a raster |
69 | 69 |
70 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(
), | 70 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(
), |
71 this->isOpaque() ? kOpaque_SkAlphaType : k
Premul_SkAlphaType); | 71 this->isOpaque() ? kOpaque_SkAlphaType : k
Premul_SkAlphaType); |
72 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 72 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
73 if (!surface) { | 73 if (!surface) { |
74 return nullptr; | 74 return nullptr; |
75 } | 75 } |
76 surface->getCanvas()->clear(0); | 76 surface->getCanvas()->clear(0); |
77 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca
lar(-subset.y()), | 77 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca
lar(-subset.y()), |
78 nullptr); | 78 nullptr); |
79 return surface->newImageSnapshot(); | 79 return surface->newImageSnapshot(); |
80 } | 80 } |
81 | 81 |
82 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* s
ubset) { | 82 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* s
ubset) { |
83 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su
bset); | 83 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su
bset); |
84 if (!cache) { | 84 if (!cache) { |
85 return nullptr; | 85 return nullptr; |
86 } | 86 } |
87 return new SkImage_Generator(cache); | 87 return new SkImage_Generator(cache); |
88 } | 88 } |
OLD | NEW |