Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 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 "LayerDrawable.h" |
| 18 | #include "gl/GrGLTypes.h" |
| 19 | |
| 20 | namespace android { |
| 21 | namespace uirenderer { |
| 22 | namespace skiapipeline { |
| 23 | |
| 24 | void LayerDrawable::onDraw(SkCanvas* canvas) { |
| 25 | // transform the matrix based on the layer |
| 26 | int saveCount = -1; |
| 27 | if (!mLayer->getTransform().isIdentity()) { |
| 28 | saveCount = canvas->save(); |
| 29 | SkMatrix transform; |
| 30 | mLayer->getTransform().copyTo(transform); |
| 31 | canvas->concat(transform); |
| 32 | } |
| 33 | GrGLTextureInfo externalTexture; |
| 34 | externalTexture.fTarget = mLayer->getRenderTarget(); |
| 35 | externalTexture.fID = mLayer->getTextureId(); |
| 36 | GrContext* context = canvas->getGrContext(); |
| 37 | GrBackendTextureDesc textureDescription; |
| 38 | textureDescription.fWidth = mLayer->getWidth(); |
| 39 | textureDescription.fHeight = mLayer->getHeight(); |
| 40 | textureDescription.fConfig = kRGBA_8888_GrPixelConfig; |
| 41 | textureDescription.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 42 | textureDescription.fTextureHandle = reinterpret_cast<GrBackendObject>(&externalTexture); |
| 43 | sk_sp<SkImage> layerImage(SkImage::NewFromTexture(context, textureDescription)); |
| 44 | if (layerImage) { |
| 45 | SkPaint paint; |
| 46 | paint.setAlpha(mLayer->getAlpha()); |
| 47 | paint.setBlendMode(mLayer->getMode()); |
| 48 | paint.setColorFilter(mLayer->getColorFilter()); |
| 49 | canvas->drawImage(layerImage, 0, 0, &paint); |
| 50 | } |
| 51 | // restore the original matrix |
| 52 | if (saveCount >= 0) { |
| 53 | canvas->restoreToCount(saveCount); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | }; // namespace skiapipeline |
| 58 | }; // namespace uirenderer |
| 59 | }; // namespace android |