diff options
Diffstat (limited to 'libs/hwui/tests/common/TestUtils.cpp')
-rw-r--r-- | libs/hwui/tests/common/TestUtils.cpp | 67 |
1 files changed, 15 insertions, 52 deletions
diff --git a/libs/hwui/tests/common/TestUtils.cpp b/libs/hwui/tests/common/TestUtils.cpp index 02ac97e0ed5c..66b9b85bdbe7 100644 --- a/libs/hwui/tests/common/TestUtils.cpp +++ b/libs/hwui/tests/common/TestUtils.cpp @@ -19,16 +19,15 @@ #include "DeferredLayerUpdater.h" #include "hwui/Paint.h" -#include <SkClipStack.h> #include <minikin/Layout.h> #include <pipeline/skia/SkiaOpenGLPipeline.h> #include <pipeline/skia/SkiaVulkanPipeline.h> #include <renderthread/EglManager.h> -#include <renderthread/OpenGLPipeline.h> #include <renderthread/VulkanManager.h> #include <utils/Unicode.h> -#include <SkGlyphCache.h> +#include "SkColorData.h" +#include "SkUnPreMultiply.h" namespace android { namespace uirenderer { @@ -53,9 +52,7 @@ SkColor TestUtils::interpolateColor(float fraction, SkColor start, SkColor end) sp<DeferredLayerUpdater> TestUtils::createTextureLayerUpdater( renderthread::RenderThread& renderThread) { android::uirenderer::renderthread::IRenderPipeline* pipeline; - if (Properties::getRenderPipelineType() == RenderPipelineType::OpenGL) { - pipeline = new renderthread::OpenGLPipeline(renderThread); - } else if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) { + if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) { pipeline = new skiapipeline::SkiaOpenGLPipeline(renderThread); } else { pipeline = new skiapipeline::SkiaVulkanPipeline(renderThread); @@ -70,61 +67,28 @@ sp<DeferredLayerUpdater> TestUtils::createTextureLayerUpdater( renderthread::RenderThread& renderThread, uint32_t width, uint32_t height, const SkMatrix& transform) { sp<DeferredLayerUpdater> layerUpdater = createTextureLayerUpdater(renderThread); - layerUpdater->backingLayer()->getTransform().load(transform); + layerUpdater->backingLayer()->getTransform() = transform; layerUpdater->setSize(width, height); layerUpdater->setTransform(&transform); // updateLayer so it's ready to draw - layerUpdater->updateLayer(true, Matrix4::identity().data, HAL_DATASPACE_UNKNOWN); - if (layerUpdater->backingLayer()->getApi() == Layer::Api::OpenGL) { - static_cast<GlLayer*>(layerUpdater->backingLayer()) - ->setRenderTarget(GL_TEXTURE_EXTERNAL_OES); - } + SkMatrix identity; + identity.setIdentity(); + layerUpdater->updateLayer(true, identity, HAL_DATASPACE_UNKNOWN, nullptr); return layerUpdater; } -void TestUtils::layoutTextUnscaled(const SkPaint& paint, const char* text, - std::vector<glyph_t>* outGlyphs, - std::vector<float>* outPositions, float* outTotalAdvance, - Rect* outBounds) { - Rect bounds; - float totalAdvance = 0; - SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); - SkAutoGlyphCacheNoGamma autoCache(paint, &surfaceProps, &SkMatrix::I()); - while (*text != '\0') { - size_t nextIndex = 0; - int32_t unichar = utf32_from_utf8_at(text, 4, 0, &nextIndex); - text += nextIndex; - - glyph_t glyph = autoCache.getCache()->unicharToGlyph(unichar); - autoCache.getCache()->unicharToGlyph(unichar); - - // push glyph and its relative position - outGlyphs->push_back(glyph); - outPositions->push_back(totalAdvance); - outPositions->push_back(0); - - // compute bounds - SkGlyph skGlyph = autoCache.getCache()->getUnicharMetrics(unichar); - Rect glyphBounds(skGlyph.fWidth, skGlyph.fHeight); - glyphBounds.translate(totalAdvance + skGlyph.fLeft, skGlyph.fTop); - bounds.unionWith(glyphBounds); - - // advance next character - SkScalar skWidth; - paint.getTextWidths(&glyph, sizeof(glyph), &skWidth, NULL); - totalAdvance += skWidth; - } - *outBounds = bounds; - *outTotalAdvance = totalAdvance; -} - void TestUtils::drawUtf8ToCanvas(Canvas* canvas, const char* text, const SkPaint& paint, float x, float y) { auto utf16 = asciiToUtf16(text); + uint32_t length = strlen(text); SkPaint glyphPaint(paint); glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - canvas->drawText(utf16.get(), 0, strlen(text), strlen(text), x, y, minikin::Bidi::LTR, + canvas->drawText( + utf16.get(), length, // text buffer + 0, length, // draw range + 0, length, // context range + x, y, minikin::Bidi::LTR, glyphPaint, nullptr, nullptr /* measured text */); } @@ -143,7 +107,7 @@ void TestUtils::TestTask::run() { if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) { renderThread.vulkanManager().initialize(); } else { - renderThread.eglManager().initialize(); + renderThread.requireGlContext(); } rtCallback(renderThread); @@ -151,8 +115,7 @@ void TestUtils::TestTask::run() { if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) { renderThread.vulkanManager().destroy(); } else { - renderThread.renderState().flush(Caches::FlushMode::Full); - renderThread.eglManager().destroy(); + renderThread.destroyGlContext(); } } |