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