From de97307362c26b64e2376b21ccde8414088cdc8b Mon Sep 17 00:00:00 2001 From: Matt Sarett Date: Tue, 25 Oct 2016 11:07:40 -0400 Subject: [PATCH] Make FrameInfoVisualizer use an IRenderPipeline to draw Removing the direct uses of the BakedOpRenderer should make it easier for the SkiaGL pipeline to take advantage of these debugging features. Test: Verified that debug.hwui.show_dirty_regions and debug.hwui.profile still behave as expected. BUG:32370375 Change-Id: I2818bda4a18ec183c9c39ca080ad34a4dc89b5cd --- libs/hwui/Android.mk | 1 + libs/hwui/FrameInfoVisualizer.cpp | 25 +++++++------- libs/hwui/FrameInfoVisualizer.h | 9 +++-- libs/hwui/IProfileRenderer.h | 34 ++++++++++++++++++ libs/hwui/ProfileRenderer.cpp | 40 +++++++++++++++++++++ libs/hwui/ProfileRenderer.h | 42 +++++++++++++++++++++++ libs/hwui/renderthread/OpenGLPipeline.cpp | 4 ++- 7 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 libs/hwui/IProfileRenderer.h create mode 100644 libs/hwui/ProfileRenderer.cpp create mode 100644 libs/hwui/ProfileRenderer.h diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index 0aa78081b0167..5069a9a686fec 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -80,6 +80,7 @@ hwui_src_files := \ PathParser.cpp \ PathTessellator.cpp \ PixelBuffer.cpp \ + ProfileRenderer.cpp \ Program.cpp \ ProgramCache.cpp \ Properties.cpp \ diff --git a/libs/hwui/FrameInfoVisualizer.cpp b/libs/hwui/FrameInfoVisualizer.cpp index 570322dfb4eb2..d3adc32da8488 100644 --- a/libs/hwui/FrameInfoVisualizer.cpp +++ b/libs/hwui/FrameInfoVisualizer.cpp @@ -16,6 +16,7 @@ #include "FrameInfoVisualizer.h" #include "BakedOpRenderer.h" +#include "IProfileRenderer.h" #include "utils/Color.h" #include @@ -88,7 +89,7 @@ void FrameInfoVisualizer::unionDirty(SkRect* dirty) { } } -void FrameInfoVisualizer::draw(ContentRenderer* renderer) { +void FrameInfoVisualizer::draw(IProfileRenderer& renderer) { RETURN_IF_DISABLED(); if (mShowDirtyRegions) { @@ -96,8 +97,8 @@ void FrameInfoVisualizer::draw(ContentRenderer* renderer) { if (mFlashToggle) { SkPaint paint; paint.setColor(0x7fff0000); - renderer->drawRect(mDirtyRegion.fLeft, mDirtyRegion.fTop, - mDirtyRegion.fRight, mDirtyRegion.fBottom, &paint); + renderer.drawRect(mDirtyRegion.fLeft, mDirtyRegion.fTop, + mDirtyRegion.fRight, mDirtyRegion.fBottom, paint); } } @@ -111,7 +112,7 @@ void FrameInfoVisualizer::draw(ContentRenderer* renderer) { info.markSwapBuffers(); info.markFrameCompleted(); - initializeRects(renderer->getViewportHeight(), renderer->getViewportWidth()); + initializeRects(renderer.getViewportHeight(), renderer.getViewportWidth()); drawGraph(renderer); drawThreshold(renderer); } @@ -194,26 +195,26 @@ void FrameInfoVisualizer::nextBarSegment(FrameInfoIndex start, FrameInfoIndex en } } -void FrameInfoVisualizer::drawGraph(ContentRenderer* renderer) { +void FrameInfoVisualizer::drawGraph(IProfileRenderer& renderer) { SkPaint paint; for (size_t i = 0; i < Bar.size(); i++) { nextBarSegment(Bar[i].start, Bar[i].end); paint.setColor(Bar[i].color & BAR_FAST_MASK); - renderer->drawRects(mFastRects.get(), mNumFastRects * 4, &paint); + renderer.drawRects(mFastRects.get(), mNumFastRects * 4, paint); paint.setColor(Bar[i].color & BAR_JANKY_MASK); - renderer->drawRects(mJankyRects.get(), mNumJankyRects * 4, &paint); + renderer.drawRects(mJankyRects.get(), mNumJankyRects * 4, paint); } } -void FrameInfoVisualizer::drawThreshold(ContentRenderer* renderer) { +void FrameInfoVisualizer::drawThreshold(IProfileRenderer& renderer) { SkPaint paint; paint.setColor(THRESHOLD_COLOR); - float yLocation = renderer->getViewportHeight() - (FRAME_THRESHOLD * mVerticalUnit); - renderer->drawRect(0.0f, + float yLocation = renderer.getViewportHeight() - (FRAME_THRESHOLD * mVerticalUnit); + renderer.drawRect(0.0f, yLocation - mThresholdStroke/2, - renderer->getViewportWidth(), + renderer.getViewportWidth(), yLocation + mThresholdStroke/2, - &paint); + paint); } bool FrameInfoVisualizer::consumeProperties() { diff --git a/libs/hwui/FrameInfoVisualizer.h b/libs/hwui/FrameInfoVisualizer.h index d60c002ed5f4e..b98f501014837 100644 --- a/libs/hwui/FrameInfoVisualizer.h +++ b/libs/hwui/FrameInfoVisualizer.h @@ -28,8 +28,7 @@ namespace android { namespace uirenderer { -class BakedOpRenderer; -typedef BakedOpRenderer ContentRenderer; +class IProfileRenderer; // TODO: This is a bit awkward as it needs to match the thing in CanvasContext // A better abstraction here would be nice but iterators are painful @@ -47,7 +46,7 @@ public: void setDensity(float density); void unionDirty(SkRect* dirty); - void draw(ContentRenderer* renderer); + void draw(IProfileRenderer& renderer); void dumpData(int fd); @@ -57,8 +56,8 @@ private: void initializeRects(const int baseline, const int width); void nextBarSegment(FrameInfoIndex start, FrameInfoIndex end); - void drawGraph(ContentRenderer* renderer); - void drawThreshold(ContentRenderer* renderer); + void drawGraph(IProfileRenderer& renderer); + void drawThreshold(IProfileRenderer& renderer); inline float durationMS(size_t index, FrameInfoIndex start, FrameInfoIndex end) { float duration = mFrameSource[index].duration(start, end) * 0.000001f; diff --git a/libs/hwui/IProfileRenderer.h b/libs/hwui/IProfileRenderer.h new file mode 100644 index 0000000000000..947ed34cc0701 --- /dev/null +++ b/libs/hwui/IProfileRenderer.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SkPaint.h" + +namespace android { +namespace uirenderer { + +class IProfileRenderer { +public: + virtual void drawRect(float left, float top, float right, float bottom, + const SkPaint& paint) = 0; + virtual void drawRects(const float* rects, int count, const SkPaint& paint) = 0; + virtual uint32_t getViewportWidth() = 0; + virtual uint32_t getViewportHeight() = 0; + + virtual ~IProfileRenderer() {} +}; + +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/ProfileRenderer.cpp b/libs/hwui/ProfileRenderer.cpp new file mode 100644 index 0000000000000..0ad484ce06873 --- /dev/null +++ b/libs/hwui/ProfileRenderer.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ProfileRenderer.h" + +namespace android { +namespace uirenderer { + +void ProfileRenderer::drawRect(float left, float top, float right, float bottom, + const SkPaint& paint) { + mRenderer.drawRect(left, top, right, bottom, &paint); +} + +void ProfileRenderer::drawRects(const float* rects, int count, const SkPaint& paint) { + mRenderer.drawRects(rects, count, &paint); +} + +uint32_t ProfileRenderer::getViewportWidth() { + return mRenderer.getViewportWidth(); +} + +uint32_t ProfileRenderer::getViewportHeight() { + return mRenderer.getViewportHeight(); +} + +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/ProfileRenderer.h b/libs/hwui/ProfileRenderer.h new file mode 100644 index 0000000000000..b9e586f592e8c --- /dev/null +++ b/libs/hwui/ProfileRenderer.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "IProfileRenderer.h" + +#include "BakedOpRenderer.h" + +namespace android { +namespace uirenderer { + +class ProfileRenderer : public IProfileRenderer { +public: + ProfileRenderer(BakedOpRenderer& renderer) + : mRenderer(renderer) { + } + + void drawRect(float left, float top, float right, float bottom, const SkPaint& paint) override; + void drawRects(const float* rects, int count, const SkPaint& paint) override; + uint32_t getViewportWidth() override; + uint32_t getViewportHeight() override; + + virtual ~ProfileRenderer() {} + +private: + BakedOpRenderer& mRenderer; +}; + +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/renderthread/OpenGLPipeline.cpp b/libs/hwui/renderthread/OpenGLPipeline.cpp index c758f6c6d1ad3..1ad38031c487e 100644 --- a/libs/hwui/renderthread/OpenGLPipeline.cpp +++ b/libs/hwui/renderthread/OpenGLPipeline.cpp @@ -18,6 +18,7 @@ #include "DeferredLayerUpdater.h" #include "EglManager.h" +#include "ProfileRenderer.h" #include "renderstate/RenderState.h" #include "Readback.h" @@ -76,7 +77,8 @@ bool OpenGLPipeline::draw(const Frame& frame, const SkRect& screenDirty, const S BakedOpRenderer renderer(caches, mRenderThread.renderState(), opaque, lightInfo); frameBuilder.replayBakedOps(renderer); - profiler->draw(&renderer); + ProfileRenderer profileRenderer(renderer); + profiler->draw(profileRenderer); drew = renderer.didDraw(); // post frame cleanup