blob: b6c78efd0f142c31b2d7490ca2e49ad651cb319a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkRectShaderImageFilter.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkFlattenableBuffers.h"
#include "SkShader.h"
SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, SkRect region) {
SkASSERT(s);
return SkNEW_ARGS(SkRectShaderImageFilter, (s, region));
}
SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, SkRect region)
: INHERITED(NULL)
, fShader(s)
, fRegion(region) {
SkASSERT(s);
SkSafeRef(s);
}
SkRectShaderImageFilter::SkRectShaderImageFilter(SkFlattenableReadBuffer& buffer)
: INHERITED(buffer) {
fShader = buffer.readFlattenableT<SkShader>();
buffer.readRect(&fRegion);
}
void SkRectShaderImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.writeFlattenable(fShader);
buffer.writeRect(fRegion);
}
SkRectShaderImageFilter::~SkRectShaderImageFilter() {
SkSafeUnref(fShader);
}
bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
const SkMatrix& matrix,
SkBitmap* result,
SkIPoint* loc) {
SkAutoTUnref<SkDevice> device(proxy->createDevice(fRegion.width(), fRegion.height()));
SkCanvas canvas(device.get());
SkPaint paint;
paint.setShader(fShader);
canvas.drawRect(fRegion, paint);
*result = device.get()->accessBitmap(false);
return true;
}
|