blob: 0ac09ac49f5d3942cacfd5f04f528e190cdef550 [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>
21#include <SkPicture.h>
22#include <SkPictureRecorder.h>
23
24using namespace android;
25using namespace android::uirenderer;
26
27/**
28 * Verify that we get the same culling bounds for text for (1) drawing glyphs
29 * directly to a Canvas or (2) going through a SkPicture as an intermediate step.
30 */
Greg Daniel98c78dad2017-01-04 14:45:56 -050031OPENGL_PIPELINE_TEST(SkiaCanvasProxy, drawGlyphsViaPicture) {
Derek Sollenberger35934cc2016-03-23 14:59:10 -040032 auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
33 // setup test variables
34 SkPaint paint;
35 paint.setAntiAlias(true);
36 paint.setTextSize(20);
Derek Sollenberger58691b62016-03-28 16:17:36 -040037 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
Derek Sollenberger35934cc2016-03-23 14:59:10 -040038 static const char* text = "testing text bounds";
39
40 // draw text directly into Recording canvas
41 TestUtils::drawUtf8ToCanvas(&canvas, text, paint, 25, 25);
42
43 // record the same text draw into a SkPicture and replay it into a Recording canvas
44 SkPictureRecorder recorder;
45 SkCanvas* skCanvas = recorder.beginRecording(200, 200, NULL, 0);
46 std::unique_ptr<Canvas> pictCanvas(Canvas::create_canvas(skCanvas));
47 TestUtils::drawUtf8ToCanvas(pictCanvas.get(), text, paint, 25, 25);
Derek Sollenberger050bb6a2016-10-26 12:05:24 -040048 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
Derek Sollenberger35934cc2016-03-23 14:59:10 -040049
50 canvas.asSkCanvas()->drawPicture(picture);
51 });
52
53 // verify that the text bounds and matrices match
54 ASSERT_EQ(2U, dl->getOps().size());
55 auto directOp = dl->getOps()[0];
56 auto pictureOp = dl->getOps()[1];
57 ASSERT_EQ(RecordedOpId::TextOp, directOp->opId);
58 EXPECT_EQ(directOp->opId, pictureOp->opId);
59 EXPECT_EQ(directOp->unmappedBounds, pictureOp->unmappedBounds);
60 EXPECT_EQ(directOp->localMatrix, pictureOp->localMatrix);
61}