RenderProxy.cpp revision 2de950d5a8b47c7b4648ada1b1260ce4b7342798
1/* 2 * Copyright (C) 2013 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 "RenderProxy.h" 18 19#include "DeferredLayerUpdater.h" 20#include "DisplayList.h" 21#include "Readback.h" 22#include "Rect.h" 23#include "renderthread/CanvasContext.h" 24#include "renderthread/EglManager.h" 25#include "renderthread/RenderTask.h" 26#include "renderthread/RenderThread.h" 27#include "utils/Macros.h" 28#include "utils/TimeUtils.h" 29 30#include <ui/GraphicBuffer.h> 31 32namespace android { 33namespace uirenderer { 34namespace renderthread { 35 36#define ARGS(method) method ## Args 37 38#define CREATE_BRIDGE0(name) CREATE_BRIDGE(name,,,,,,,,) 39#define CREATE_BRIDGE1(name, a1) CREATE_BRIDGE(name, a1,,,,,,,) 40#define CREATE_BRIDGE2(name, a1, a2) CREATE_BRIDGE(name, a1,a2,,,,,,) 41#define CREATE_BRIDGE3(name, a1, a2, a3) CREATE_BRIDGE(name, a1,a2,a3,,,,,) 42#define CREATE_BRIDGE4(name, a1, a2, a3, a4) CREATE_BRIDGE(name, a1,a2,a3,a4,,,,) 43#define CREATE_BRIDGE5(name, a1, a2, a3, a4, a5) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,,,) 44#define CREATE_BRIDGE6(name, a1, a2, a3, a4, a5, a6) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,,) 45#define CREATE_BRIDGE7(name, a1, a2, a3, a4, a5, a6, a7) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,a7,) 46#define CREATE_BRIDGE(name, a1, a2, a3, a4, a5, a6, a7, a8) \ 47 typedef struct { \ 48 a1; a2; a3; a4; a5; a6; a7; a8; \ 49 } ARGS(name); \ 50 static_assert(std::is_trivially_destructible<ARGS(name)>::value, \ 51 "Error, ARGS must be trivially destructible!"); \ 52 static void* Bridge_ ## name(ARGS(name)* args) 53 54#define SETUP_TASK(method) \ 55 LOG_ALWAYS_FATAL_IF( METHOD_INVOKE_PAYLOAD_SIZE < sizeof(ARGS(method)), \ 56 "METHOD_INVOKE_PAYLOAD_SIZE %zu is smaller than sizeof(" #method "Args) %zu", \ 57 METHOD_INVOKE_PAYLOAD_SIZE, sizeof(ARGS(method))); \ 58 MethodInvokeRenderTask* task = new MethodInvokeRenderTask((RunnableMethod) Bridge_ ## method); \ 59 ARGS(method) *args = (ARGS(method) *) task->payload() 60 61CREATE_BRIDGE4(createContext, RenderThread* thread, bool translucent, 62 RenderNode* rootRenderNode, IContextFactory* contextFactory) { 63 return CanvasContext::create(*args->thread, args->translucent, 64 args->rootRenderNode, args->contextFactory); 65} 66 67RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory) 68 : mRenderThread(RenderThread::getInstance()) 69 , mContext(nullptr) { 70 SETUP_TASK(createContext); 71 args->translucent = translucent; 72 args->rootRenderNode = rootRenderNode; 73 args->thread = &mRenderThread; 74 args->contextFactory = contextFactory; 75 mContext = (CanvasContext*) postAndWait(task); 76 mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode); 77} 78 79RenderProxy::~RenderProxy() { 80 destroyContext(); 81} 82 83CREATE_BRIDGE1(destroyContext, CanvasContext* context) { 84 delete args->context; 85 return nullptr; 86} 87 88void RenderProxy::destroyContext() { 89 if (mContext) { 90 SETUP_TASK(destroyContext); 91 args->context = mContext; 92 mContext = nullptr; 93 mDrawFrameTask.setContext(nullptr, nullptr, nullptr); 94 // This is also a fence as we need to be certain that there are no 95 // outstanding mDrawFrame tasks posted before it is destroyed 96 postAndWait(task); 97 } 98} 99 100CREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) { 101 args->context->setSwapBehavior(args->swapBehavior); 102 return nullptr; 103} 104 105void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) { 106 SETUP_TASK(setSwapBehavior); 107 args->context = mContext; 108 args->swapBehavior = swapBehavior; 109 post(task); 110} 111 112CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) { 113 bool needsRedraw = false; 114 if (Caches::hasInstance()) { 115 needsRedraw = Properties::load(); 116 } 117 if (args->context->profiler().consumeProperties()) { 118 needsRedraw = true; 119 } 120 return (void*) needsRedraw; 121} 122 123bool RenderProxy::loadSystemProperties() { 124 SETUP_TASK(loadSystemProperties); 125 args->context = mContext; 126 return (bool) postAndWait(task); 127} 128 129CREATE_BRIDGE2(setName, CanvasContext* context, const char* name) { 130 args->context->setName(std::string(args->name)); 131 return nullptr; 132} 133 134void RenderProxy::setName(const char* name) { 135 SETUP_TASK(setName); 136 args->context = mContext; 137 args->name = name; 138 postAndWait(task); // block since name/value pointers owned by caller 139} 140 141CREATE_BRIDGE2(initialize, CanvasContext* context, Surface* surface) { 142 args->context->initialize(args->surface); 143 return nullptr; 144} 145 146void RenderProxy::initialize(const sp<Surface>& surface) { 147 SETUP_TASK(initialize); 148 args->context = mContext; 149 args->surface = surface.get(); 150 post(task); 151} 152 153CREATE_BRIDGE2(updateSurface, CanvasContext* context, Surface* surface) { 154 args->context->updateSurface(args->surface); 155 return nullptr; 156} 157 158void RenderProxy::updateSurface(const sp<Surface>& surface) { 159 SETUP_TASK(updateSurface); 160 args->context = mContext; 161 args->surface = surface.get(); 162 post(task); 163} 164 165CREATE_BRIDGE2(pauseSurface, CanvasContext* context, Surface* surface) { 166 return (void*) args->context->pauseSurface(args->surface); 167} 168 169bool RenderProxy::pauseSurface(const sp<Surface>& surface) { 170 SETUP_TASK(pauseSurface); 171 args->context = mContext; 172 args->surface = surface.get(); 173 return (bool) postAndWait(task); 174} 175 176CREATE_BRIDGE2(setStopped, CanvasContext* context, bool stopped) { 177 args->context->setStopped(args->stopped); 178 return nullptr; 179} 180 181void RenderProxy::setStopped(bool stopped) { 182 SETUP_TASK(setStopped); 183 args->context = mContext; 184 args->stopped = stopped; 185 postAndWait(task); 186} 187 188CREATE_BRIDGE4(setup, CanvasContext* context, 189 float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { 190 args->context->setup(args->lightRadius, 191 args->ambientShadowAlpha, args->spotShadowAlpha); 192 return nullptr; 193} 194 195void RenderProxy::setup(float lightRadius, 196 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { 197 SETUP_TASK(setup); 198 args->context = mContext; 199 args->lightRadius = lightRadius; 200 args->ambientShadowAlpha = ambientShadowAlpha; 201 args->spotShadowAlpha = spotShadowAlpha; 202 post(task); 203} 204 205CREATE_BRIDGE2(setLightCenter, CanvasContext* context, Vector3 lightCenter) { 206 args->context->setLightCenter(args->lightCenter); 207 return nullptr; 208} 209 210void RenderProxy::setLightCenter(const Vector3& lightCenter) { 211 SETUP_TASK(setLightCenter); 212 args->context = mContext; 213 args->lightCenter = lightCenter; 214 post(task); 215} 216 217CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) { 218 args->context->setOpaque(args->opaque); 219 return nullptr; 220} 221 222void RenderProxy::setOpaque(bool opaque) { 223 SETUP_TASK(setOpaque); 224 args->context = mContext; 225 args->opaque = opaque; 226 post(task); 227} 228 229int64_t* RenderProxy::frameInfo() { 230 return mDrawFrameTask.frameInfo(); 231} 232 233int RenderProxy::syncAndDrawFrame() { 234 return mDrawFrameTask.drawFrame(); 235} 236 237CREATE_BRIDGE1(destroy, CanvasContext* context) { 238 args->context->destroy(); 239 return nullptr; 240} 241 242void RenderProxy::destroy() { 243 SETUP_TASK(destroy); 244 args->context = mContext; 245 // destroyCanvasAndSurface() needs a fence as when it returns the 246 // underlying BufferQueue is going to be released from under 247 // the render thread. 248 postAndWait(task); 249} 250 251CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) { 252 CanvasContext::invokeFunctor(*args->thread, args->functor); 253 return nullptr; 254} 255 256void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) { 257 ATRACE_CALL(); 258 RenderThread& thread = RenderThread::getInstance(); 259 SETUP_TASK(invokeFunctor); 260 args->thread = &thread; 261 args->functor = functor; 262 if (waitForCompletion) { 263 // waitForCompletion = true is expected to be fairly rare and only 264 // happen in destruction. Thus it should be fine to temporarily 265 // create a Mutex 266 staticPostAndWait(task); 267 } else { 268 thread.queue(task); 269 } 270} 271 272CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) { 273 return args->context->createTextureLayer(); 274} 275 276DeferredLayerUpdater* RenderProxy::createTextureLayer() { 277 SETUP_TASK(createTextureLayer); 278 args->context = mContext; 279 void* retval = postAndWait(task); 280 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); 281 return layer; 282} 283 284CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) { 285 args->context->buildLayer(args->node); 286 return nullptr; 287} 288 289void RenderProxy::buildLayer(RenderNode* node) { 290 SETUP_TASK(buildLayer); 291 args->context = mContext; 292 args->node = node; 293 postAndWait(task); 294} 295 296CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer, 297 SkBitmap* bitmap) { 298 bool success = args->context->copyLayerInto(args->layer, args->bitmap); 299 return (void*) success; 300} 301 302bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) { 303 SETUP_TASK(copyLayerInto); 304 args->context = mContext; 305 args->layer = layer; 306 args->bitmap = &bitmap; 307 return (bool) postAndWait(task); 308} 309 310void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) { 311 mDrawFrameTask.pushLayerUpdate(layer); 312} 313 314void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) { 315 mDrawFrameTask.removeLayerUpdate(layer); 316} 317 318CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) { 319 args->layer->detachSurfaceTexture(); 320 return nullptr; 321} 322 323void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) { 324 SETUP_TASK(detachSurfaceTexture); 325 args->layer = layer; 326 postAndWait(task); 327} 328 329CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) { 330 args->context->destroyHardwareResources(); 331 return nullptr; 332} 333 334void RenderProxy::destroyHardwareResources() { 335 SETUP_TASK(destroyHardwareResources); 336 args->context = mContext; 337 postAndWait(task); 338} 339 340CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) { 341 CanvasContext::trimMemory(*args->thread, args->level); 342 return nullptr; 343} 344 345void RenderProxy::trimMemory(int level) { 346 // Avoid creating a RenderThread to do a trimMemory. 347 if (RenderThread::hasInstance()) { 348 RenderThread& thread = RenderThread::getInstance(); 349 SETUP_TASK(trimMemory); 350 args->thread = &thread; 351 args->level = level; 352 thread.queue(task); 353 } 354} 355 356CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) { 357 Properties::overrideProperty(args->name, args->value); 358 return nullptr; 359} 360 361void RenderProxy::overrideProperty(const char* name, const char* value) { 362 SETUP_TASK(overrideProperty); 363 args->name = name; 364 args->value = value; 365 staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller 366} 367 368CREATE_BRIDGE0(fence) { 369 // Intentionally empty 370 return nullptr; 371} 372 373template <typename T> 374void UNUSED(T t) {} 375 376void RenderProxy::fence() { 377 SETUP_TASK(fence); 378 UNUSED(args); 379 postAndWait(task); 380} 381 382void RenderProxy::staticFence() { 383 SETUP_TASK(fence); 384 UNUSED(args); 385 staticPostAndWait(task); 386} 387 388CREATE_BRIDGE1(stopDrawing, CanvasContext* context) { 389 args->context->stopDrawing(); 390 return nullptr; 391} 392 393void RenderProxy::stopDrawing() { 394 SETUP_TASK(stopDrawing); 395 args->context = mContext; 396 postAndWait(task); 397} 398 399CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) { 400 args->context->notifyFramePending(); 401 return nullptr; 402} 403 404void RenderProxy::notifyFramePending() { 405 SETUP_TASK(notifyFramePending); 406 args->context = mContext; 407 mRenderThread.queueAtFront(task); 408} 409 410CREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread, 411 int fd, int dumpFlags) { 412 args->context->profiler().dumpData(args->fd); 413 if (args->dumpFlags & DumpFlags::FrameStats) { 414 args->context->dumpFrames(args->fd); 415 } 416 if (args->dumpFlags & DumpFlags::Reset) { 417 args->context->resetFrameStats(); 418 } 419 if (args->dumpFlags & DumpFlags::JankStats) { 420 args->thread->jankTracker().dump(args->fd); 421 } 422 return nullptr; 423} 424 425void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) { 426 SETUP_TASK(dumpProfileInfo); 427 args->context = mContext; 428 args->thread = &mRenderThread; 429 args->fd = fd; 430 args->dumpFlags = dumpFlags; 431 postAndWait(task); 432} 433 434CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) { 435 args->context->resetFrameStats(); 436 return nullptr; 437} 438 439void RenderProxy::resetProfileInfo() { 440 SETUP_TASK(resetProfileInfo); 441 args->context = mContext; 442 postAndWait(task); 443} 444 445CREATE_BRIDGE2(frameTimePercentile, RenderThread* thread, int percentile) { 446 return reinterpret_cast<void*>(static_cast<uintptr_t>( 447 args->thread->jankTracker().findPercentile(args->percentile))); 448} 449 450uint32_t RenderProxy::frameTimePercentile(int p) { 451 SETUP_TASK(frameTimePercentile); 452 args->thread = &mRenderThread; 453 args->percentile = p; 454 return static_cast<uint32_t>(reinterpret_cast<uintptr_t>( 455 postAndWait(task))); 456} 457 458CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) { 459 args->thread->jankTracker().dump(args->fd); 460 461 FILE *file = fdopen(args->fd, "a"); 462 if (Caches::hasInstance()) { 463 String8 cachesLog; 464 Caches::getInstance().dumpMemoryUsage(cachesLog); 465 fprintf(file, "\nCaches:\n%s\n", cachesLog.string()); 466 } else { 467 fprintf(file, "\nNo caches instance.\n"); 468 } 469 fprintf(file, "\nPipeline=FrameBuilder\n"); 470 fflush(file); 471 return nullptr; 472} 473 474void RenderProxy::dumpGraphicsMemory(int fd) { 475 if (!RenderThread::hasInstance()) return; 476 SETUP_TASK(dumpGraphicsMemory); 477 args->fd = fd; 478 args->thread = &RenderThread::getInstance(); 479 staticPostAndWait(task); 480} 481 482CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) { 483 args->thread->jankTracker().switchStorageToAshmem(args->fd); 484 close(args->fd); 485 return nullptr; 486} 487 488void RenderProxy::setProcessStatsBuffer(int fd) { 489 SETUP_TASK(setProcessStatsBuffer); 490 args->thread = &mRenderThread; 491 args->fd = dup(fd); 492 post(task); 493} 494 495int RenderProxy::getRenderThreadTid() { 496 return mRenderThread.getTid(); 497} 498 499CREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) { 500 args->context->addRenderNode(args->node, args->placeFront); 501 return nullptr; 502} 503 504void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) { 505 SETUP_TASK(addRenderNode); 506 args->context = mContext; 507 args->node = node; 508 args->placeFront = placeFront; 509 post(task); 510} 511 512CREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) { 513 args->context->removeRenderNode(args->node); 514 return nullptr; 515} 516 517void RenderProxy::removeRenderNode(RenderNode* node) { 518 SETUP_TASK(removeRenderNode); 519 args->context = mContext; 520 args->node = node; 521 post(task); 522} 523 524CREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) { 525 args->context->prepareAndDraw(args->node); 526 return nullptr; 527} 528 529void RenderProxy::drawRenderNode(RenderNode* node) { 530 SETUP_TASK(drawRenderNode); 531 args->context = mContext; 532 args->node = node; 533 // Be pseudo-thread-safe and don't use any member variables 534 staticPostAndWait(task); 535} 536 537CREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top, 538 int right, int bottom) { 539 args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom); 540 return nullptr; 541} 542 543void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) { 544 SETUP_TASK(setContentDrawBounds); 545 args->context = mContext; 546 args->left = left; 547 args->top = top; 548 args->right = right; 549 args->bottom = bottom; 550 staticPostAndWait(task); 551} 552 553CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) { 554 args->context->serializeDisplayListTree(); 555 return nullptr; 556} 557 558void RenderProxy::serializeDisplayListTree() { 559 SETUP_TASK(serializeDisplayListTree); 560 args->context = mContext; 561 post(task); 562} 563 564CREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context, 565 FrameMetricsObserver* frameStatsObserver) { 566 args->context->addFrameMetricsObserver(args->frameStatsObserver); 567 if (args->frameStatsObserver != nullptr) { 568 args->frameStatsObserver->decStrong(args->context); 569 } 570 return nullptr; 571} 572 573void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) { 574 SETUP_TASK(addFrameMetricsObserver); 575 args->context = mContext; 576 args->frameStatsObserver = observer; 577 if (observer != nullptr) { 578 observer->incStrong(mContext); 579 } 580 post(task); 581} 582 583CREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context, 584 FrameMetricsObserver* frameStatsObserver) { 585 args->context->removeFrameMetricsObserver(args->frameStatsObserver); 586 if (args->frameStatsObserver != nullptr) { 587 args->frameStatsObserver->decStrong(args->context); 588 } 589 return nullptr; 590} 591 592void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) { 593 SETUP_TASK(removeFrameMetricsObserver); 594 args->context = mContext; 595 args->frameStatsObserver = observer; 596 if (observer != nullptr) { 597 observer->incStrong(mContext); 598 } 599 post(task); 600} 601 602CREATE_BRIDGE4(copySurfaceInto, RenderThread* thread, 603 Surface* surface, Rect srcRect, SkBitmap* bitmap) { 604 return (void*)args->thread->readback().copySurfaceInto(*args->surface, 605 args->srcRect, args->bitmap); 606} 607 608int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, 609 int right, int bottom, SkBitmap* bitmap) { 610 SETUP_TASK(copySurfaceInto); 611 args->bitmap = bitmap; 612 args->surface = surface.get(); 613 args->thread = &RenderThread::getInstance(); 614 args->srcRect.set(left, top, right, bottom); 615 return static_cast<int>( 616 reinterpret_cast<intptr_t>( staticPostAndWait(task) )); 617} 618 619CREATE_BRIDGE2(prepareToDraw, RenderThread* thread, Bitmap* bitmap) { 620 CanvasContext::prepareToDraw(*args->thread, args->bitmap); 621 args->bitmap->unref(); 622 args->bitmap = nullptr; 623 return nullptr; 624} 625 626void RenderProxy::prepareToDraw(Bitmap& bitmap) { 627 // If we haven't spun up a hardware accelerated window yet, there's no 628 // point in precaching these bitmaps as it can't impact jank. 629 // We also don't know if we even will spin up a hardware-accelerated 630 // window or not. 631 if (!RenderThread::hasInstance()) return; 632 RenderThread* renderThread = &RenderThread::getInstance(); 633 SETUP_TASK(prepareToDraw); 634 args->thread = renderThread; 635 bitmap.ref(); 636 args->bitmap = &bitmap; 637 nsecs_t lastVsync = renderThread->timeLord().latestVsync(); 638 nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos(); 639 nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(CLOCK_MONOTONIC); 640 // We expect the UI thread to take 4ms and for RT to be active from VSYNC+4ms to 641 // VSYNC+12ms or so, so aim for the gap during which RT is expected to 642 // be idle 643 // TODO: Make this concept a first-class supported thing? RT could use 644 // knowledge of pending draws to better schedule this task 645 if (timeToNextVsync > -6_ms && timeToNextVsync < 1_ms) { 646 renderThread->queueAt(task, estimatedNextVsync + 8_ms); 647 } else { 648 renderThread->queue(task); 649 } 650} 651 652CREATE_BRIDGE2(allocateHardwareBitmap, RenderThread* thread, SkBitmap* bitmap) { 653 sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(*args->thread, *args->bitmap); 654 return hardwareBitmap.release(); 655} 656 657sk_sp<Bitmap> RenderProxy::allocateHardwareBitmap(SkBitmap& bitmap) { 658 SETUP_TASK(allocateHardwareBitmap); 659 args->bitmap = &bitmap; 660 args->thread = &RenderThread::getInstance(); 661 sk_sp<Bitmap> hardwareBitmap(reinterpret_cast<Bitmap*>(staticPostAndWait(task))); 662 return hardwareBitmap; 663} 664 665CREATE_BRIDGE3(copyGraphicBufferInto, RenderThread* thread, GraphicBuffer* buffer, SkBitmap* bitmap) { 666 return (void*) args->thread->readback().copyGraphicBufferInto(args->buffer, args->bitmap); 667} 668 669int RenderProxy::copyGraphicBufferInto(GraphicBuffer* buffer, SkBitmap* bitmap) { 670 SETUP_TASK(copyGraphicBufferInto); 671 args->thread = &RenderThread::getInstance(); 672 args->bitmap = bitmap; 673 args->buffer = buffer; 674 return static_cast<int>(reinterpret_cast<intptr_t>(staticPostAndWait(task))); 675} 676 677void RenderProxy::post(RenderTask* task) { 678 mRenderThread.queue(task); 679} 680 681void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { 682 void* retval; 683 task->setReturnPtr(&retval); 684 SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); 685 AutoMutex _lock(mSyncMutex); 686 mRenderThread.queue(&syncTask); 687 mSyncCondition.wait(mSyncMutex); 688 return retval; 689} 690 691void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) { 692 RenderThread& thread = RenderThread::getInstance(); 693 void* retval; 694 task->setReturnPtr(&retval); 695 thread.queueAndWait(task); 696 return retval; 697} 698 699} /* namespace renderthread */ 700} /* namespace uirenderer */ 701} /* namespace android */ 702