1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <SkBlendMode.h>
18 #include <SkImageFilter.h>
19 #include <hwui/Paint.h>
20
21 #include "TypeCast.h"
22 #include "android/graphics/paint.h"
23 #include "include/effects/SkImageFilters.h"
24
25 using namespace android;
26
27
APaint_createPaint()28 APaint* APaint_createPaint() {
29 return TypeCast::toAPaint(new Paint());
30 }
31
APaint_destroyPaint(APaint * paint)32 void APaint_destroyPaint(APaint* paint) {
33 delete TypeCast::toPaint(paint);
34 }
35
convertBlendMode(ABlendMode blendMode)36 static SkBlendMode convertBlendMode(ABlendMode blendMode) {
37 switch (blendMode) {
38 case ABLEND_MODE_CLEAR:
39 return SkBlendMode::kClear;
40 case ABLEND_MODE_SRC_OVER:
41 return SkBlendMode::kSrcOver;
42 case ABLEND_MODE_SRC:
43 return SkBlendMode::kSrc;
44 }
45 }
46
convertImageFilter(AImageFilter imageFilter)47 static sk_sp<SkImageFilter> convertImageFilter(AImageFilter imageFilter) {
48 switch (imageFilter) {
49 case AIMAGE_FILTER_DROP_SHADOW_FOR_POINTER_ICON:
50 // Material Elevation Level 1 Drop Shadow.
51 sk_sp<SkImageFilter> key_shadow = SkImageFilters::DropShadow(
52 0.0f, 1.0f, 2.0f, 2.0f, SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), nullptr);
53 sk_sp<SkImageFilter> ambient_shadow = SkImageFilters::DropShadow(
54 0.0f, 1.0f, 3.0f, 3.0f, SkColorSetARGB(0x26, 0x00, 0x00, 0x00), nullptr);
55 return SkImageFilters::Compose(ambient_shadow, key_shadow);
56 }
57 }
58
APaint_setBlendMode(APaint * paint,ABlendMode blendMode)59 void APaint_setBlendMode(APaint* paint, ABlendMode blendMode) {
60 TypeCast::toPaint(paint)->setBlendMode(convertBlendMode(blendMode));
61 }
62
APaint_setImageFilter(APaint * paint,AImageFilter imageFilter)63 void APaint_setImageFilter(APaint* paint, AImageFilter imageFilter) {
64 TypeCast::toPaint(paint)->setImageFilter(convertImageFilter(imageFilter));
65 }
66