Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 17 | #include "Layer.h" |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 18 | |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 19 | #include "renderstate/RenderState.h" |
Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 20 | |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 21 | #include <SkToSRGBColorFilter.h> |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 26 | Layer::Layer(RenderState& renderState, Api api, sk_sp<SkColorFilter> colorFilter, int alpha, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 27 | SkBlendMode mode) |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 28 | : GpuMemoryTracker(GpuObjectType::Layer) |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 29 | , mRenderState(renderState) |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 30 | , mApi(api) |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 31 | , mColorFilter(colorFilter) |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 32 | , alpha(alpha) |
| 33 | , mode(mode) { |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 34 | // TODO: This is a violation of Android's typical ref counting, but it |
| 35 | // preserves the old inc/dec ref locations. This should be changed... |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 36 | incStrong(nullptr); |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 37 | buildColorSpaceWithFilter(); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 38 | renderState.registerLayer(this); |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 41 | Layer::~Layer() { |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 42 | mRenderState.unregisterLayer(this); |
John Reck | 5799801 | 2015-01-29 10:17:57 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 45 | void Layer::setColorFilter(sk_sp<SkColorFilter> filter) { |
| 46 | if (filter != mColorFilter) { |
| 47 | mColorFilter = filter; |
| 48 | buildColorSpaceWithFilter(); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void Layer::setDataSpace(android_dataspace dataspace) { |
| 53 | if (dataspace != mCurrentDataspace) { |
| 54 | mCurrentDataspace = dataspace; |
| 55 | buildColorSpaceWithFilter(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void Layer::buildColorSpaceWithFilter() { |
| 60 | sk_sp<SkColorFilter> colorSpaceFilter; |
| 61 | sk_sp<SkColorSpace> colorSpace = DataSpaceToColorSpace(mCurrentDataspace); |
| 62 | if (colorSpace && !colorSpace->isSRGB()) { |
| 63 | colorSpaceFilter = SkToSRGBColorFilter::Make(colorSpace); |
| 64 | } |
| 65 | |
| 66 | if (mColorFilter && colorSpaceFilter) { |
| 67 | mColorSpaceWithFilter = mColorFilter->makeComposed(colorSpaceFilter); |
| 68 | } else if (colorSpaceFilter) { |
| 69 | mColorSpaceWithFilter = colorSpaceFilter; |
| 70 | } else { |
| 71 | mColorSpaceWithFilter = mColorFilter; |
| 72 | } |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 73 | } |
| 74 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 75 | void Layer::postDecStrong() { |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 76 | mRenderState.postDecStrong(this); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 77 | } |
| 78 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 79 | }; // namespace uirenderer |
| 80 | }; // namespace android |