OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2012 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkImage_Base.h" | |
9 #include "SkBitmap.h" | |
10 #include "SkCanvas.h" | |
11 #include "SkColorTable.h" | |
12 #include "SkData.h" | |
13 //#include "SkImageGeneratorPriv.h" | |
bsalomon
2015/08/24 13:42:08
what this?
reed1
2015/08/24 14:05:04
cruft, gone.
| |
14 #include "SkImageCacherator.h" | |
15 #include "SkImagePriv.h" | |
16 #include "SkPixelRef.h" | |
17 #include "SkSurface.h" | |
18 | |
19 class SkImage_Generator : public SkImage_Base { | |
20 public: | |
21 SkImage_Generator(SkImageCacherator* cache) | |
22 : INHERITED(cache->info().width(), cache->info().height(), kNeedNewImage UniqueID, NULL) | |
23 , fCache(cache) // take ownership | |
24 {} | |
25 | |
26 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const ove rride; | |
27 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con st override; | |
28 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; | |
29 SkData* onRefEncoded() const override; | |
30 bool isOpaque() const override { return fCache->info().isOpaque(); } | |
31 | |
32 bool getROPixels(SkBitmap*) const override; | |
33 GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; | |
34 | |
35 SkShader* onNewShader(SkShader::TileMode, | |
36 SkShader::TileMode, | |
37 const SkMatrix* localMatrix) const override; | |
38 | |
39 bool onIsLazyGenerated() const override { return true; } | |
40 | |
41 private: | |
42 SkAutoTDelete<SkImageCacherator> fCache; | |
43 | |
44 typedef SkImage_Base INHERITED; | |
45 }; | |
46 | |
47 /////////////////////////////////////////////////////////////////////////////// | |
48 | |
49 | |
50 SkShader* SkImage_Generator::onNewShader(SkShader::TileMode tileX, SkShader::Til eMode tileY, | |
51 const SkMatrix* localMatrix) const { | |
52 // TODO: need a native Shader that takes Cacherator (or this image) so we ca n native | |
53 // textures as output from the shader. | |
54 SkBitmap bm; | |
55 if (this->getROPixels(&bm)) { | |
56 return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix); | |
57 } | |
58 return nullptr; | |
59 } | |
60 | |
61 SkSurface* SkImage_Generator::onNewSurface(const SkImageInfo& info, | |
62 const SkSurfaceProps& props) const { | |
63 return SkSurface::NewRaster(info, &props); | |
64 } | |
65 | |
66 bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels , size_t dstRB, | |
67 int srcX, int srcY) const { | |
68 SkBitmap bm; | |
69 if (this->getROPixels(&bm)) { | |
70 return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY); | |
71 } | |
72 return false; | |
73 } | |
74 | |
75 const void* SkImage_Generator::onPeekPixels(SkImageInfo* infoPtr, size_t* rowByt esPtr) const { | |
76 return NULL; | |
77 } | |
78 | |
79 SkData* SkImage_Generator::onRefEncoded() const { | |
80 return fCache->refEncoded(); | |
81 } | |
82 | |
83 bool SkImage_Generator::getROPixels(SkBitmap* bitmap) const { | |
84 return fCache->lockAsBitmap(bitmap); | |
85 } | |
86 | |
87 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, SkImageUsageType usag e) const { | |
88 return fCache->lockAsTexture(ctx, usage); | |
89 } | |
90 | |
91 /////////////////////////////////////////////////////////////////////////////// | |
92 | |
93 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* s ubset) { | |
94 // | |
95 // TODO: need to handle subset! | |
96 // | |
97 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su bset); | |
98 if (!cache) { | |
99 return nullptr; | |
100 } | |
101 return SkNEW_ARGS(SkImage_Generator, (cache)); | |
102 } | |
OLD | NEW |