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 "SkImageGeneratorUtils.h" | 8 #include "SkImageGeneratorUtils.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "GrTexture.h" | 49 #include "GrTexture.h" |
50 #include "SkGrPriv.h" | 50 #include "SkGrPriv.h" |
51 | 51 |
52 class GeneratorFromTexture : public SkImageGenerator { | 52 class GeneratorFromTexture : public SkImageGenerator { |
53 public: | 53 public: |
54 GeneratorFromTexture(GrContext* ctx, GrTexture* tex, const SkImageInfo& info
) | 54 GeneratorFromTexture(GrContext* ctx, GrTexture* tex, const SkImageInfo& info
) |
55 : SkImageGenerator(info), fCtx(ctx), fTexture(tex) | 55 : SkImageGenerator(info), fCtx(ctx), fTexture(tex) |
56 {} | 56 {} |
57 | 57 |
58 protected: | 58 protected: |
59 GrTexture* onGenerateTexture(GrContext* ctx, const GrTextureParams&, | 59 GrTexture* onGenerateTexture(GrContext* ctx, const SkIRect* subset) override
{ |
60 const SkIRect* subset) override { | |
61 if (ctx) { | 60 if (ctx) { |
62 SkASSERT(ctx == fCtx.get()); | 61 SkASSERT(ctx == fCtx.get()); |
63 } | 62 } |
64 | 63 |
65 if (!subset) { | 64 if (!subset) { |
66 return SkRef(fTexture.get()); | 65 return SkRef(fTexture.get()); |
67 } | 66 } |
68 // need to copy the subset into a new texture | 67 // need to copy the subset into a new texture |
69 GrSurfaceDesc desc = fTexture->desc(); | 68 GrSurfaceDesc desc = fTexture->desc(); |
70 desc.fWidth = subset->width(); | 69 desc.fWidth = subset->width(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 public: | 105 public: |
107 GeneratorFromImage(const SkImage* image, const SkImageInfo& info) | 106 GeneratorFromImage(const SkImage* image, const SkImageInfo& info) |
108 : SkImageGenerator(info), fImage(image) {} | 107 : SkImageGenerator(info), fImage(image) {} |
109 | 108 |
110 protected: | 109 protected: |
111 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | 110 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
112 SkPMColor*, int*) override { | 111 SkPMColor*, int*) override { |
113 return fImage->readPixels(info, pixels, rowBytes, 0, 0); | 112 return fImage->readPixels(info, pixels, rowBytes, 0, 0); |
114 } | 113 } |
115 | 114 |
116 GrTexture* onGenerateTexture(GrContext* ctx, const GrTextureParams&, | 115 GrTexture* onGenerateTexture(GrContext* ctx, const SkIRect* subset) override
{ |
117 const SkIRect* subset) override { | |
118 // waiting on https://code.google.com/p/skia/issues/detail?id=4233 | 116 // waiting on https://code.google.com/p/skia/issues/detail?id=4233 |
119 return nullptr; | 117 return nullptr; |
120 } | 118 } |
121 | 119 |
122 private: | 120 private: |
123 SkAutoTUnref<const SkImage> fImage; | 121 SkAutoTUnref<const SkImage> fImage; |
124 }; | 122 }; |
125 | 123 |
126 SkImageGenerator* SkImageGeneratorUtils::NewFromImage(const SkImage* image) { | 124 SkImageGenerator* SkImageGeneratorUtils::NewFromImage(const SkImage* image) { |
127 if (image) { | 125 if (image) { |
128 const SkColorType ct = kN32_SkColorType; | 126 const SkColorType ct = kN32_SkColorType; |
129 const SkAlphaType at = image->isOpaque() ? kOpaque_SkAlphaType : kPremul
_SkAlphaType; | 127 const SkAlphaType at = image->isOpaque() ? kOpaque_SkAlphaType : kPremul
_SkAlphaType; |
130 const SkImageInfo info = SkImageInfo::Make(image->width(), image->height
(), ct, at); | 128 const SkImageInfo info = SkImageInfo::Make(image->width(), image->height
(), ct, at); |
131 return new GeneratorFromImage(image, info); | 129 return new GeneratorFromImage(image, info); |
132 } | 130 } |
133 return nullptr; | 131 return nullptr; |
134 } | 132 } |
135 | 133 |
136 | 134 |
OLD | NEW |