OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 | 8 |
9 #include "SkGr.h" | 9 #include "SkGr.h" |
10 | 10 |
11 #include <memory> | |
12 | |
11 #include "GrCaps.h" | 13 #include "GrCaps.h" |
12 #include "GrContext.h" | 14 #include "GrContext.h" |
13 #include "GrTextureParamsAdjuster.h" | 15 #include "GrTextureParamsAdjuster.h" |
14 #include "GrGpuResourcePriv.h" | 16 #include "GrGpuResourcePriv.h" |
15 #include "GrImageIDTextureAdjuster.h" | 17 #include "GrImageIDTextureAdjuster.h" |
16 #include "GrXferProcessor.h" | 18 #include "GrXferProcessor.h" |
17 #include "GrYUVProvider.h" | 19 #include "GrYUVProvider.h" |
18 | 20 |
19 #include "SkColorFilter.h" | 21 #include "SkColorFilter.h" |
20 #include "SkConfig8888.h" | 22 #include "SkConfig8888.h" |
21 #include "SkCanvas.h" | 23 #include "SkCanvas.h" |
22 #include "SkData.h" | 24 #include "SkData.h" |
23 #include "SkErrorInternals.h" | 25 #include "SkErrorInternals.h" |
24 #include "SkGrPixelRef.h" | 26 #include "SkGrPixelRef.h" |
25 #include "SkMessageBus.h" | 27 #include "SkMessageBus.h" |
28 #include "SkMipMap.h" | |
29 #include "SkMipMapLevel.h" | |
26 #include "SkPixelRef.h" | 30 #include "SkPixelRef.h" |
27 #include "SkResourceCache.h" | 31 #include "SkResourceCache.h" |
28 #include "SkTextureCompressor.h" | 32 #include "SkTextureCompressor.h" |
29 #include "SkYUVPlanesCache.h" | 33 #include "SkYUVPlanesCache.h" |
30 #include "effects/GrBicubicEffect.h" | 34 #include "effects/GrBicubicEffect.h" |
31 #include "effects/GrConstColorProcessor.h" | 35 #include "effects/GrConstColorProcessor.h" |
32 #include "effects/GrDitherEffect.h" | 36 #include "effects/GrDitherEffect.h" |
33 #include "effects/GrPorterDuffXferProcessor.h" | 37 #include "effects/GrPorterDuffXferProcessor.h" |
34 #include "effects/GrXfermodeFragmentProcessor.h" | 38 #include "effects/GrXfermodeFragmentProcessor.h" |
35 #include "effects/GrYUVtoRGBEffect.h" | 39 #include "effects/GrYUVtoRGBEffect.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} | 282 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} |
279 private: | 283 private: |
280 GrUniqueKeyInvalidatedMessage fMsg; | 284 GrUniqueKeyInvalidatedMessage fMsg; |
281 | 285 |
282 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg); } | 286 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>:: Post(fMsg); } |
283 }; | 287 }; |
284 | 288 |
285 pixelRef->addGenIDChangeListener(new Invalidator(key)); | 289 pixelRef->addGenIDChangeListener(new Invalidator(key)); |
286 } | 290 } |
287 | 291 |
292 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b itmap) | |
293 { | |
294 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); | |
295 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) { | |
296 GrTexture *texture = load_etc1_texture(ctx, bitmap, desc); | |
297 if (texture) { | |
298 return texture; | |
299 } | |
300 } | |
301 | |
302 GrTexture *texture = create_texture_from_yuv(ctx, bitmap, desc); | |
303 if (texture) { | |
304 return texture; | |
305 } | |
306 | |
307 SkASSERT(sizeof(int) <= sizeof(uint32_t)); | |
308 if (bitmap.width() < 0 || bitmap.height() < 0) { | |
309 return nullptr; | |
310 } | |
311 | |
312 SkAutoLockPixels alp(bitmap); | |
313 if (!bitmap.readyToDraw()) { | |
314 return nullptr; | |
315 } | |
316 | |
317 std::unique_ptr<SkMipMap> mipmaps(SkMipMap::Build(bitmap, nullptr)); | |
bsalomon
2016/01/22 14:33:36
We don't currently use unique_ptr in Skia. That is
cblume
2016/02/24 07:59:24
Done.
| |
318 if (!mipmaps) { | |
319 return nullptr; | |
320 } | |
321 | |
322 const int mipLevelCount = mipmaps->getLevelsCount(); | |
323 | |
324 const bool isMipMapped = mipLevelCount > 1; | |
325 desc.fIsMipMapped = isMipMapped; | |
326 | |
327 SkTArray<SkMipMapLevel> texels(mipLevelCount); | |
328 | |
329 SkMipMapLevel baseLevel(bitmap.getPixels(), bitmap.rowBytes(), bitmap.width( ), | |
330 bitmap.height()); | |
331 texels.push_back(baseLevel); | |
332 | |
333 for (int i = 1; i <= mipLevelCount; ++i) { | |
334 SkMipMap::Level generatedMipLevel; | |
335 mipmaps->getLevel(i, &generatedMipLevel); | |
336 SkMipMapLevel currentMipLevel(generatedMipLevel.fPixmap.addr(), | |
337 generatedMipLevel.fPixmap.rowBytes(), | |
338 generatedMipLevel.fPixmap.width(), | |
339 generatedMipLevel.fPixmap.height()); | |
340 texels.push_back(currentMipLevel); | |
341 } | |
342 | |
343 return ctx->textureProvider()->createTexture(desc, true, texels); | |
344 } | |
345 | |
288 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, | 346 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, |
289 const GrTextureParams& params) { | 347 const GrTextureParams& params) { |
290 if (bitmap.getTexture()) { | 348 if (bitmap.getTexture()) { |
291 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr); | 349 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr); |
292 } | 350 } |
293 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); | 351 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); |
294 } | 352 } |
295 | 353 |
296 /////////////////////////////////////////////////////////////////////////////// | 354 /////////////////////////////////////////////////////////////////////////////// |
297 | 355 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 SkErrorInternals::SetError( kInvalidPaint_SkError, | 685 SkErrorInternals::SetError( kInvalidPaint_SkError, |
628 "Sorry, I don't understand the filtering " | 686 "Sorry, I don't understand the filtering " |
629 "mode you asked for. Falling back to " | 687 "mode you asked for. Falling back to " |
630 "MIPMaps."); | 688 "MIPMaps."); |
631 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 689 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
632 break; | 690 break; |
633 | 691 |
634 } | 692 } |
635 return textureFilterMode; | 693 return textureFilterMode; |
636 } | 694 } |
OLD | NEW |