Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
Jerome Gaillard | bea67ce | 2024-03-28 14:21:16 +0000 | [diff] [blame] | 17 | #include "pipeline/skia/SkiaOpenGLPipeline.h" |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 18 | |
Alec Mouri | 3afb397 | 2022-05-27 22:03:11 +0000 | [diff] [blame] | 19 | #include <SkBlendMode.h> |
| 20 | #include <SkImageInfo.h> |
| 21 | #include <cutils/properties.h> |
rnlee | ce9762b | 2021-05-21 15:40:53 -0700 | [diff] [blame] | 22 | #include <gui/TraceUtils.h> |
Nolan Scobie | 572d801 | 2024-08-30 13:43:34 -0400 | [diff] [blame^] | 23 | #include <include/gpu/ganesh/GrBackendSurface.h> |
Jerome Gaillard | bea67ce | 2024-03-28 14:21:16 +0000 | [diff] [blame] | 24 | #include <include/gpu/ganesh/SkSurfaceGanesh.h> |
| 25 | #include <include/gpu/ganesh/gl/GrGLBackendSurface.h> |
Nolan Scobie | 572d801 | 2024-08-30 13:43:34 -0400 | [diff] [blame^] | 26 | #include <include/gpu/ganesh/gl/GrGLTypes.h> |
Alec Mouri | 3afb397 | 2022-05-27 22:03:11 +0000 | [diff] [blame] | 27 | #include <strings.h> |
| 28 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 29 | #include "DeferredLayerUpdater.h" |
Alec Mouri | 3afb397 | 2022-05-27 22:03:11 +0000 | [diff] [blame] | 30 | #include "FrameInfo.h" |
Fedor Kudasov | 90df056 | 2019-06-19 11:41:34 +0100 | [diff] [blame] | 31 | #include "LightingInfo.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 32 | #include "hwui/Bitmap.h" |
Jerome Gaillard | bea67ce | 2024-03-28 14:21:16 +0000 | [diff] [blame] | 33 | #include "pipeline/skia/LayerDrawable.h" |
| 34 | #include "pipeline/skia/SkiaGpuPipeline.h" |
| 35 | #include "pipeline/skia/SkiaProfileRenderer.h" |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 36 | #include "private/hwui/DrawGlInfo.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 37 | #include "renderstate/RenderState.h" |
| 38 | #include "renderthread/EglManager.h" |
| 39 | #include "renderthread/Frame.h" |
Alec Mouri | 3afb397 | 2022-05-27 22:03:11 +0000 | [diff] [blame] | 40 | #include "renderthread/IRenderPipeline.h" |
John Reck | d9d7f12 | 2018-05-03 14:40:56 -0700 | [diff] [blame] | 41 | #include "utils/GLUtils.h" |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 42 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 43 | using namespace android::uirenderer::renderthread; |
| 44 | |
| 45 | namespace android { |
| 46 | namespace uirenderer { |
| 47 | namespace skiapipeline { |
| 48 | |
| 49 | SkiaOpenGLPipeline::SkiaOpenGLPipeline(RenderThread& thread) |
Jerome Gaillard | bea67ce | 2024-03-28 14:21:16 +0000 | [diff] [blame] | 50 | : SkiaGpuPipeline(thread), mEglManager(thread.eglManager()) { |
Derek Sollenberger | 5a5a648 | 2018-09-19 13:52:13 -0400 | [diff] [blame] | 51 | thread.renderState().registerContextCallback(this); |
| 52 | } |
| 53 | |
| 54 | SkiaOpenGLPipeline::~SkiaOpenGLPipeline() { |
| 55 | mRenderThread.renderState().removeContextCallback(this); |
| 56 | } |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 57 | |
| 58 | MakeCurrentResult SkiaOpenGLPipeline::makeCurrent() { |
Shih-Hsin Li | 4a012f5 | 2021-09-21 18:11:23 -0700 | [diff] [blame] | 59 | bool wasSurfaceless = mEglManager.isCurrent(EGL_NO_SURFACE); |
| 60 | |
Derek Sollenberger | b830772 | 2022-08-30 14:24:22 -0400 | [diff] [blame] | 61 | // In case the surface was destroyed (e.g. a previous trimMemory call) we |
| 62 | // need to recreate it here. |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 63 | if (mHardwareBuffer) { |
| 64 | mRenderThread.requireGlContext(); |
| 65 | } else if (!isSurfaceReady() && mNativeWindow) { |
Derek Sollenberger | b830772 | 2022-08-30 14:24:22 -0400 | [diff] [blame] | 66 | setSurface(mNativeWindow.get(), mSwapBehavior); |
| 67 | } |
| 68 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 69 | EGLint error = 0; |
| 70 | if (!mEglManager.makeCurrent(mEglSurface, &error)) { |
| 71 | return MakeCurrentResult::AlreadyCurrent; |
| 72 | } |
Shih-Hsin Li | 4a012f5 | 2021-09-21 18:11:23 -0700 | [diff] [blame] | 73 | |
Shih-hsin Li | d82c91d | 2023-04-21 12:13:47 -0700 | [diff] [blame] | 74 | EGLint majorVersion = 0; |
| 75 | eglQueryContext(eglGetCurrentDisplay(), eglGetCurrentContext(), EGL_CONTEXT_CLIENT_VERSION, &majorVersion); |
| 76 | |
| 77 | // Make sure read/draw buffer state of default framebuffer is GL_BACK for ES 3.X. Vendor implementations |
Shih-Hsin Li | 4a012f5 | 2021-09-21 18:11:23 -0700 | [diff] [blame] | 78 | // disagree on the draw/read buffer state if the default framebuffer transitions from a surface |
| 79 | // to EGL_NO_SURFACE and vice-versa. There was a related discussion within Khronos on this topic. |
| 80 | // See https://cvs.khronos.org/bugzilla/show_bug.cgi?id=13534. |
| 81 | // The discussion was not resolved with a clear consensus |
Shih-hsin Li | d82c91d | 2023-04-21 12:13:47 -0700 | [diff] [blame] | 82 | if (error == 0 && (majorVersion > 2) && wasSurfaceless && mEglSurface != EGL_NO_SURFACE) { |
Shih-Hsin Li | 4a012f5 | 2021-09-21 18:11:23 -0700 | [diff] [blame] | 83 | GLint curReadFB = 0; |
| 84 | GLint curDrawFB = 0; |
| 85 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &curReadFB); |
| 86 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &curDrawFB); |
| 87 | |
| 88 | GLint buffer = GL_NONE; |
| 89 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 90 | glGetIntegerv(GL_DRAW_BUFFER0, &buffer); |
| 91 | if (buffer == GL_NONE) { |
| 92 | const GLenum drawBuffer = GL_BACK; |
| 93 | glDrawBuffers(1, &drawBuffer); |
| 94 | } |
| 95 | |
| 96 | glGetIntegerv(GL_READ_BUFFER, &buffer); |
| 97 | if (buffer == GL_NONE) { |
| 98 | glReadBuffer(GL_BACK); |
| 99 | } |
| 100 | |
| 101 | glBindFramebuffer(GL_READ_FRAMEBUFFER, curReadFB); |
| 102 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, curDrawFB); |
| 103 | |
| 104 | GL_CHECKPOINT(LOW); |
| 105 | } |
| 106 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 107 | return error ? MakeCurrentResult::Failed : MakeCurrentResult::Succeeded; |
| 108 | } |
| 109 | |
| 110 | Frame SkiaOpenGLPipeline::getFrame() { |
Nader Jawad | 2461722 | 2023-03-30 12:29:01 -0700 | [diff] [blame] | 111 | LOG_ALWAYS_FATAL_IF(mEglSurface == EGL_NO_SURFACE, |
| 112 | "drawRenderNode called on a context with no surface!"); |
| 113 | return mEglManager.beginFrame(mEglSurface); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 114 | } |
| 115 | |
Alec Mouri | 3afb397 | 2022-05-27 22:03:11 +0000 | [diff] [blame] | 116 | IRenderPipeline::DrawResult SkiaOpenGLPipeline::draw( |
| 117 | const Frame& frame, const SkRect& screenDirty, const SkRect& dirty, |
| 118 | const LightGeometry& lightGeometry, LayerUpdateQueue* layerUpdateQueue, |
| 119 | const Rect& contentDrawBounds, bool opaque, const LightInfo& lightInfo, |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 120 | const std::vector<sp<RenderNode>>& renderNodes, FrameInfoVisualizer* profiler, |
Jiang Tian | e0edc3a | 2024-01-09 11:52:05 +0800 | [diff] [blame] | 121 | const HardwareBufferRenderParams& bufferParams, std::mutex& profilerLock) { |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 122 | if (!isCapturingSkp() && !mHardwareBuffer) { |
John Reck | 7600518 | 2021-06-09 22:43:05 -0400 | [diff] [blame] | 123 | mEglManager.damageFrame(frame, dirty); |
| 124 | } |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 125 | |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 126 | SkColorType colorType = getSurfaceColorType(); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 127 | // setup surface for fbo0 |
Greg Daniel | ac2d232 | 2017-07-12 11:30:15 -0400 | [diff] [blame] | 128 | GrGLFramebufferInfo fboInfo; |
| 129 | fboInfo.fFBOID = 0; |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 130 | if (colorType == kRGBA_F16_SkColorType) { |
Greg Daniel | c9da8e8 | 2018-03-21 10:50:24 -0400 | [diff] [blame] | 131 | fboInfo.fFormat = GL_RGBA16F; |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 132 | } else if (colorType == kN32_SkColorType) { |
| 133 | // Note: The default preference of pixel format is RGBA_8888, when other |
| 134 | // pixel format is available, we should branch out and do more check. |
Greg Daniel | c9da8e8 | 2018-03-21 10:50:24 -0400 | [diff] [blame] | 135 | fboInfo.fFormat = GL_RGBA8; |
John Reck | b36bfdd | 2020-07-23 13:47:49 -0700 | [diff] [blame] | 136 | } else if (colorType == kRGBA_1010102_SkColorType) { |
| 137 | fboInfo.fFormat = GL_RGB10_A2; |
Leon Scroggins III | e157ee8 | 2021-11-30 14:12:42 -0500 | [diff] [blame] | 138 | } else if (colorType == kAlpha_8_SkColorType) { |
| 139 | fboInfo.fFormat = GL_R8; |
Peiyong Lin | 1f6aa12 | 2018-09-10 16:28:08 -0700 | [diff] [blame] | 140 | } else { |
| 141 | LOG_ALWAYS_FATAL("Unsupported color type."); |
Greg Daniel | c9da8e8 | 2018-03-21 10:50:24 -0400 | [diff] [blame] | 142 | } |
Greg Daniel | ac2d232 | 2017-07-12 11:30:15 -0400 | [diff] [blame] | 143 | |
Kevin Lubick | 2757694 | 2023-08-16 12:50:44 +0000 | [diff] [blame] | 144 | auto backendRT = GrBackendRenderTargets::MakeGL(frame.width(), frame.height(), 0, |
| 145 | STENCIL_BUFFER_SIZE, fboInfo); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 146 | |
John Reck | b026f35 | 2023-04-05 13:19:15 -0400 | [diff] [blame] | 147 | SkSurfaceProps props(mColorMode == ColorMode::Default ? 0 : SkSurfaceProps::kAlwaysDither_Flag, |
| 148 | kUnknown_SkPixelGeometry); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 149 | |
| 150 | SkASSERT(mRenderThread.getGrContext() != nullptr); |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 151 | sk_sp<SkSurface> surface; |
| 152 | SkMatrix preTransform; |
| 153 | if (mHardwareBuffer) { |
| 154 | surface = getBufferSkSurface(bufferParams); |
| 155 | preTransform = bufferParams.getTransform(); |
| 156 | } else { |
Kevin Lubick | 6817fc4 | 2023-05-12 19:27:20 +0000 | [diff] [blame] | 157 | surface = SkSurfaces::WrapBackendRenderTarget(mRenderThread.getGrContext(), backendRT, |
| 158 | getSurfaceOrigin(), colorType, |
| 159 | mSurfaceColorSpace, &props); |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 160 | preTransform = SkMatrix::I(); |
| 161 | } |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 162 | |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 163 | SkPoint lightCenter = preTransform.mapXY(lightGeometry.center.x, lightGeometry.center.y); |
| 164 | LightGeometry localGeometry = lightGeometry; |
| 165 | localGeometry.center.x = lightCenter.fX; |
| 166 | localGeometry.center.y = lightCenter.fY; |
| 167 | LightingInfo::updateLighting(localGeometry, lightInfo); |
Greg Daniel | c407678 | 2019-01-08 16:01:18 -0500 | [diff] [blame] | 168 | renderFrame(*layerUpdateQueue, dirty, renderNodes, opaque, contentDrawBounds, surface, |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 169 | preTransform); |
Matt Sarett | cf2c05c | 2016-10-26 11:03:23 -0400 | [diff] [blame] | 170 | |
| 171 | // Draw visual debugging features |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 172 | if (CC_UNLIKELY(Properties::showDirtyRegions || |
| 173 | ProfileType::None != Properties::getProfileType())) { |
Jiang Tian | e0edc3a | 2024-01-09 11:52:05 +0800 | [diff] [blame] | 174 | std::scoped_lock lock(profilerLock); |
Matt Sarett | cf2c05c | 2016-10-26 11:03:23 -0400 | [diff] [blame] | 175 | SkCanvas* profileCanvas = surface->getCanvas(); |
John Reck | c30836d | 2022-08-12 14:28:31 -0400 | [diff] [blame] | 176 | SkiaProfileRenderer profileRenderer(profileCanvas, frame.width(), frame.height()); |
Matt Sarett | cf2c05c | 2016-10-26 11:03:23 -0400 | [diff] [blame] | 177 | profiler->draw(profileRenderer); |
Matt Sarett | cf2c05c | 2016-10-26 11:03:23 -0400 | [diff] [blame] | 178 | } |
| 179 | |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 180 | { |
| 181 | ATRACE_NAME("flush commands"); |
Kevin Lubick | aa592d0 | 2023-05-30 15:07:06 +0000 | [diff] [blame] | 182 | skgpu::ganesh::FlushAndSubmit(surface); |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 183 | } |
| 184 | layerUpdateQueue->clear(); |
| 185 | |
Matt Sarett | 4bda6bf | 2016-11-07 15:43:41 -0500 | [diff] [blame] | 186 | // Log memory statistics |
| 187 | if (CC_UNLIKELY(Properties::debugLevel != kDebugDisabled)) { |
| 188 | dumpResourceCacheUsage(); |
| 189 | } |
| 190 | |
John Reck | 5d3fac1 | 2023-11-08 23:08:10 -0500 | [diff] [blame] | 191 | return {true, IRenderPipeline::DrawResult::kUnknownTime, android::base::unique_fd{}}; |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 192 | } |
| 193 | |
John Reck | 5d3fac1 | 2023-11-08 23:08:10 -0500 | [diff] [blame] | 194 | bool SkiaOpenGLPipeline::swapBuffers(const Frame& frame, IRenderPipeline::DrawResult& drawResult, |
| 195 | const SkRect& screenDirty, FrameInfo* currentFrameInfo, |
| 196 | bool* requireSwap) { |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 197 | GL_CHECKPOINT(LOW); |
| 198 | |
| 199 | // Even if we decided to cancel the frame, from the perspective of jank |
| 200 | // metrics the frame was swapped at this point |
| 201 | currentFrameInfo->markSwapBuffers(); |
| 202 | |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 203 | if (mHardwareBuffer) { |
| 204 | return false; |
| 205 | } |
| 206 | |
John Reck | 5d3fac1 | 2023-11-08 23:08:10 -0500 | [diff] [blame] | 207 | *requireSwap = drawResult.success || mEglManager.damageRequiresSwap(); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 208 | |
| 209 | if (*requireSwap && (CC_UNLIKELY(!mEglManager.swapBuffers(frame, screenDirty)))) { |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | return *requireSwap; |
| 214 | } |
| 215 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 216 | DeferredLayerUpdater* SkiaOpenGLPipeline::createTextureLayer() { |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 217 | mRenderThread.requireGlContext(); |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 218 | return new DeferredLayerUpdater(mRenderThread.renderState()); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Derek Sollenberger | 5a5a648 | 2018-09-19 13:52:13 -0400 | [diff] [blame] | 221 | void SkiaOpenGLPipeline::onContextDestroyed() { |
| 222 | if (mEglSurface != EGL_NO_SURFACE) { |
| 223 | mEglManager.destroySurface(mEglSurface); |
| 224 | mEglSurface = EGL_NO_SURFACE; |
| 225 | } |
| 226 | } |
| 227 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 228 | void SkiaOpenGLPipeline::onStop() { |
| 229 | if (mEglManager.isCurrent(mEglSurface)) { |
| 230 | mEglManager.makeCurrent(EGL_NO_SURFACE); |
| 231 | } |
| 232 | } |
| 233 | |
John Reck | 8ddbc59 | 2020-05-07 16:11:18 -0700 | [diff] [blame] | 234 | bool SkiaOpenGLPipeline::setSurface(ANativeWindow* surface, SwapBehavior swapBehavior) { |
Derek Sollenberger | b830772 | 2022-08-30 14:24:22 -0400 | [diff] [blame] | 235 | mNativeWindow = surface; |
| 236 | mSwapBehavior = swapBehavior; |
| 237 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 238 | if (mEglSurface != EGL_NO_SURFACE) { |
| 239 | mEglManager.destroySurface(mEglSurface); |
| 240 | mEglSurface = EGL_NO_SURFACE; |
| 241 | } |
| 242 | |
| 243 | if (surface) { |
John Reck | 1e51071 | 2018-04-23 08:15:03 -0700 | [diff] [blame] | 244 | mRenderThread.requireGlContext(); |
Derek Sollenberger | 1863d94 | 2020-02-05 15:41:51 -0500 | [diff] [blame] | 245 | auto newSurface = mEglManager.createSurface(surface, mColorMode, mSurfaceColorSpace); |
John Reck | 8e539ca | 2018-11-15 15:21:29 -0800 | [diff] [blame] | 246 | if (!newSurface) { |
| 247 | return false; |
| 248 | } |
| 249 | mEglSurface = newSurface.unwrap(); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | if (mEglSurface != EGL_NO_SURFACE) { |
| 253 | const bool preserveBuffer = (swapBehavior != SwapBehavior::kSwap_discardBuffer); |
John Reck | 3c26088 | 2023-05-30 17:39:21 -0400 | [diff] [blame] | 254 | mEglManager.setPreserveBuffer(mEglSurface, preserveBuffer); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 255 | return true; |
| 256 | } |
| 257 | |
| 258 | return false; |
| 259 | } |
| 260 | |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 261 | [[nodiscard]] android::base::unique_fd SkiaOpenGLPipeline::flush() { |
| 262 | int fence = -1; |
| 263 | EGLSyncKHR sync = EGL_NO_SYNC_KHR; |
| 264 | mEglManager.createReleaseFence(true, &sync, &fence); |
| 265 | // If a sync object is returned here then the device does not support native |
| 266 | // fences, we block on the returned sync and return -1 as a file descriptor |
| 267 | if (sync != EGL_NO_SYNC_KHR) { |
| 268 | EGLDisplay display = mEglManager.eglDisplay(); |
| 269 | EGLint result = eglClientWaitSyncKHR(display, sync, 0, 1000000000); |
| 270 | if (result == EGL_FALSE) { |
| 271 | ALOGE("EglManager::createReleaseFence: error waiting for previous fence: %#x", |
| 272 | eglGetError()); |
| 273 | } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { |
| 274 | ALOGE("EglManager::createReleaseFence: timeout waiting for previous fence"); |
| 275 | } |
| 276 | eglDestroySyncKHR(display, sync); |
| 277 | } |
| 278 | return android::base::unique_fd(fence); |
| 279 | } |
| 280 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 281 | bool SkiaOpenGLPipeline::isSurfaceReady() { |
| 282 | return CC_UNLIKELY(mEglSurface != EGL_NO_SURFACE); |
| 283 | } |
| 284 | |
| 285 | bool SkiaOpenGLPipeline::isContextReady() { |
| 286 | return CC_LIKELY(mEglManager.hasEglContext()); |
| 287 | } |
| 288 | |
| 289 | void SkiaOpenGLPipeline::invokeFunctor(const RenderThread& thread, Functor* functor) { |
| 290 | DrawGlInfo::Mode mode = DrawGlInfo::kModeProcessNoContext; |
| 291 | if (thread.eglManager().hasEglContext()) { |
| 292 | mode = DrawGlInfo::kModeProcess; |
| 293 | } |
| 294 | |
| 295 | (*functor)(mode, nullptr); |
| 296 | |
| 297 | // If there's no context we don't need to reset as there's no gl state to save/restore |
| 298 | if (mode != DrawGlInfo::kModeProcessNoContext) { |
| 299 | thread.getGrContext()->resetContext(); |
| 300 | } |
| 301 | } |
| 302 | |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 303 | } /* namespace skiapipeline */ |
| 304 | } /* namespace uirenderer */ |
| 305 | } /* namespace android */ |