2016-10-26 10:30:09 -04:00
|
|
|
/*
|
|
|
|
* 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 "SkiaVulkanPipeline.h"
|
|
|
|
|
|
|
|
#include "DeferredLayerUpdater.h"
|
|
|
|
#include "Readback.h"
|
2016-10-26 11:03:23 -04:00
|
|
|
#include "SkiaPipeline.h"
|
|
|
|
#include "SkiaProfileRenderer.h"
|
2018-12-13 16:40:14 -08:00
|
|
|
#include "VkInteropFunctorDrawable.h"
|
2017-11-03 10:12:19 -07:00
|
|
|
#include "renderstate/RenderState.h"
|
|
|
|
#include "renderthread/Frame.h"
|
2019-01-14 12:29:30 -05:00
|
|
|
#include "ShaderCache.h"
|
2016-10-26 10:30:09 -04:00
|
|
|
|
2016-11-09 11:58:36 -05:00
|
|
|
#include <SkSurface.h>
|
2016-10-26 10:30:09 -04:00
|
|
|
#include <SkTypes.h>
|
2016-11-09 11:58:36 -05:00
|
|
|
|
|
|
|
#include <GrContext.h>
|
|
|
|
#include <GrTypes.h>
|
|
|
|
#include <vk/GrVkTypes.h>
|
2016-10-26 10:30:09 -04:00
|
|
|
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
|
|
|
using namespace android::uirenderer::renderthread;
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
namespace skiapipeline {
|
|
|
|
|
2016-11-09 11:58:36 -05:00
|
|
|
SkiaVulkanPipeline::SkiaVulkanPipeline(renderthread::RenderThread& thread)
|
2017-11-03 10:12:19 -07:00
|
|
|
: SkiaPipeline(thread), mVkManager(thread.vulkanManager()) {}
|
2016-11-09 11:58:36 -05:00
|
|
|
|
2016-10-26 10:30:09 -04:00
|
|
|
MakeCurrentResult SkiaVulkanPipeline::makeCurrent() {
|
2016-11-09 11:58:36 -05:00
|
|
|
return MakeCurrentResult::AlreadyCurrent;
|
2016-10-26 10:30:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Frame SkiaVulkanPipeline::getFrame() {
|
2016-11-09 11:58:36 -05:00
|
|
|
LOG_ALWAYS_FATAL_IF(mVkSurface == nullptr,
|
2017-11-03 10:12:19 -07:00
|
|
|
"drawRenderNode called on a context with no surface!");
|
2016-11-09 11:58:36 -05:00
|
|
|
|
2018-11-13 11:14:48 -05:00
|
|
|
SkSurface* backBuffer = mVkManager.getBackbufferSurface(&mVkSurface);
|
2016-11-09 11:58:36 -05:00
|
|
|
if (backBuffer == nullptr) {
|
2016-10-26 10:30:09 -04:00
|
|
|
SkDebugf("failed to get backbuffer");
|
|
|
|
return Frame(-1, -1, 0);
|
|
|
|
}
|
|
|
|
|
2019-01-08 16:01:18 -05:00
|
|
|
Frame frame(mVkSurface->windowWidth(), mVkSurface->windowHeight(),
|
|
|
|
mVkManager.getAge(mVkSurface));
|
2016-10-26 10:30:09 -04:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
bool SkiaVulkanPipeline::draw(const Frame& frame, const SkRect& screenDirty, const SkRect& dirty,
|
2018-05-03 14:40:56 -07:00
|
|
|
const LightGeometry& lightGeometry,
|
2017-11-03 10:12:19 -07:00
|
|
|
LayerUpdateQueue* layerUpdateQueue, const Rect& contentDrawBounds,
|
2018-09-10 16:28:08 -07:00
|
|
|
bool opaque, const LightInfo& lightInfo,
|
2017-11-03 10:12:19 -07:00
|
|
|
const std::vector<sp<RenderNode>>& renderNodes,
|
|
|
|
FrameInfoVisualizer* profiler) {
|
2016-11-09 11:58:36 -05:00
|
|
|
sk_sp<SkSurface> backBuffer = mVkSurface->getBackBufferSurface();
|
|
|
|
if (backBuffer.get() == nullptr) {
|
2016-10-26 10:30:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
2016-11-09 11:58:36 -05:00
|
|
|
SkiaPipeline::updateLighting(lightGeometry, lightInfo);
|
2019-01-08 16:01:18 -05:00
|
|
|
renderFrame(*layerUpdateQueue, dirty, renderNodes, opaque, contentDrawBounds,
|
|
|
|
backBuffer, mVkSurface->preTransform());
|
2019-01-14 12:29:30 -05:00
|
|
|
ShaderCache::get().onVkFrameFlushed(mRenderThread.getGrContext());
|
2016-10-26 10:30:09 -04:00
|
|
|
layerUpdateQueue->clear();
|
2016-10-26 11:03:23 -04:00
|
|
|
|
|
|
|
// Draw visual debugging features
|
2017-11-03 10:12:19 -07:00
|
|
|
if (CC_UNLIKELY(Properties::showDirtyRegions ||
|
|
|
|
ProfileType::None != Properties::getProfileType())) {
|
2016-11-09 11:58:36 -05:00
|
|
|
SkCanvas* profileCanvas = backBuffer->getCanvas();
|
2016-10-26 11:03:23 -04:00
|
|
|
SkiaProfileRenderer profileRenderer(profileCanvas);
|
|
|
|
profiler->draw(profileRenderer);
|
|
|
|
profileCanvas->flush();
|
|
|
|
}
|
|
|
|
|
2016-11-07 15:43:41 -05:00
|
|
|
// Log memory statistics
|
|
|
|
if (CC_UNLIKELY(Properties::debugLevel != kDebugDisabled)) {
|
|
|
|
dumpResourceCacheUsage();
|
|
|
|
}
|
|
|
|
|
2016-10-26 10:30:09 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
bool SkiaVulkanPipeline::swapBuffers(const Frame& frame, bool drew, const SkRect& screenDirty,
|
|
|
|
FrameInfo* currentFrameInfo, bool* requireSwap) {
|
2016-10-26 10:30:09 -04:00
|
|
|
*requireSwap = drew;
|
|
|
|
|
|
|
|
// Even if we decided to cancel the frame, from the perspective of jank
|
|
|
|
// metrics the frame was swapped at this point
|
|
|
|
currentFrameInfo->markSwapBuffers();
|
|
|
|
|
|
|
|
if (*requireSwap) {
|
2016-11-09 11:58:36 -05:00
|
|
|
mVkManager.swapBuffers(mVkSurface);
|
2016-10-26 10:30:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return *requireSwap;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeferredLayerUpdater* SkiaVulkanPipeline::createTextureLayer() {
|
2016-11-09 11:58:36 -05:00
|
|
|
mVkManager.initialize();
|
2017-01-09 14:15:41 -05:00
|
|
|
|
2018-09-04 22:00:00 +00:00
|
|
|
return new DeferredLayerUpdater(mRenderThread.renderState());
|
2016-10-26 10:30:09 -04:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
void SkiaVulkanPipeline::onStop() {}
|
2016-10-26 10:30:09 -04:00
|
|
|
|
2018-12-03 13:26:43 -08:00
|
|
|
bool SkiaVulkanPipeline::setSurface(ANativeWindow* surface, SwapBehavior swapBehavior,
|
2017-11-03 10:12:19 -07:00
|
|
|
ColorMode colorMode) {
|
2016-11-09 11:58:36 -05:00
|
|
|
if (mVkSurface) {
|
|
|
|
mVkManager.destroySurface(mVkSurface);
|
|
|
|
mVkSurface = nullptr;
|
2016-10-26 10:30:09 -04:00
|
|
|
}
|
|
|
|
|
2018-12-11 07:56:07 -08:00
|
|
|
setSurfaceColorProperties(colorMode);
|
2016-10-26 10:30:09 -04:00
|
|
|
if (surface) {
|
2018-12-11 07:56:07 -08:00
|
|
|
mVkSurface = mVkManager.createSurface(surface, colorMode, mSurfaceColorSpace,
|
|
|
|
mSurfaceColorGamut, mSurfaceColorType);
|
2018-10-02 14:47:22 -04:00
|
|
|
}
|
|
|
|
|
2016-11-09 11:58:36 -05:00
|
|
|
return mVkSurface != nullptr;
|
2016-10-26 10:30:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SkiaVulkanPipeline::isSurfaceReady() {
|
2016-11-09 11:58:36 -05:00
|
|
|
return CC_UNLIKELY(mVkSurface != nullptr);
|
2016-10-26 10:30:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SkiaVulkanPipeline::isContextReady() {
|
2016-11-09 11:58:36 -05:00
|
|
|
return CC_LIKELY(mVkManager.hasVkContext());
|
2016-10-26 10:30:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkiaVulkanPipeline::invokeFunctor(const RenderThread& thread, Functor* functor) {
|
2018-11-05 16:10:39 -08:00
|
|
|
VkInteropFunctorDrawable::vkInvokeFunctor(functor);
|
2016-10-26 10:30:09 -04:00
|
|
|
}
|
|
|
|
|
2017-05-24 13:28:36 -04:00
|
|
|
sk_sp<Bitmap> SkiaVulkanPipeline::allocateHardwareBitmap(renderthread::RenderThread& renderThread,
|
2017-11-03 10:12:19 -07:00
|
|
|
SkBitmap& skBitmap) {
|
|
|
|
// TODO: implement this function for Vulkan pipeline
|
|
|
|
// code below is a hack to avoid crashing because of missing HW Bitmap support
|
|
|
|
sp<GraphicBuffer> buffer = new GraphicBuffer(
|
|
|
|
skBitmap.info().width(), skBitmap.info().height(), PIXEL_FORMAT_RGBA_8888,
|
|
|
|
GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_NEVER |
|
|
|
|
GraphicBuffer::USAGE_SW_READ_NEVER,
|
|
|
|
std::string("SkiaVulkanPipeline::allocateHardwareBitmap pid [") +
|
|
|
|
std::to_string(getpid()) + "]");
|
2017-05-24 13:28:36 -04:00
|
|
|
status_t error = buffer->initCheck();
|
|
|
|
if (error < 0) {
|
|
|
|
ALOGW("SkiaVulkanPipeline::allocateHardwareBitmap() failed in GraphicBuffer.create()");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-20 10:57:20 -05:00
|
|
|
return Bitmap::createFrom(buffer, skBitmap.refColorSpace());
|
2017-05-24 13:28:36 -04:00
|
|
|
}
|
|
|
|
|
2016-10-26 10:30:09 -04:00
|
|
|
} /* namespace skiapipeline */
|
|
|
|
} /* namespace uirenderer */
|
|
|
|
} /* namespace android */
|