Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: src/image/SkImage.cpp

Issue 1964043002: Image filters: implement SkImage::makeWithFilter(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes per Rob's comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkImageFilter.h ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkImageGenerator.h" 14 #include "SkImageGenerator.h"
14 #include "SkImagePriv.h" 15 #include "SkImagePriv.h"
15 #include "SkImageShader.h" 16 #include "SkImageShader.h"
16 #include "SkImage_Base.h" 17 #include "SkImage_Base.h"
17 #include "SkNextID.h" 18 #include "SkNextID.h"
18 #include "SkPicture.h" 19 #include "SkPicture.h"
19 #include "SkPixelRef.h" 20 #include "SkPixelRef.h"
20 #include "SkPixelSerializer.h" 21 #include "SkPixelSerializer.h"
21 #include "SkReadPixelsRec.h" 22 #include "SkReadPixelsRec.h"
23 #include "SkSpecialImage.h"
22 #include "SkString.h" 24 #include "SkString.h"
23 #include "SkSurface.h" 25 #include "SkSurface.h"
24 26
25 #if SK_SUPPORT_GPU 27 #if SK_SUPPORT_GPU
26 #include "GrTexture.h" 28 #include "GrTexture.h"
27 #include "GrContext.h" 29 #include "GrContext.h"
28 #include "SkImage_Gpu.h" 30 #include "SkImage_Gpu.h"
29 #endif 31 #endif
30 32
31 SkImage::SkImage(int width, int height, uint32_t uniqueID) 33 SkImage::SkImage(int width, int height, uint32_t uniqueID)
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 337
336 sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions, 338 sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
337 const SkMatrix* matrix, const SkPaint* p aint) { 339 const SkMatrix* matrix, const SkPaint* p aint) {
338 if (!picture) { 340 if (!picture) {
339 return nullptr; 341 return nullptr;
340 } 342 }
341 return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, pictur e.get(), 343 return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, pictur e.get(),
342 matrix, paint)); 344 matrix, paint));
343 } 345 }
344 346
347 sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec t& subset,
348 const SkIRect& clipBounds, SkIRect* outSu bset,
349 SkIPoint* offset) const {
350 if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) {
351 return nullptr;
352 }
353 sk_sp<SkSpecialImage> srcSpecialImage = SkSpecialImage::MakeFromImage(
354 subset, sk_ref_sp(const_cast<SkImage*>(this)));
355 if (!srcSpecialImage) {
356 return nullptr;
357 }
358
359 // FIXME: build a cache here.
360 SkImageFilter::Context context(SkMatrix::I(), clipBounds, nullptr);
361 sk_sp<SkSpecialImage> result =
362 filter->filterImage(srcSpecialImage.get(), context, offset);
363
364 if (!result) {
365 return nullptr;
366 }
367
368 SkIRect fullSize = SkIRect::MakeWH(result->width(), result->height());
369 #if SK_SUPPORT_GPU
370 if (result->isTextureBacked()) {
371 GrContext* context = result->getContext();
372 sk_sp<GrTexture> texture = result->asTextureRef(context);
373 fullSize = SkIRect::MakeWH(texture->width(), texture->height());
374 }
375 #endif
376 *outSubset = SkIRect::MakeWH(result->width(), result->height());
377 if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y()))) {
378 return nullptr;
379 }
380 offset->fX += outSubset->x();
381 offset->fY += outSubset->y();
382 // This isn't really a "tight" subset, but includes any texture padding.
383 return result->makeTightSubset(fullSize);
384 }
385
345 bool SkImage::isLazyGenerated() const { 386 bool SkImage::isLazyGenerated() const {
346 return as_IB(this)->onIsLazyGenerated(); 387 return as_IB(this)->onIsLazyGenerated();
347 } 388 }
348 389
349 //////////////////////////////////////////////////////////////////////////////// ////// 390 //////////////////////////////////////////////////////////////////////////////// //////
350 391
351 #if !SK_SUPPORT_GPU 392 #if !SK_SUPPORT_GPU
352 393
353 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBud geted budgeted) { 394 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBud geted budgeted) {
354 return nullptr; 395 return nullptr;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 492
452 SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pmap, SkB udgeted budgeted) { 493 SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pmap, SkB udgeted budgeted) {
453 return MakeTextureFromPixmap(ctx, pmap, budgeted).release(); 494 return MakeTextureFromPixmap(ctx, pmap, budgeted).release();
454 } 495 }
455 496
456 SkImage* SkImage::NewFromDeferredTextureImageData(GrContext* ctx, const void* da ta, 497 SkImage* SkImage::NewFromDeferredTextureImageData(GrContext* ctx, const void* da ta,
457 SkBudgeted budgeted) { 498 SkBudgeted budgeted) {
458 return MakeFromDeferredTextureImageData(ctx, data, budgeted).release(); 499 return MakeFromDeferredTextureImageData(ctx, data, budgeted).release();
459 } 500 }
460 #endif 501 #endif
OLDNEW
« no previous file with comments | « include/core/SkImageFilter.h ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698