blob: 7fb75dce8a194d74d6a7db16f852ea7e44e3e620 [file] [log] [blame]
Derek Sollenberger35934cc2016-03-23 14:59:10 -04001/*
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 "tests/common/TestUtils.h"
18
19#include <gtest/gtest.h>
20#include <RecordingCanvas.h>
Derek Sollenberger792fb322017-03-03 14:02:09 -050021#include <SkBlurDrawLooper.h>
Derek Sollenberger35934cc2016-03-23 14:59:10 -040022#include <SkPicture.h>
23#include <SkPictureRecorder.h>
24
25using namespace android;
26using namespace android::uirenderer;
27
28/**
29 * Verify that we get the same culling bounds for text for (1) drawing glyphs
30 * directly to a Canvas or (2) going through a SkPicture as an intermediate step.
31 */
Greg Daniel98c78dad2017-01-04 14:45:56 -050032OPENGL_PIPELINE_TEST(SkiaCanvasProxy, drawGlyphsViaPicture) {
Derek Sollenberger35934cc2016-03-23 14:59:10 -040033 auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
34 // setup test variables
35 SkPaint paint;
36 paint.setAntiAlias(true);
37 paint.setTextSize(20);
Derek Sollenberger58691b62016-03-28 16:17:36 -040038 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
Derek Sollenberger35934cc2016-03-23 14:59:10 -040039 static const char* text = "testing text bounds";
40
41 // draw text directly into Recording canvas
42 TestUtils::drawUtf8ToCanvas(&canvas, text, paint, 25, 25);
43
44 // record the same text draw into a SkPicture and replay it into a Recording canvas
45 SkPictureRecorder recorder;
46 SkCanvas* skCanvas = recorder.beginRecording(200, 200, NULL, 0);
47 std::unique_ptr<Canvas> pictCanvas(Canvas::create_canvas(skCanvas));
48 TestUtils::drawUtf8ToCanvas(pictCanvas.get(), text, paint, 25, 25);
Derek Sollenberger050bb6a2016-10-26 12:05:24 -040049 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
Derek Sollenberger35934cc2016-03-23 14:59:10 -040050
51 canvas.asSkCanvas()->drawPicture(picture);
52 });
53
54 // verify that the text bounds and matrices match
55 ASSERT_EQ(2U, dl->getOps().size());
56 auto directOp = dl->getOps()[0];
57 auto pictureOp = dl->getOps()[1];
58 ASSERT_EQ(RecordedOpId::TextOp, directOp->opId);
59 EXPECT_EQ(directOp->opId, pictureOp->opId);
60 EXPECT_EQ(directOp->unmappedBounds, pictureOp->unmappedBounds);
61 EXPECT_EQ(directOp->localMatrix, pictureOp->localMatrix);
62}
Derek Sollenberger792fb322017-03-03 14:02:09 -050063
64TEST(SkiaCanvas, drawShadowLayer) {
65 auto surface = SkSurface::MakeRasterN32Premul(10, 10);
66 SkiaCanvas canvas(surface->getCanvas());
67
68 // clear to white
69 canvas.drawColor(SK_ColorWHITE, SkBlendMode::kSrc);
70
71 SkPaint paint;
72 // it is transparent to ensure that we still draw the rect since it has a looper
73 paint.setColor(SK_ColorTRANSPARENT);
74 // this is how view's shadow layers are implemented
75 paint.setLooper(SkBlurDrawLooper::Make(0xF0000000, 6.0f, 0, 10));
76 canvas.drawRect(3, 3, 7, 7, paint);
77
78 ASSERT_EQ(TestUtils::getColor(surface, 0, 0), SK_ColorWHITE);
79 ASSERT_NE(TestUtils::getColor(surface, 5, 5), SK_ColorWHITE);
80}