OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #include "SkSpecialImage.h" | 7 #include "SkSpecialImage.h" |
8 | 8 |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrContext* context) { | 74 sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrContext* context) { |
75 #if SK_SUPPORT_GPU | 75 #if SK_SUPPORT_GPU |
76 if (!context) { | 76 if (!context) { |
77 return nullptr; | 77 return nullptr; |
78 } | 78 } |
79 if (GrTexture* peek = as_SIB(this)->onPeekTexture()) { | 79 if (GrTexture* peek = as_SIB(this)->onPeekTexture()) { |
80 return peek->getContext() == context ? sk_sp<SkSpecialImage>(SkRef(this)
) : nullptr; | 80 return peek->getContext() == context ? sk_sp<SkSpecialImage>(SkRef(this)
) : nullptr; |
81 } | 81 } |
82 | 82 |
83 SkBitmap bmp; | 83 SkBitmap bmp; |
84 if (!this->internal_getBM(&bmp)) { | 84 // At this point, we are definitely not texture-backed, so we must be raster
or generator |
| 85 // backed. If we remove the special-wrapping-an-image subclass, we may be ab
le to assert that |
| 86 // we are strictly raster-backed (i.e. generator images become raster when t
hey are specialized) |
| 87 // in which case getROPixels could turn into peekPixels... |
| 88 if (!this->getROPixels(&bmp)) { |
85 return nullptr; | 89 return nullptr; |
86 } | 90 } |
87 | 91 |
88 if (bmp.empty()) { | 92 if (bmp.empty()) { |
89 return SkSpecialImage::MakeFromRaster(SkIRect::MakeEmpty(), bmp, &this->
props()); | 93 return SkSpecialImage::MakeFromRaster(SkIRect::MakeEmpty(), bmp, &this->
props()); |
90 } | 94 } |
91 | 95 |
92 sk_sp<GrTexture> resultTex(GrRefCachedBitmapTexture(context, | 96 sk_sp<GrTexture> resultTex(GrRefCachedBitmapTexture(context, |
93 bmp, | 97 bmp, |
94 GrTextureParams::ClampNo
Filter(), | 98 GrTextureParams::ClampNo
Filter(), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 158 |
155 sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { | 159 sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const { |
156 return as_SIB(this)->onMakeTightSubset(subset); | 160 return as_SIB(this)->onMakeTightSubset(subset); |
157 } | 161 } |
158 | 162 |
159 #if SK_SUPPORT_GPU | 163 #if SK_SUPPORT_GPU |
160 #include "SkGr.h" | 164 #include "SkGr.h" |
161 #include "SkGrPixelRef.h" | 165 #include "SkGrPixelRef.h" |
162 #endif | 166 #endif |
163 | 167 |
164 sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(const SkBitmap& src, | |
165 const SkSurfaceProps* prop
s) { | |
166 #if SK_SUPPORT_GPU | |
167 // Need to test offset case! (see skbug.com/4967) | |
168 if (src.getTexture()) { | |
169 return SkSpecialImage::MakeFromGpu(src.bounds(), | |
170 src.getGenerationID(), | |
171 sk_ref_sp(src.getTexture()), | |
172 props); | |
173 } | |
174 #endif | |
175 | |
176 return SkSpecialImage::MakeFromRaster(src.bounds(), src, props); | |
177 } | |
178 | |
179 bool SkSpecialImage::internal_getBM(SkBitmap* result) { | |
180 const SkSpecialImage_Base* ib = as_SIB(this); | |
181 | |
182 // TODO: need to test offset case! (see skbug.com/4967) | |
183 return ib->getBitmapDeprecated(result); | |
184 } | |
185 | |
186 /////////////////////////////////////////////////////////////////////////////// | 168 /////////////////////////////////////////////////////////////////////////////// |
187 #include "SkImage.h" | 169 #include "SkImage.h" |
188 #if SK_SUPPORT_GPU | 170 #if SK_SUPPORT_GPU |
189 #include "GrContext.h" | 171 #include "GrContext.h" |
190 #include "SkGrPriv.h" | 172 #include "SkGrPriv.h" |
191 #endif | 173 #endif |
192 | 174 |
193 class SkSpecialImage_Image : public SkSpecialImage_Base { | 175 class SkSpecialImage_Image : public SkSpecialImage_Base { |
194 public: | 176 public: |
195 SkSpecialImage_Image(const SkIRect& subset, | 177 SkSpecialImage_Image(const SkIRect& subset, |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, | 562 sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, |
581 uint32_t uniqueID, | 563 uint32_t uniqueID, |
582 sk_sp<GrTexture> tex, | 564 sk_sp<GrTexture> tex, |
583 const SkSurfaceProps* props, | 565 const SkSurfaceProps* props, |
584 SkAlphaType at) { | 566 SkAlphaType at) { |
585 SkASSERT(rect_fits(subset, tex->width(), tex->height())); | 567 SkASSERT(rect_fits(subset, tex->width(), tex->height())); |
586 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); | 568 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
props); |
587 } | 569 } |
588 | 570 |
589 #endif | 571 #endif |
OLD | NEW |