14f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck/* 24f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * Copyright (C) 2013 The Android Open Source Project 34f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * 44f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 54f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * you may not use this file except in compliance with the License. 64f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * You may obtain a copy of the License at 74f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * 84f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * http://www.apache.org/licenses/LICENSE-2.0 94f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * 104f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * Unless required by applicable law or agreed to in writing, software 114f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * distributed under the License is distributed on an "AS IS" BASIS, 124f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * See the License for the specific language governing permissions and 144f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * limitations under the License. 154f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck */ 164f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 174f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck#include "RenderProxy.h" 184f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 19ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "DeferredLayerUpdater.h" 20ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "DisplayList.h" 21ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "LayerRenderer.h" 2210dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck#include "Readback.h" 23ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "Rect.h" 24ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "renderthread/CanvasContext.h" 25ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "renderthread/RenderTask.h" 26ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "renderthread/RenderThread.h" 27ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck#include "utils/Macros.h" 284f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 294f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Recknamespace android { 304f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Recknamespace uirenderer { 314f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Recknamespace renderthread { 324f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 334f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck#define ARGS(method) method ## Args 344f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 3519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck#define CREATE_BRIDGE0(name) CREATE_BRIDGE(name,,,,,,,,) 364f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck#define CREATE_BRIDGE1(name, a1) CREATE_BRIDGE(name, a1,,,,,,,) 374f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck#define CREATE_BRIDGE2(name, a1, a2) CREATE_BRIDGE(name, a1,a2,,,,,,) 384f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck#define CREATE_BRIDGE3(name, a1, a2, a3) CREATE_BRIDGE(name, a1,a2,a3,,,,,) 394f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck#define CREATE_BRIDGE4(name, a1, a2, a3, a4) CREATE_BRIDGE(name, a1,a2,a3,a4,,,,) 40797b95b26bbb7557678af78b9a2a61830158920fChris Craik#define CREATE_BRIDGE5(name, a1, a2, a3, a4, a5) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,,,) 41058fc640017c90120c599d378a4cbc55668b05b7Chris Craik#define CREATE_BRIDGE6(name, a1, a2, a3, a4, a5, a6) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,,) 42058fc640017c90120c599d378a4cbc55668b05b7Chris Craik#define CREATE_BRIDGE7(name, a1, a2, a3, a4, a5, a6, a7) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,a7,) 434f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck#define CREATE_BRIDGE(name, a1, a2, a3, a4, a5, a6, a7, a8) \ 444f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck typedef struct { \ 454f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck a1; a2; a3; a4; a5; a6; a7; a8; \ 464f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck } ARGS(name); \ 474f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck static void* Bridge_ ## name(ARGS(name)* args) 484f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 494f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck#define SETUP_TASK(method) \ 504f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck LOG_ALWAYS_FATAL_IF( METHOD_INVOKE_PAYLOAD_SIZE < sizeof(ARGS(method)), \ 51546f353e7f562fdbcf59980bcb7dc11567658aa3Mark Salyzyn "METHOD_INVOKE_PAYLOAD_SIZE %zu is smaller than sizeof(" #method "Args) %zu", \ 524f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck METHOD_INVOKE_PAYLOAD_SIZE, sizeof(ARGS(method))); \ 53e2c455264351964bf1ae78da2256c17258f0d3eaJohn Reck MethodInvokeRenderTask* task = new MethodInvokeRenderTask((RunnableMethod) Bridge_ ## method); \ 544f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck ARGS(method) *args = (ARGS(method) *) task->payload() 554f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 56119907cd2575c56b1ebf66348b52e67aaf6a88d8John ReckCREATE_BRIDGE4(createContext, RenderThread* thread, bool translucent, 57119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck RenderNode* rootRenderNode, IContextFactory* contextFactory) { 58119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck return new CanvasContext(*args->thread, args->translucent, 59119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck args->rootRenderNode, args->contextFactory); 604f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 614f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 62119907cd2575c56b1ebf66348b52e67aaf6a88d8John ReckRenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory) 634f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck : mRenderThread(RenderThread::getInstance()) 64d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik , mContext(nullptr) { 654f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck SETUP_TASK(createContext); 664f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck args->translucent = translucent; 67e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck args->rootRenderNode = rootRenderNode; 683b20251a355c88193c439f928a84ae69483fb488John Reck args->thread = &mRenderThread; 69119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck args->contextFactory = contextFactory; 704f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck mContext = (CanvasContext*) postAndWait(task); 71ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode); 724f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 734f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 744f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John ReckRenderProxy::~RenderProxy() { 754f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck destroyContext(); 764f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 774f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 784f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John ReckCREATE_BRIDGE1(destroyContext, CanvasContext* context) { 794f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck delete args->context; 80d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 814f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 824f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 834f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reckvoid RenderProxy::destroyContext() { 844f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck if (mContext) { 854f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck SETUP_TASK(destroyContext); 864f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck args->context = mContext; 87d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik mContext = nullptr; 88ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne mDrawFrameTask.setContext(nullptr, nullptr, nullptr); 89668f0e38ef0277d55d3118af37e17b8c435df85cJohn Reck // This is also a fence as we need to be certain that there are no 90668f0e38ef0277d55d3118af37e17b8c435df85cJohn Reck // outstanding mDrawFrame tasks posted before it is destroyed 91668f0e38ef0277d55d3118af37e17b8c435df85cJohn Reck postAndWait(task); 924f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck } 934f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 944f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 951125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn ReckCREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) { 961125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck args->context->setSwapBehavior(args->swapBehavior); 97d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 981125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck} 991125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck 1001125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reckvoid RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) { 1011125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck SETUP_TASK(setSwapBehavior); 1021125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck args->context = mContext; 1031125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck args->swapBehavior = swapBehavior; 1041125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck post(task); 1051125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck} 1061125d1fa92ab9f3b8315bbfb72e038b62dfd454bJohn Reck 107fe5e7b7346a54537b980796ceeca66bfdbd05561John ReckCREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) { 108e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck bool needsRedraw = false; 109e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck if (Caches::hasInstance()) { 1102507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik needsRedraw = Properties::load(); 111e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck } 1122507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik if (args->context->profiler().consumeProperties()) { 113fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck needsRedraw = true; 114fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck } 115e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck return (void*) needsRedraw; 116e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck} 117e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck 118e4280baaa709c74d86cf6a389a4674ca665f5af6John Reckbool RenderProxy::loadSystemProperties() { 119e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck SETUP_TASK(loadSystemProperties); 120fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck args->context = mContext; 121e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck return (bool) postAndWait(task); 122e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck} 123e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck 124b36016c65f1d1b5846dba0349aab491dbd3a746aJohn ReckCREATE_BRIDGE2(setName, CanvasContext* context, const char* name) { 125b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck args->context->setName(std::string(args->name)); 126b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck return nullptr; 127b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck} 128b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck 129b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reckvoid RenderProxy::setName(const char* name) { 130b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck SETUP_TASK(setName); 131b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck args->context = mContext; 132b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck args->name = name; 1332507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik postAndWait(task); // block since name/value pointers owned by caller 134b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck} 135b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck 136f648108f83d4e74811919e9811efb8fcc184b8a3John ReckCREATE_BRIDGE2(initialize, CanvasContext* context, Surface* surface) { 137f648108f83d4e74811919e9811efb8fcc184b8a3John Reck args->context->initialize(args->surface); 1380bcd0cb6b1193168fa2840855195347488daab9eThomas Buhot return nullptr; 1394f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 1404f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 141f648108f83d4e74811919e9811efb8fcc184b8a3John Reckvoid RenderProxy::initialize(const sp<Surface>& surface) { 1424f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck SETUP_TASK(initialize); 1434f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck args->context = mContext; 144f648108f83d4e74811919e9811efb8fcc184b8a3John Reck args->surface = surface.get(); 1450bcd0cb6b1193168fa2840855195347488daab9eThomas Buhot post(task); 1464f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 1474f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 148f648108f83d4e74811919e9811efb8fcc184b8a3John ReckCREATE_BRIDGE2(updateSurface, CanvasContext* context, Surface* surface) { 149f648108f83d4e74811919e9811efb8fcc184b8a3John Reck args->context->updateSurface(args->surface); 150d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 1514f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 1524f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 153f648108f83d4e74811919e9811efb8fcc184b8a3John Reckvoid RenderProxy::updateSurface(const sp<Surface>& surface) { 1544f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck SETUP_TASK(updateSurface); 1554f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck args->context = mContext; 156f648108f83d4e74811919e9811efb8fcc184b8a3John Reck args->surface = surface.get(); 157f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck postAndWait(task); 158f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck} 159f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck 160f648108f83d4e74811919e9811efb8fcc184b8a3John ReckCREATE_BRIDGE2(pauseSurface, CanvasContext* context, Surface* surface) { 161f648108f83d4e74811919e9811efb8fcc184b8a3John Reck return (void*) args->context->pauseSurface(args->surface); 162f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck} 163f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck 164f648108f83d4e74811919e9811efb8fcc184b8a3John Reckbool RenderProxy::pauseSurface(const sp<Surface>& surface) { 165f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck SETUP_TASK(pauseSurface); 166f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck args->context = mContext; 167f648108f83d4e74811919e9811efb8fcc184b8a3John Reck args->surface = surface.get(); 16801a5ea35fbba4c5bb1d7790ae1677a2fa752e042John Reck return (bool) postAndWait(task); 1694f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 1704f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 1718afcc76920499d0a384dba1470c5a377f80ed768John ReckCREATE_BRIDGE2(setStopped, CanvasContext* context, bool stopped) { 1728afcc76920499d0a384dba1470c5a377f80ed768John Reck args->context->setStopped(args->stopped); 1738afcc76920499d0a384dba1470c5a377f80ed768John Reck return nullptr; 1748afcc76920499d0a384dba1470c5a377f80ed768John Reck} 1758afcc76920499d0a384dba1470c5a377f80ed768John Reck 1768afcc76920499d0a384dba1470c5a377f80ed768John Reckvoid RenderProxy::setStopped(bool stopped) { 1778afcc76920499d0a384dba1470c5a377f80ed768John Reck SETUP_TASK(setStopped); 1788afcc76920499d0a384dba1470c5a377f80ed768John Reck args->context = mContext; 1798afcc76920499d0a384dba1470c5a377f80ed768John Reck args->stopped = stopped; 1808afcc76920499d0a384dba1470c5a377f80ed768John Reck postAndWait(task); 1818afcc76920499d0a384dba1470c5a377f80ed768John Reck} 1828afcc76920499d0a384dba1470c5a377f80ed768John Reck 18350210d912925aef14e4ce69be82e4949122a3cd9Alan ViveretteCREATE_BRIDGE6(setup, CanvasContext* context, int width, int height, 18450210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { 18550210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette args->context->setup(args->width, args->height, args->lightRadius, 186058fc640017c90120c599d378a4cbc55668b05b7Chris Craik args->ambientShadowAlpha, args->spotShadowAlpha); 187d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 1884f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 1894f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 19050210d912925aef14e4ce69be82e4949122a3cd9Alan Viverettevoid RenderProxy::setup(int width, int height, float lightRadius, 191b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { 1924f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck SETUP_TASK(setup); 1934f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck args->context = mContext; 1944f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck args->width = width; 1954f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck args->height = height; 196797b95b26bbb7557678af78b9a2a61830158920fChris Craik args->lightRadius = lightRadius; 197058fc640017c90120c599d378a4cbc55668b05b7Chris Craik args->ambientShadowAlpha = ambientShadowAlpha; 198058fc640017c90120c599d378a4cbc55668b05b7Chris Craik args->spotShadowAlpha = spotShadowAlpha; 1994f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck post(task); 2004f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 2014f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 20250210d912925aef14e4ce69be82e4949122a3cd9Alan ViveretteCREATE_BRIDGE2(setLightCenter, CanvasContext* context, Vector3 lightCenter) { 20350210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette args->context->setLightCenter(args->lightCenter); 20450210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette return nullptr; 20550210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette} 20650210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette 20750210d912925aef14e4ce69be82e4949122a3cd9Alan Viverettevoid RenderProxy::setLightCenter(const Vector3& lightCenter) { 20850210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette SETUP_TASK(setLightCenter); 20950210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette args->context = mContext; 21050210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette args->lightCenter = lightCenter; 21150210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette post(task); 21250210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette} 21350210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette 21463a06673253914510bbeebd500655008682dade1John ReckCREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) { 21563a06673253914510bbeebd500655008682dade1John Reck args->context->setOpaque(args->opaque); 216d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 21763a06673253914510bbeebd500655008682dade1John Reck} 21863a06673253914510bbeebd500655008682dade1John Reck 21963a06673253914510bbeebd500655008682dade1John Reckvoid RenderProxy::setOpaque(bool opaque) { 22063a06673253914510bbeebd500655008682dade1John Reck SETUP_TASK(setOpaque); 22163a06673253914510bbeebd500655008682dade1John Reck args->context = mContext; 22263a06673253914510bbeebd500655008682dade1John Reck args->opaque = opaque; 22363a06673253914510bbeebd500655008682dade1John Reck post(task); 22463a06673253914510bbeebd500655008682dade1John Reck} 22563a06673253914510bbeebd500655008682dade1John Reck 226ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckint64_t* RenderProxy::frameInfo() { 227ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck return mDrawFrameTask.frameInfo(); 228ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck} 229ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck 23051f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reckint RenderProxy::syncAndDrawFrame(TreeObserver* observer) { 23151f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck return mDrawFrameTask.drawFrame(observer); 2324f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 2334f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 23451f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn ReckCREATE_BRIDGE2(destroy, CanvasContext* context, TreeObserver* observer) { 23551f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck args->context->destroy(args->observer); 236d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 2374f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 2384f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 23951f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reckvoid RenderProxy::destroy(TreeObserver* observer) { 24017035b0211a3c9d45ea46a99217a6acbe76e8fbeJohn Reck SETUP_TASK(destroy); 2414f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck args->context = mContext; 24251f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck args->observer = observer; 243fae904d63947fe1687d1d44be29234cc3d538f24John Reck // destroyCanvasAndSurface() needs a fence as when it returns the 244fae904d63947fe1687d1d44be29234cc3d538f24John Reck // underlying BufferQueue is going to be released from under 245fae904d63947fe1687d1d44be29234cc3d538f24John Reck // the render thread. 246fae904d63947fe1687d1d44be29234cc3d538f24John Reck postAndWait(task); 2474f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 2484f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 2493b20251a355c88193c439f928a84ae69483fb488John ReckCREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) { 2503b20251a355c88193c439f928a84ae69483fb488John Reck CanvasContext::invokeFunctor(*args->thread, args->functor); 251d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 2520d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck} 2530d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck 2540d1f634f4b5e1bb37aa51777efb6a68619488d01John Reckvoid RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) { 255d3d8dafc2f61fb118c060720b52684c59303f3dbJohn Reck ATRACE_CALL(); 2563b20251a355c88193c439f928a84ae69483fb488John Reck RenderThread& thread = RenderThread::getInstance(); 2570d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck SETUP_TASK(invokeFunctor); 2583b20251a355c88193c439f928a84ae69483fb488John Reck args->thread = &thread; 2590d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck args->functor = functor; 2600d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck if (waitForCompletion) { 2613b20251a355c88193c439f928a84ae69483fb488John Reck // waitForCompletion = true is expected to be fairly rare and only 2623b20251a355c88193c439f928a84ae69483fb488John Reck // happen in destruction. Thus it should be fine to temporarily 2633b20251a355c88193c439f928a84ae69483fb488John Reck // create a Mutex 2640e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck staticPostAndWait(task); 2650d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck } else { 2663b20251a355c88193c439f928a84ae69483fb488John Reck thread.queue(task); 2670d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck } 2680d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck} 2690d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck 270fc53ef27793a39e9effd829e9cae02a9ca14147eJohn ReckCREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) { 271fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck args->context->runWithGlContext(args->task); 272d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 273fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck} 274fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck 275fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reckvoid RenderProxy::runWithGlContext(RenderTask* gltask) { 276fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck SETUP_TASK(runWithGlContext); 277fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck args->context = mContext; 278fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck args->task = gltask; 279fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck postAndWait(task); 280fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck} 281fc53ef27793a39e9effd829e9cae02a9ca14147eJohn Reck 282c36df952292b69920d4764a8a37361073fcf4f2cJohn ReckCREATE_BRIDGE1(createTextureLayer, CanvasContext* context) { 2831949e7928eeec22cd3f74b5f763a4eb433238453John Reck Layer* layer = args->context->createTextureLayer(); 284d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik if (!layer) return nullptr; 285c36df952292b69920d4764a8a37361073fcf4f2cJohn Reck return new DeferredLayerUpdater(layer); 28619b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck} 28719b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck 28819b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John ReckDeferredLayerUpdater* RenderProxy::createTextureLayer() { 28919b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck SETUP_TASK(createTextureLayer); 2901949e7928eeec22cd3f74b5f763a4eb433238453John Reck args->context = mContext; 29119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck void* retval = postAndWait(task); 29219b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); 29319b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck return layer; 29419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck} 29519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck 29651f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn ReckCREATE_BRIDGE3(buildLayer, CanvasContext* context, RenderNode* node, TreeObserver* observer) { 29751f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck args->context->buildLayer(args->node, args->observer); 298d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 2993e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck} 3003e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck 30151f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reckvoid RenderProxy::buildLayer(RenderNode* node, TreeObserver* observer) { 3023e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck SETUP_TASK(buildLayer); 3033e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck args->context = mContext; 3043e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck args->node = node; 30551f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck args->observer = observer; 3063e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck postAndWait(task); 3073e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck} 3083e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck 30919b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John ReckCREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer, 31019b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck SkBitmap* bitmap) { 31119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck bool success = args->context->copyLayerInto(args->layer, args->bitmap); 31219b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck return (void*) success; 31319b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck} 31419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck 3153731dc220ed457e0f1e99d7ec2589e0a43872b59John Reckbool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) { 31619b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck SETUP_TASK(copyLayerInto); 31719b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck args->context = mContext; 31819b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck args->layer = layer; 3193731dc220ed457e0f1e99d7ec2589e0a43872b59John Reck args->bitmap = &bitmap; 32019b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck return (bool) postAndWait(task); 32119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck} 32219b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck 323d72e0a339b54af0c4e731513bbad120dff694723John Reckvoid RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) { 324d72e0a339b54af0c4e731513bbad120dff694723John Reck mDrawFrameTask.pushLayerUpdate(layer); 325d72e0a339b54af0c4e731513bbad120dff694723John Reck} 326d72e0a339b54af0c4e731513bbad120dff694723John Reck 327d72e0a339b54af0c4e731513bbad120dff694723John Reckvoid RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) { 328d72e0a339b54af0c4e731513bbad120dff694723John Reck mDrawFrameTask.removeLayerUpdate(layer); 329918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck} 330918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck 331918ad523b2780e0c893f3d2a32d4ec13f2a7e921John ReckCREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) { 332918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck args->layer->detachSurfaceTexture(); 333d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 334918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck} 335918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck 336918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reckvoid RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) { 337918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck SETUP_TASK(detachSurfaceTexture); 338918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck args->layer = layer; 339918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck postAndWait(task); 34019b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck} 34119b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck 34251f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn ReckCREATE_BRIDGE2(destroyHardwareResources, CanvasContext* context, TreeObserver* observer) { 34351f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck args->context->destroyHardwareResources(args->observer); 344d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 345e1628b7c6fc3822fa83cf02028ce8ad67abb0afeJohn Reck} 346e1628b7c6fc3822fa83cf02028ce8ad67abb0afeJohn Reck 34751f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reckvoid RenderProxy::destroyHardwareResources(TreeObserver* observer) { 348f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck SETUP_TASK(destroyHardwareResources); 349e1628b7c6fc3822fa83cf02028ce8ad67abb0afeJohn Reck args->context = mContext; 35051f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck args->observer = observer; 35151f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck postAndWait(task); 352e1628b7c6fc3822fa83cf02028ce8ad67abb0afeJohn Reck} 353e1628b7c6fc3822fa83cf02028ce8ad67abb0afeJohn Reck 3542507c34d91bb0d722b6012e85cb47387b2aa6873Chris CraikCREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) { 355f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck CanvasContext::trimMemory(*args->thread, args->level); 356d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 357f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck} 358f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck 359f47a594f5250b1914c36423ee6b371f0b8db09d0John Reckvoid RenderProxy::trimMemory(int level) { 360cd3a22cfec09c065d0667dd044c0788912e82465John Reck // Avoid creating a RenderThread to do a trimMemory. 361cd3a22cfec09c065d0667dd044c0788912e82465John Reck if (RenderThread::hasInstance()) { 362cd3a22cfec09c065d0667dd044c0788912e82465John Reck RenderThread& thread = RenderThread::getInstance(); 3632507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik SETUP_TASK(trimMemory); 364cd3a22cfec09c065d0667dd044c0788912e82465John Reck args->thread = &thread; 365cd3a22cfec09c065d0667dd044c0788912e82465John Reck args->level = level; 366cd3a22cfec09c065d0667dd044c0788912e82465John Reck thread.queue(task); 367cd3a22cfec09c065d0667dd044c0788912e82465John Reck } 368f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck} 369f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck 3702507c34d91bb0d722b6012e85cb47387b2aa6873Chris CraikCREATE_BRIDGE2(overrideProperty, const char* name, const char* value) { 3712507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik Properties::overrideProperty(args->name, args->value); 3722507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik return nullptr; 3732507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik} 3742507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik 3752507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craikvoid RenderProxy::overrideProperty(const char* name, const char* value) { 3762507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik SETUP_TASK(overrideProperty); 3772507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik args->name = name; 3782507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik args->value = value; 3792507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller 3802507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik} 3812507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik 38228ad7b52e038ef0cdd89f753d9839444a434b299John ReckCREATE_BRIDGE0(fence) { 38328ad7b52e038ef0cdd89f753d9839444a434b299John Reck // Intentionally empty 384d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 38528ad7b52e038ef0cdd89f753d9839444a434b299John Reck} 38628ad7b52e038ef0cdd89f753d9839444a434b299John Reck 38764bb413a664001c95c8439cf097dc3033f4ed733Andreas Gampetemplate <typename T> 38864bb413a664001c95c8439cf097dc3033f4ed733Andreas Gampevoid UNUSED(T t) {} 38964bb413a664001c95c8439cf097dc3033f4ed733Andreas Gampe 39028ad7b52e038ef0cdd89f753d9839444a434b299John Reckvoid RenderProxy::fence() { 39128ad7b52e038ef0cdd89f753d9839444a434b299John Reck SETUP_TASK(fence); 3921e19674107e1aa2224c2b8c7d12bfa057efe80eaAndreas Gampe UNUSED(args); 39328ad7b52e038ef0cdd89f753d9839444a434b299John Reck postAndWait(task); 39428ad7b52e038ef0cdd89f753d9839444a434b299John Reck} 39528ad7b52e038ef0cdd89f753d9839444a434b299John Reck 396c0a0e1a66da20a18045d59451b59ec32685bcf18Thomas Buhotvoid RenderProxy::staticFence() { 397c0a0e1a66da20a18045d59451b59ec32685bcf18Thomas Buhot SETUP_TASK(fence); 398c0a0e1a66da20a18045d59451b59ec32685bcf18Thomas Buhot UNUSED(args); 399c0a0e1a66da20a18045d59451b59ec32685bcf18Thomas Buhot staticPostAndWait(task); 400c0a0e1a66da20a18045d59451b59ec32685bcf18Thomas Buhot} 401c0a0e1a66da20a18045d59451b59ec32685bcf18Thomas Buhot 402f47a594f5250b1914c36423ee6b371f0b8db09d0John ReckCREATE_BRIDGE1(stopDrawing, CanvasContext* context) { 403f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck args->context->stopDrawing(); 404d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 405f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck} 406f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck 407f47a594f5250b1914c36423ee6b371f0b8db09d0John Reckvoid RenderProxy::stopDrawing() { 408f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck SETUP_TASK(stopDrawing); 409f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck args->context = mContext; 410f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck postAndWait(task); 411f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck} 412f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck 413a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn ReckCREATE_BRIDGE1(notifyFramePending, CanvasContext* context) { 414a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck args->context->notifyFramePending(); 415d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 416a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck} 417a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck 418a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reckvoid RenderProxy::notifyFramePending() { 419a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck SETUP_TASK(notifyFramePending); 420a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck args->context = mContext; 421a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck mRenderThread.queueAtFront(task); 422a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck} 423a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck 4247f2e5e3cea6af1f1dff35842aa13d46c47315b91John ReckCREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread, 4257f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck int fd, int dumpFlags) { 426fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck args->context->profiler().dumpData(args->fd); 42753e51e4aa933f9603587e1780f446c18816bf9beChris Craik if (args->dumpFlags & DumpFlags::FrameStats) { 428ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck args->context->dumpFrames(args->fd); 429ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck } 43053e51e4aa933f9603587e1780f446c18816bf9beChris Craik if (args->dumpFlags & DumpFlags::Reset) { 431ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck args->context->resetFrameStats(); 432ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck } 433a41f2445156fe0bcfde6bd4d813dfc43796a526dJohn Reck if (args->dumpFlags & DumpFlags::JankStats) { 434a41f2445156fe0bcfde6bd4d813dfc43796a526dJohn Reck args->thread->jankTracker().dump(args->fd); 435a41f2445156fe0bcfde6bd4d813dfc43796a526dJohn Reck } 436d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 437fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck} 438fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck 439ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckvoid RenderProxy::dumpProfileInfo(int fd, int dumpFlags) { 440fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck SETUP_TASK(dumpProfileInfo); 441fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck args->context = mContext; 4427f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck args->thread = &mRenderThread; 443fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck args->fd = fd; 444ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck args->dumpFlags = dumpFlags; 445fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck postAndWait(task); 446fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck} 447fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck 4487f2e5e3cea6af1f1dff35842aa13d46c47315b91John ReckCREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) { 4497f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck args->context->resetFrameStats(); 4507f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck return nullptr; 4517f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck} 4527f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck 4537f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reckvoid RenderProxy::resetProfileInfo() { 4547f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck SETUP_TASK(resetProfileInfo); 4557f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck args->context = mContext; 4567f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck postAndWait(task); 4577f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck} 4587f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck 459ba6adf66d3c44c0aa2fd8a224862ff1901d64300John ReckCREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) { 460ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck args->thread->jankTracker().dump(args->fd); 461ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck 4622ae07339824efc50468f971ff8920ff0b894cad4Chris Craik FILE *file = fdopen(args->fd, "a"); 4632ae07339824efc50468f971ff8920ff0b894cad4Chris Craik if (Caches::hasInstance()) { 4642ae07339824efc50468f971ff8920ff0b894cad4Chris Craik String8 cachesLog; 4652ae07339824efc50468f971ff8920ff0b894cad4Chris Craik Caches::getInstance().dumpMemoryUsage(cachesLog); 4662ae07339824efc50468f971ff8920ff0b894cad4Chris Craik fprintf(file, "\nCaches:\n%s\n", cachesLog.string()); 4672ae07339824efc50468f971ff8920ff0b894cad4Chris Craik } else { 4682ae07339824efc50468f971ff8920ff0b894cad4Chris Craik fprintf(file, "\nNo caches instance.\n"); 4692ae07339824efc50468f971ff8920ff0b894cad4Chris Craik } 470ff3edce12d3081517e9a724cc18a0de58af5187aChris Craik#if HWUI_NEW_OPS 471ff3edce12d3081517e9a724cc18a0de58af5187aChris Craik fprintf(file, "\nPipeline=FrameBuilder\n"); 472ff3edce12d3081517e9a724cc18a0de58af5187aChris Craik#else 473ff3edce12d3081517e9a724cc18a0de58af5187aChris Craik fprintf(file, "\nPipeline=OpenGLRenderer\n"); 474ff3edce12d3081517e9a724cc18a0de58af5187aChris Craik#endif 4752ae07339824efc50468f971ff8920ff0b894cad4Chris Craik fflush(file); 476d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 4770e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck} 4780e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck 4792ae07339824efc50468f971ff8920ff0b894cad4Chris Craikvoid RenderProxy::dumpGraphicsMemory(int fd) { 480c80c9ad188ac6c421e70c906104d4394504878fbyoungmin if (!RenderThread::hasInstance()) return; 4812ae07339824efc50468f971ff8920ff0b894cad4Chris Craik SETUP_TASK(dumpGraphicsMemory); 4820e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck args->fd = fd; 483ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck args->thread = &RenderThread::getInstance(); 4840e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck staticPostAndWait(task); 4850e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck} 4860e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck 487ea7a7fb75acb7305eb774ca7bc7e96103bd49323SkuhneCREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map, 488ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne size_t size) { 4893b20251a355c88193c439f928a84ae69483fb488John Reck CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size); 490d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik args->buffer->decStrong(nullptr); 491d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik return nullptr; 4923b20251a355c88193c439f928a84ae69483fb488John Reck} 4933b20251a355c88193c439f928a84ae69483fb488John Reck 4943b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) { 4953b20251a355c88193c439f928a84ae69483fb488John Reck SETUP_TASK(setTextureAtlas); 4963b20251a355c88193c439f928a84ae69483fb488John Reck args->thread = &mRenderThread; 4973b20251a355c88193c439f928a84ae69483fb488John Reck args->buffer = buffer.get(); 498d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik args->buffer->incStrong(nullptr); 4993b20251a355c88193c439f928a84ae69483fb488John Reck args->map = map; 5003b20251a355c88193c439f928a84ae69483fb488John Reck args->size = size; 5013b20251a355c88193c439f928a84ae69483fb488John Reck post(task); 5023b20251a355c88193c439f928a84ae69483fb488John Reck} 5033b20251a355c88193c439f928a84ae69483fb488John Reck 504edc524c90506d80e0fc5fb67e8de7b8f3ef53439John ReckCREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) { 505edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck args->thread->jankTracker().switchStorageToAshmem(args->fd); 506edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck close(args->fd); 507edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck return nullptr; 508edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck} 509edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck 510edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reckvoid RenderProxy::setProcessStatsBuffer(int fd) { 511edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck SETUP_TASK(setProcessStatsBuffer); 512edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck args->thread = &mRenderThread; 513edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck args->fd = dup(fd); 514edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck post(task); 515edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck} 516edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck 517ea7a7fb75acb7305eb774ca7bc7e96103bd49323SkuhneCREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) { 518ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->context->addRenderNode(args->node, args->placeFront); 519ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne return nullptr; 520ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne} 521ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 522ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhnevoid RenderProxy::addRenderNode(RenderNode* node, bool placeFront) { 523ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne SETUP_TASK(addRenderNode); 524ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->context = mContext; 525ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->node = node; 526ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->placeFront = placeFront; 527ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne post(task); 528ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne} 529ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 530ea7a7fb75acb7305eb774ca7bc7e96103bd49323SkuhneCREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) { 531ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->context->removeRenderNode(args->node); 532ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne return nullptr; 533ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne} 534ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 535ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhnevoid RenderProxy::removeRenderNode(RenderNode* node) { 536ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne SETUP_TASK(removeRenderNode); 537ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->context = mContext; 538ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->node = node; 539ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne post(task); 540ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne} 541ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 542ea7a7fb75acb7305eb774ca7bc7e96103bd49323SkuhneCREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) { 543ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->context->prepareAndDraw(args->node); 544ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne return nullptr; 545ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne} 546ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 547ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhnevoid RenderProxy::drawRenderNode(RenderNode* node) { 548ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne SETUP_TASK(drawRenderNode); 549ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->context = mContext; 550ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->node = node; 551ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne // Be pseudo-thread-safe and don't use any member variables 552ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne staticPostAndWait(task); 553ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne} 554ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 555b816087962aba0019b022303330f03b897b580edSkuhneCREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top, 556ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne int right, int bottom) { 557b816087962aba0019b022303330f03b897b580edSkuhne args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom); 558ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne return nullptr; 559ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne} 560ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 561b816087962aba0019b022303330f03b897b580edSkuhnevoid RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) { 562b816087962aba0019b022303330f03b897b580edSkuhne SETUP_TASK(setContentDrawBounds); 563ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->context = mContext; 564ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->left = left; 565ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->top = top; 566ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->right = right; 567ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne args->bottom = bottom; 568ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne staticPostAndWait(task); 569ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne} 570ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 571e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn ReckCREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) { 572e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck args->context->serializeDisplayListTree(); 573e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck return nullptr; 574e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck} 575e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck 576e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reckvoid RenderProxy::serializeDisplayListTree() { 577e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck SETUP_TASK(serializeDisplayListTree); 578e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck args->context = mContext; 579e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck post(task); 580e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck} 581e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck 582910beb8f5d9042163e2ad0dbb744d9f147db9604Andres MoralesCREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context, 583910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales FrameMetricsObserver* frameStatsObserver) { 584910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales args->context->addFrameMetricsObserver(args->frameStatsObserver); 58506f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales if (args->frameStatsObserver != nullptr) { 58606f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales args->frameStatsObserver->decStrong(args->context); 58706f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales } 58806f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales return nullptr; 58906f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales} 59006f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales 591910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Moralesvoid RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) { 592910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales SETUP_TASK(addFrameMetricsObserver); 59306f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales args->context = mContext; 59406f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales args->frameStatsObserver = observer; 59506f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales if (observer != nullptr) { 59606f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales observer->incStrong(mContext); 59706f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales } 59806f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales post(task); 59906f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales} 60006f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales 601910beb8f5d9042163e2ad0dbb744d9f147db9604Andres MoralesCREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context, 602910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales FrameMetricsObserver* frameStatsObserver) { 603910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales args->context->removeFrameMetricsObserver(args->frameStatsObserver); 60406f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales if (args->frameStatsObserver != nullptr) { 60506f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales args->frameStatsObserver->decStrong(args->context); 60606f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales } 60706f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales return nullptr; 60806f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales} 60906f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales 610910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Moralesvoid RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) { 611910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales SETUP_TASK(removeFrameMetricsObserver); 61206f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales args->context = mContext; 61306f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales args->frameStatsObserver = observer; 61406f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales if (observer != nullptr) { 61506f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales observer->incStrong(mContext); 61606f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales } 61706f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales post(task); 61806f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales} 61906f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales 62010dd0585c11dcedb5a271d54e645594f1d215d5cJohn ReckCREATE_BRIDGE3(copySurfaceInto, RenderThread* thread, 62110dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck Surface* surface, SkBitmap* bitmap) { 62210dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck return (void*) Readback::copySurfaceInto(*args->thread, 62310dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck *args->surface, args->bitmap); 62410dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck} 62510dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck 626e94cbc76d560a157c0a0d47181b4ed2a0aadbeb1John Reckint RenderProxy::copySurfaceInto(sp<Surface>& surface, SkBitmap* bitmap) { 62710dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck SETUP_TASK(copySurfaceInto); 62810dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck args->bitmap = bitmap; 62910dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck args->surface = surface.get(); 63010dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck args->thread = &RenderThread::getInstance(); 631e94cbc76d560a157c0a0d47181b4ed2a0aadbeb1John Reck return static_cast<int>( 632e94cbc76d560a157c0a0d47181b4ed2a0aadbeb1John Reck reinterpret_cast<intptr_t>( staticPostAndWait(task) )); 63310dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck} 63410dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck 6354f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reckvoid RenderProxy::post(RenderTask* task) { 6364f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck mRenderThread.queue(task); 6374f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 6384f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 6394f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reckvoid* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { 6404f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck void* retval; 6414f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck task->setReturnPtr(&retval); 642cba287b9716155183faf21865a6c28ba49ffe486John Reck SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); 643cba287b9716155183faf21865a6c28ba49ffe486John Reck AutoMutex _lock(mSyncMutex); 644cba287b9716155183faf21865a6c28ba49ffe486John Reck mRenderThread.queue(&syncTask); 645cba287b9716155183faf21865a6c28ba49ffe486John Reck mSyncCondition.wait(mSyncMutex); 6464f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck return retval; 6474f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} 6484f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 6490e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reckvoid* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) { 6500e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck RenderThread& thread = RenderThread::getInstance(); 6510e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck void* retval; 6520e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck task->setReturnPtr(&retval); 6530a24b146cd3dacf372ce98424044423a5b2fbf2aChris Craik thread.queueAndWait(task); 6540e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck return retval; 6550e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck} 6560e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck 6574f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} /* namespace renderthread */ 6584f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} /* namespace uirenderer */ 6594f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck} /* namespace android */ 660