Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 8b54bae

Browse files
[[ SkiaUpdate ]] Reinstate stipple.
Skia's old stipple implmentation has been pulled over into libgraphics and updated to implement the new mask filter API.
1 parent e7c3835 commit 8b54bae

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
lines changed

libgraphics/libgraphics.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
'src/spread.cpp',
4242
'src/utils.cpp',
4343
'src/w32text.cpp',
44+
'src/SkStippleMaskFilter.cpp',
4445
],
4546

4647
'conditions':
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2012 Google Inc.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include "SkStippleMaskFilter.h"
9+
#include <SkString.h>
10+
11+
bool SkStippleMaskFilter::filterMask(SkMask* dst,
12+
const SkMask& src,
13+
const SkMatrix& matrix,
14+
SkIPoint* margin) const {
15+
16+
if (src.fFormat != SkMask::kA8_Format) {
17+
return false;
18+
}
19+
20+
dst->fBounds = src.fBounds;
21+
dst->fRowBytes = dst->fBounds.width();
22+
dst->fFormat = SkMask::kA8_Format;
23+
dst->fImage = NULL;
24+
25+
if (NULL != src.fImage) {
26+
size_t dstSize = dst->computeImageSize();
27+
if (0 == dstSize) {
28+
return false; // too big to allocate, abort
29+
}
30+
31+
dst->fImage = SkMask::AllocImage(dstSize);
32+
33+
uint8_t* srcScanLine = src.fImage;
34+
uint8_t* scanline = dst->fImage;
35+
36+
for (int y = 0; y < src.fBounds.height(); ++y) {
37+
for (int x = 0; x < src.fBounds.width(); ++x) {
38+
scanline[x] = srcScanLine[x] && ((x+y) & 0x1) ? 0xFF : 0x00;
39+
}
40+
scanline += dst->fRowBytes;
41+
srcScanLine += src.fRowBytes;
42+
}
43+
}
44+
45+
return true;
46+
}
47+
48+
#ifndef SK_IGNORE_TO_STRING
49+
void SkStippleMaskFilter::toString(SkString* str) const {
50+
str->append("SkStippleMaskFilter: ()");
51+
}
52+
#endif
53+
54+
sk_sp<SkFlattenable> SkStippleMaskFilter::CreateProc(SkReadBuffer& buf) {
55+
return sk_make_sp<SkStippleMaskFilter>();
56+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012 Google Inc.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#ifndef SkStippleMaskFilter_DEFINED
9+
#define SkStippleMaskFilter_DEFINED
10+
11+
#include <SkMaskFilter.h>
12+
13+
/**
14+
* Simple MaskFilter that creates a screen door stipple pattern.
15+
*/
16+
class SK_API SkStippleMaskFilter : public SkMaskFilter {
17+
public:
18+
SkStippleMaskFilter() : INHERITED() {
19+
}
20+
21+
virtual bool filterMask(SkMask* dst, const SkMask& src,
22+
const SkMatrix& matrix,
23+
SkIPoint* margin) const override;
24+
25+
// getFormat is from SkMaskFilter
26+
virtual SkMask::Format getFormat() const override {
27+
return SkMask::kA8_Format;
28+
}
29+
30+
SK_TO_STRING_OVERRIDE()
31+
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkStippleMaskFilter)
32+
33+
private:
34+
typedef SkMaskFilter INHERITED;
35+
};
36+
37+
#endif // SkStippleMaskFilter_DEFINED

libgraphics/src/context.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3737

3838
#include <time.h>
3939

40+
#include "SkStippleMaskFilter.h"
41+
4042
////////////////////////////////////////////////////////////////////////////////
4143

4244

@@ -2245,8 +2247,8 @@ static bool MCGContextApplyPaintSettingsToSkPaint(MCGContextRef self, MCGColor p
22452247
}
22462248
else if (p_paint_style == kMCGPaintStyleStippled)
22472249
{
2248-
//t_stipple = new (nothrow) SkStippleMaskFilter();
2249-
//t_success = t_stipple != NULL;
2250+
t_stipple = sk_sp<SkMaskFilter>(new (nothrow) SkStippleMaskFilter());
2251+
t_success = t_stipple != NULL;
22502252
}
22512253
}
22522254

0 commit comments

Comments
 (0)