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

Side by Side Diff: gm/imagefiltersgraph.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
« no previous file with comments | « no previous file | gyp/effects.gyp » ('j') | include/core/SkDevice.h » ('J')
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 "gm.h" 8 #include "gm.h"
9 9
10 #include "SkArithmeticMode.h" 10 #include "SkArithmeticMode.h"
11 #include "SkDevice.h" 11 #include "SkSurface.h"
12 #include "SkBitmapSource.h" 12 #include "SkBitmapSource.h"
13 #include "SkBlurImageFilter.h" 13 #include "SkBlurImageFilter.h"
14 #include "SkColorFilter.h" 14 #include "SkColorFilter.h"
15 #include "SkColorFilterImageFilter.h" 15 #include "SkColorFilterImageFilter.h"
16 #include "SkColorMatrixFilter.h" 16 #include "SkColorMatrixFilter.h"
17 #include "SkReadBuffer.h" 17 #include "SkReadBuffer.h"
18 #include "SkWriteBuffer.h" 18 #include "SkWriteBuffer.h"
19 #include "SkMergeImageFilter.h" 19 #include "SkMergeImageFilter.h"
20 #include "SkMorphologyImageFilter.h" 20 #include "SkMorphologyImageFilter.h"
21 #include "SkTestImageFilters.h" 21 #include "SkTestImageFilters.h"
22 #include "SkXfermodeImageFilter.h" 22 #include "SkXfermodeImageFilter.h"
23 23
24 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm ageFilter doesn't 24 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm ageFilter doesn't
25 // perform a draw and this one does. 25 // perform a draw and this one does.
26 class SimpleOffsetFilter : public SkImageFilter { 26 class SimpleOffsetFilter : public SkImageFilter {
27 public: 27 public:
28 class Registrar { 28 class Registrar {
29 public: 29 public:
30 Registrar() { 30 Registrar() {
31 SkFlattenable::Register("SimpleOffsetFilter", 31 SkFlattenable::Register("SimpleOffsetFilter",
32 SimpleOffsetFilter::CreateProc, 32 SimpleOffsetFilter::CreateProc,
33 SimpleOffsetFilter::GetFlattenableType()); 33 SimpleOffsetFilter::GetFlattenableType());
34 } 34 }
35 }; 35 };
36 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input) { 36 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input) {
37 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input)); 37 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input));
38 } 38 }
39 39
40 virtual bool onFilterImage(Proxy* proxy, const SkBitmap& src, const Context& ctx, 40 virtual bool onFilterImage(Proxy* proxy, SkImage& src, const Context& ctx,
41 SkBitmap* dst, SkIPoint* offset) const SK_OVERRID E { 41 SkAutoTUnref<SkImage>& dst, SkIPoint* offset) con st SK_OVERRIDE {
42 SkBitmap source = src; 42 SkAutoTUnref<SkImage> source(SkRef(&src));
43 SkImageFilter* input = getInput(0); 43 SkImageFilter* input = getInput(0);
44 SkIPoint srcOffset = SkIPoint::Make(0, 0); 44 SkIPoint srcOffset = SkIPoint::Make(0, 0);
45 if (input && !input->filterImage(proxy, src, ctx, &source, &srcOffset)) { 45 if (input && !input->filterImage(proxy, src, ctx, source, &srcOffset)) {
46 return false; 46 return false;
47 } 47 }
48 48
49 SkIRect bounds; 49 SkIRect bounds;
50 if (!this->applyCropRect(ctx, proxy, source, &srcOffset, &bounds, &sourc e)) { 50 if (!this->applyCropRect(ctx, proxy, *source, &srcOffset, &bounds, sourc e)) {
51 return false; 51 return false;
52 } 52 }
53 53
54 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo unds.height())); 54 SkAutoTUnref<SkSurface> surface(proxy->createSurface(bounds.width(), bou nds.height()));
55 SkCanvas canvas(device); 55 SkCanvas* canvas = surface->getCanvas();
56 SkPaint paint; 56 SkPaint paint;
57 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 57 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
58 canvas.drawBitmap(source, fDX - bounds.left(), fDY - bounds.top(), &pain t); 58 canvas->drawImage(source, fDX - bounds.left(), fDY - bounds.top(), &pain t);
59 *dst = device->accessBitmap(false); 59 SkImage* image = surface->newImageSnapshot(SkSurface::kYes_Budgeted);
60 if (NULL == image) {
61 return false;
62 }
63 dst.reset(image);
60 offset->fX += bounds.left(); 64 offset->fX += bounds.left();
61 offset->fY += bounds.top(); 65 offset->fY += bounds.top();
62 return true; 66 return true;
63 } 67 }
64 68
65 SK_TO_STRING_OVERRIDE() 69 SK_TO_STRING_OVERRIDE()
66 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SimpleOffsetFilter); 70 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SimpleOffsetFilter);
67 71
68 protected: 72 protected:
69 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE { 73 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 228
225 private: 229 private:
226 typedef GM INHERITED; 230 typedef GM INHERITED;
227 SkBitmap fBitmap; 231 SkBitmap fBitmap;
228 }; 232 };
229 233
230 /////////////////////////////////////////////////////////////////////////////// 234 ///////////////////////////////////////////////////////////////////////////////
231 235
232 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } 236 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; }
233 static skiagm::GMRegistry reg(MyFactory); 237 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | gyp/effects.gyp » ('j') | include/core/SkDevice.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698