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

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

Issue 1414843003: Image filters: Replace all use of tryAllocPixels() with createDevice(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix morphology: don't allocate dest or temp until we need them Created 5 years, 2 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 | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | no next file » | 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 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 "SkMorphologyImageFilter.h" 8 #include "SkMorphologyImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkDevice.h"
11 #include "SkOpts.h" 12 #include "SkOpts.h"
12 #include "SkReadBuffer.h" 13 #include "SkReadBuffer.h"
13 #include "SkRect.h" 14 #include "SkRect.h"
14 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
15 #if SK_SUPPORT_GPU 16 #if SK_SUPPORT_GPU
16 #include "GrContext.h" 17 #include "GrContext.h"
17 #include "GrDrawContext.h" 18 #include "GrDrawContext.h"
18 #include "GrInvariantOutput.h" 19 #include "GrInvariantOutput.h"
19 #include "GrTexture.h" 20 #include "GrTexture.h"
20 #include "effects/Gr1DKernelEffect.h" 21 #include "effects/Gr1DKernelEffect.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 SkIRect bounds; 70 SkIRect bounds;
70 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) { 71 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) {
71 return false; 72 return false;
72 } 73 }
73 74
74 SkAutoLockPixels alp(src); 75 SkAutoLockPixels alp(src);
75 if (!src.getPixels()) { 76 if (!src.getPixels()) {
76 return false; 77 return false;
77 } 78 }
78 79
79 if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height())) ) {
80 return false;
81 }
82
83 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), 80 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
84 SkIntToScalar(this->radius().height())); 81 SkIntToScalar(this->radius().height()));
85 ctx.ctm().mapVectors(&radius, 1); 82 ctx.ctm().mapVectors(&radius, 1);
86 int width = SkScalarFloorToInt(radius.fX); 83 int width = SkScalarFloorToInt(radius.fX);
87 int height = SkScalarFloorToInt(radius.fY); 84 int height = SkScalarFloorToInt(radius.fY);
88 85
89 if (width < 0 || height < 0) { 86 if (width < 0 || height < 0) {
90 return false; 87 return false;
91 } 88 }
92 89
93 SkIRect srcBounds = bounds; 90 SkIRect srcBounds = bounds;
94 srcBounds.offset(-srcOffset); 91 srcBounds.offset(-srcOffset);
95 92
96 if (width == 0 && height == 0) { 93 if (width == 0 && height == 0) {
97 src.extractSubset(dst, srcBounds); 94 src.extractSubset(dst, srcBounds);
98 offset->fX = bounds.left(); 95 offset->fX = bounds.left();
99 offset->fY = bounds.top(); 96 offset->fY = bounds.top();
100 return true; 97 return true;
101 } 98 }
102 99
103 SkBitmap temp; 100 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
104 if (!temp.tryAllocPixels(dst->info())) { 101 if (!device) {
105 return false; 102 return false;
106 } 103 }
104 *dst = device->accessBitmap(false);
105 SkAutoLockPixels alp_dst(*dst);
107 106
108 if (width > 0 && height > 0) { 107 if (width > 0 && height > 0) {
108 SkAutoTUnref<SkBaseDevice> tempDevice(proxy->createDevice(dst->width(), dst->height()));
109 if (!tempDevice) {
110 return false;
111 }
112 SkBitmap temp = tempDevice->accessBitmap(false);
113 SkAutoLockPixels alp_temp(temp);
109 callProcX(procX, src, &temp, width, srcBounds); 114 callProcX(procX, src, &temp, width, srcBounds);
110 SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height( )); 115 SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height( ));
111 callProcY(procY, temp, dst, height, tmpBounds); 116 callProcY(procY, temp, dst, height, tmpBounds);
112 } else if (width > 0) { 117 } else if (width > 0) {
113 callProcX(procX, src, dst, width, srcBounds); 118 callProcX(procX, src, dst, width, srcBounds);
114 } else if (height > 0) { 119 } else if (height > 0) {
115 callProcY(procY, src, dst, height, srcBounds); 120 callProcY(procY, src, dst, height, srcBounds);
116 } 121 }
117 offset->fX = bounds.left(); 122 offset->fX = bounds.left();
118 offset->fY = bounds.top(); 123 offset->fY = bounds.top();
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 SkBitmap* result, SkIPoint* offset) con st { 659 SkBitmap* result, SkIPoint* offset) con st {
655 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); 660 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset);
656 } 661 }
657 662
658 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, 663 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
659 SkBitmap* result, SkIPoint* offset) cons t { 664 SkBitmap* result, SkIPoint* offset) cons t {
660 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); 665 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset);
661 } 666 }
662 667
663 #endif 668 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698