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

Side by Side Diff: src/effects/SkRectShaderImageFilter.cpp

Issue 920513003: Make filters use SkImage instead of SkBitmap Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkRectShaderImageFilter.h" 8 #include "SkRectShaderImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 void SkRectShaderImageFilter::flatten(SkWriteBuffer& buffer) const { 43 void SkRectShaderImageFilter::flatten(SkWriteBuffer& buffer) const {
44 this->INHERITED::flatten(buffer); 44 this->INHERITED::flatten(buffer);
45 buffer.writeFlattenable(fShader); 45 buffer.writeFlattenable(fShader);
46 } 46 }
47 47
48 SkRectShaderImageFilter::~SkRectShaderImageFilter() { 48 SkRectShaderImageFilter::~SkRectShaderImageFilter() {
49 fShader->unref(); 49 fShader->unref();
50 } 50 }
51 51
52 bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, 52 bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy,
53 const SkBitmap& source, 53 const SkImage* source,
54 const Context& ctx, 54 const Context& ctx,
55 SkBitmap* result, 55 SkAutoTUnref<const SkImage>& result,
56 SkIPoint* offset) const { 56 SkIPoint* offset) const {
57 SkIRect bounds; 57 SkIRect bounds;
58 if (!this->applyCropRect(ctx, source, SkIPoint::Make(0, 0), &bounds)) { 58 if (!this->applyCropRect(ctx, source, SkIPoint::Make(0, 0), &bounds)) {
59 return false; 59 return false;
60 } 60 }
61 61
62 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), 62 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(),
63 bounds.height())); 63 bounds.height()));
64 if (NULL == device.get()) { 64 if (NULL == device.get()) {
65 return false; 65 return false;
66 } 66 }
67 SkCanvas canvas(device.get()); 67 SkCanvas canvas(device.get());
68 68
69 SkPaint paint; 69 SkPaint paint;
70 SkMatrix matrix(ctx.ctm()); 70 SkMatrix matrix(ctx.ctm());
71 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to p())); 71 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to p()));
72 SkSafeUnref(paint.setShader(SkShader::CreateLocalMatrixShader(fShader, matri x))); 72 SkSafeUnref(paint.setShader(SkShader::CreateLocalMatrixShader(fShader, matri x)));
73 73
74 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo unds.height())); 74 SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bo unds.height()));
75 canvas.drawRect(rect, paint); 75 canvas.drawRect(rect, paint);
76 SkImage* image = device->newImageSnapshot();
77 if (NULL == image) {
78 return false;
79 }
80 result.reset(image);
76 81
77 *result = device.get()->accessBitmap(false);
78 offset->fX = bounds.fLeft; 82 offset->fX = bounds.fLeft;
79 offset->fY = bounds.fTop; 83 offset->fY = bounds.fTop;
80 return true; 84 return true;
81 } 85 }
82 86
83 #ifndef SK_IGNORE_TO_STRING 87 #ifndef SK_IGNORE_TO_STRING
84 void SkRectShaderImageFilter::toString(SkString* str) const { 88 void SkRectShaderImageFilter::toString(SkString* str) const {
85 str->appendf("SkRectShaderImageFilter: ("); 89 str->appendf("SkRectShaderImageFilter: (");
86 str->append(")"); 90 str->append(")");
87 } 91 }
88 #endif 92 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698