OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkImageEncoder.h" | 12 #include "SkImageEncoder.h" |
13 #include "SkImageFilter.h" | 13 #include "SkImageFilter.h" |
| 14 #include "SkImageFilterCache.h" |
14 #include "SkImageGenerator.h" | 15 #include "SkImageGenerator.h" |
15 #include "SkImagePriv.h" | 16 #include "SkImagePriv.h" |
16 #include "SkImageShader.h" | 17 #include "SkImageShader.h" |
17 #include "SkImage_Base.h" | 18 #include "SkImage_Base.h" |
18 #include "SkNextID.h" | 19 #include "SkNextID.h" |
19 #include "SkPicture.h" | 20 #include "SkPicture.h" |
20 #include "SkPixelRef.h" | 21 #include "SkPixelRef.h" |
21 #include "SkPixelSerializer.h" | 22 #include "SkPixelSerializer.h" |
22 #include "SkReadPixelsRec.h" | 23 #include "SkReadPixelsRec.h" |
23 #include "SkSpecialImage.h" | 24 #include "SkSpecialImage.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 if (!picture) { | 328 if (!picture) { |
328 return nullptr; | 329 return nullptr; |
329 } | 330 } |
330 return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, pictur
e.get(), | 331 return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, pictur
e.get(), |
331 matrix, paint)); | 332 matrix, paint)); |
332 } | 333 } |
333 | 334 |
334 sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec
t& subset, | 335 sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec
t& subset, |
335 const SkIRect& clipBounds, SkIRect* outSu
bset, | 336 const SkIRect& clipBounds, SkIRect* outSu
bset, |
336 SkIPoint* offset) const { | 337 SkIPoint* offset) const { |
337 if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) { | 338 if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) { |
338 return nullptr; | 339 return nullptr; |
339 } | 340 } |
340 sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage( | 341 sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage( |
341 subset, sk_ref_sp(const_cast<SkImage*>(this))); | 342 subset, sk_ref_sp(const_cast<SkImage*>(this))); |
342 if (!srcSpecialImage) { | 343 if (!srcSpecialImage) { |
343 return nullptr; | 344 return nullptr; |
344 } | 345 } |
345 | 346 |
346 // FIXME: build a cache here. | 347 SkAutoTUnref<SkImageFilterCache> cache( |
347 SkImageFilter::Context context(SkMatrix::I(), clipBounds, nullptr); | 348 SkImageFilterCache::Create(SkImageFilterCache::kDefaultTransientSize)); |
348 sk_sp<SkSpecialImage> result = | 349 SkImageFilter::Context context(SkMatrix::I(), clipBounds, cache.get()); |
349 filter->filterImage(srcSpecialImage.get(), context, offset); | 350 sk_sp<SkSpecialImage> result = |
| 351 filter->filterImage(srcSpecialImage.get(), context, offset); |
350 | 352 |
351 if (!result) { | 353 if (!result) { |
352 return nullptr; | 354 return nullptr; |
353 } | 355 } |
354 | 356 |
355 SkIRect fullSize = SkIRect::MakeWH(result->width(), result->height()); | 357 SkIRect fullSize = SkIRect::MakeWH(result->width(), result->height()); |
356 #if SK_SUPPORT_GPU | 358 #if SK_SUPPORT_GPU |
357 if (result->isTextureBacked()) { | 359 if (result->isTextureBacked()) { |
358 GrContext* context = result->getContext(); | 360 GrContext* context = result->getContext(); |
359 sk_sp<GrTexture> texture = result->asTextureRef(context); | 361 sk_sp<GrTexture> texture = result->asTextureRef(context); |
360 fullSize = SkIRect::MakeWH(texture->width(), texture->height()); | 362 fullSize = SkIRect::MakeWH(texture->width(), texture->height()); |
361 } | 363 } |
362 #endif | 364 #endif |
363 *outSubset = SkIRect::MakeWH(result->width(), result->height()); | 365 *outSubset = SkIRect::MakeWH(result->width(), result->height()); |
364 if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y())))
{ | 366 if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y()))
) { |
365 return nullptr; | 367 return nullptr; |
366 } | 368 } |
367 offset->fX += outSubset->x(); | 369 offset->fX += outSubset->x(); |
368 offset->fY += outSubset->y(); | 370 offset->fY += outSubset->y(); |
369 // This isn't really a "tight" subset, but includes any texture padding. | 371 // This isn't really a "tight" subset, but includes any texture padding. |
370 return result->makeTightSubset(fullSize); | 372 return result->makeTightSubset(fullSize); |
371 } | 373 } |
372 | 374 |
373 bool SkImage::isLazyGenerated() const { | 375 bool SkImage::isLazyGenerated() const { |
374 return as_IB(this)->onIsLazyGenerated(); | 376 return as_IB(this)->onIsLazyGenerated(); |
375 } | 377 } |
376 | 378 |
377 ////////////////////////////////////////////////////////////////////////////////
////// | 379 ////////////////////////////////////////////////////////////////////////////////
////// |
378 | 380 |
379 #if !SK_SUPPORT_GPU | 381 #if !SK_SUPPORT_GPU |
380 | 382 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 SkASSERT(image); | 513 SkASSERT(image); |
512 SkASSERT(ctx); | 514 SkASSERT(ctx); |
513 as_IB(image)->onPinAsTexture(ctx); | 515 as_IB(image)->onPinAsTexture(ctx); |
514 } | 516 } |
515 | 517 |
516 void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) { | 518 void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) { |
517 SkASSERT(image); | 519 SkASSERT(image); |
518 SkASSERT(ctx); | 520 SkASSERT(ctx); |
519 as_IB(image)->onUnpinAsTexture(ctx); | 521 as_IB(image)->onUnpinAsTexture(ctx); |
520 } | 522 } |
OLD | NEW |