2014-01-03 18:08:34 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "CanvasContext.h"
|
|
|
|
|
2014-08-28 15:35:53 -07:00
|
|
|
#include <algorithm>
|
2014-01-03 18:09:17 -08:00
|
|
|
#include <private/hwui/DrawGlInfo.h>
|
2014-01-03 18:08:34 -08:00
|
|
|
#include <strings.h>
|
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
#include "EglManager.h"
|
2014-01-03 18:09:17 -08:00
|
|
|
#include "RenderThread.h"
|
2014-08-14 09:02:01 -07:00
|
|
|
#include "../AnimationContext.h"
|
2014-01-03 18:08:34 -08:00
|
|
|
#include "../Caches.h"
|
2014-02-14 20:03:38 -08:00
|
|
|
#include "../DeferredLayerUpdater.h"
|
2014-06-23 13:13:08 -07:00
|
|
|
#include "../RenderState.h"
|
2014-02-14 20:03:38 -08:00
|
|
|
#include "../LayerRenderer.h"
|
2014-01-03 18:09:17 -08:00
|
|
|
#include "../OpenGLRenderer.h"
|
2014-01-03 18:08:34 -08:00
|
|
|
#include "../Stencil.h"
|
|
|
|
|
2014-06-30 16:20:04 -07:00
|
|
|
#define TRIM_MEMORY_COMPLETE 80
|
|
|
|
#define TRIM_MEMORY_UI_HIDDEN 20
|
|
|
|
|
2014-01-03 18:08:34 -08:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
namespace renderthread {
|
|
|
|
|
2014-08-14 09:02:01 -07:00
|
|
|
CanvasContext::CanvasContext(RenderThread& thread, bool translucent,
|
|
|
|
RenderNode* rootRenderNode, IContextFactory* contextFactory)
|
2014-06-23 13:13:08 -07:00
|
|
|
: mRenderThread(thread)
|
|
|
|
, mEglManager(thread.eglManager())
|
2014-01-03 18:09:17 -08:00
|
|
|
, mEglSurface(EGL_NO_SURFACE)
|
2014-10-23 11:02:19 -07:00
|
|
|
, mBufferPreserved(false)
|
|
|
|
, mSwapBehavior(kSwap_default)
|
2014-01-03 18:09:17 -08:00
|
|
|
, mOpaque(!translucent)
|
2014-06-23 13:13:08 -07:00
|
|
|
, mCanvas(NULL)
|
2014-04-15 09:50:16 -07:00
|
|
|
, mHaveNewSurface(false)
|
|
|
|
, mRootRenderNode(rootRenderNode) {
|
2014-08-14 09:02:01 -07:00
|
|
|
mAnimationContext = contextFactory->createAnimationContext(mRenderThread.timeLord());
|
2014-09-04 17:40:05 -07:00
|
|
|
mRenderThread.renderState().registerCanvasContext(this);
|
2014-01-03 18:08:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
CanvasContext::~CanvasContext() {
|
2014-09-03 07:39:53 -07:00
|
|
|
destroy();
|
2014-08-14 09:02:01 -07:00
|
|
|
delete mAnimationContext;
|
2014-09-04 17:40:05 -07:00
|
|
|
mRenderThread.renderState().unregisterCanvasContext(this);
|
2014-01-03 18:09:17 -08:00
|
|
|
}
|
|
|
|
|
2014-09-03 07:39:53 -07:00
|
|
|
void CanvasContext::destroy() {
|
|
|
|
stopDrawing();
|
2014-11-21 18:05:41 +09:00
|
|
|
setSurface(NULL);
|
2014-09-03 07:39:53 -07:00
|
|
|
freePrefetechedLayers();
|
|
|
|
destroyHardwareResources();
|
2014-09-03 16:46:05 -07:00
|
|
|
mAnimationContext->destroy();
|
2014-01-03 18:09:17 -08:00
|
|
|
if (mCanvas) {
|
|
|
|
delete mCanvas;
|
|
|
|
mCanvas = 0;
|
|
|
|
}
|
2014-01-03 18:08:34 -08:00
|
|
|
}
|
|
|
|
|
2014-05-22 15:43:54 -07:00
|
|
|
void CanvasContext::setSurface(ANativeWindow* window) {
|
2014-11-14 16:18:41 -08:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2014-05-22 15:43:54 -07:00
|
|
|
mNativeWindow = window;
|
|
|
|
|
2014-01-03 18:08:34 -08:00
|
|
|
if (mEglSurface != EGL_NO_SURFACE) {
|
2014-06-23 13:13:08 -07:00
|
|
|
mEglManager.destroySurface(mEglSurface);
|
2014-01-03 18:08:34 -08:00
|
|
|
mEglSurface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window) {
|
2014-06-23 13:13:08 -07:00
|
|
|
mEglSurface = mEglManager.createSurface(window);
|
2014-01-03 18:08:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mEglSurface != EGL_NO_SURFACE) {
|
2014-10-23 11:02:19 -07:00
|
|
|
const bool preserveBuffer = (mSwapBehavior != kSwap_discardBuffer);
|
|
|
|
mBufferPreserved = mEglManager.setPreserveBuffer(mEglSurface, preserveBuffer);
|
2014-01-03 18:09:17 -08:00
|
|
|
mHaveNewSurface = true;
|
2014-04-17 20:25:13 -07:00
|
|
|
makeCurrent();
|
2014-05-07 13:11:00 -07:00
|
|
|
} else {
|
|
|
|
mRenderThread.removeFrameCallback(this);
|
2014-01-03 18:09:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasContext::swapBuffers() {
|
2014-09-17 16:06:36 -07:00
|
|
|
if (CC_UNLIKELY(!mEglManager.swapBuffers(mEglSurface))) {
|
|
|
|
setSurface(NULL);
|
|
|
|
}
|
2014-01-03 18:09:17 -08:00
|
|
|
mHaveNewSurface = false;
|
|
|
|
}
|
|
|
|
|
2014-04-09 10:01:03 -07:00
|
|
|
void CanvasContext::requireSurface() {
|
|
|
|
LOG_ALWAYS_FATAL_IF(mEglSurface == EGL_NO_SURFACE,
|
|
|
|
"requireSurface() called but no surface set!");
|
2014-04-17 20:25:13 -07:00
|
|
|
makeCurrent();
|
2014-01-03 18:09:17 -08:00
|
|
|
}
|
|
|
|
|
2014-10-23 11:02:19 -07:00
|
|
|
void CanvasContext::setSwapBehavior(SwapBehavior swapBehavior) {
|
|
|
|
mSwapBehavior = swapBehavior;
|
|
|
|
}
|
|
|
|
|
2014-05-22 15:43:54 -07:00
|
|
|
bool CanvasContext::initialize(ANativeWindow* window) {
|
2014-01-03 18:09:17 -08:00
|
|
|
setSurface(window);
|
2014-09-17 16:06:36 -07:00
|
|
|
if (mCanvas) return false;
|
2014-06-23 13:13:08 -07:00
|
|
|
mCanvas = new OpenGLRenderer(mRenderThread.renderState());
|
2014-01-03 18:09:17 -08:00
|
|
|
mCanvas->initProperties();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-22 15:43:54 -07:00
|
|
|
void CanvasContext::updateSurface(ANativeWindow* window) {
|
2014-01-03 18:09:17 -08:00
|
|
|
setSurface(window);
|
2014-04-09 10:01:03 -07:00
|
|
|
}
|
|
|
|
|
2014-12-03 13:01:07 -08:00
|
|
|
bool CanvasContext::pauseSurface(ANativeWindow* window) {
|
|
|
|
return mRenderThread.removeFrameCallback(this);
|
2014-01-03 18:09:17 -08:00
|
|
|
}
|
|
|
|
|
2014-09-18 16:05:35 -07:00
|
|
|
// TODO: don't pass viewport size, it's automatic via EGL
|
2014-07-23 18:19:28 -07:00
|
|
|
void CanvasContext::setup(int width, int height, const Vector3& lightCenter, float lightRadius,
|
|
|
|
uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
|
2014-01-03 18:09:17 -08:00
|
|
|
if (!mCanvas) return;
|
2014-07-23 18:19:28 -07:00
|
|
|
mCanvas->initLight(lightCenter, lightRadius, ambientShadowAlpha, spotShadowAlpha);
|
2014-01-03 18:09:17 -08:00
|
|
|
}
|
|
|
|
|
2014-05-07 13:45:54 -07:00
|
|
|
void CanvasContext::setOpaque(bool opaque) {
|
|
|
|
mOpaque = opaque;
|
|
|
|
}
|
|
|
|
|
2014-04-11 19:15:05 -07:00
|
|
|
void CanvasContext::makeCurrent() {
|
2014-04-17 20:25:13 -07:00
|
|
|
// TODO: Figure out why this workaround is needed, see b/13913604
|
|
|
|
// In the meantime this matches the behavior of GLRenderer, so it is not a regression
|
2014-06-23 13:13:08 -07:00
|
|
|
mHaveNewSurface |= mEglManager.makeCurrent(mEglSurface);
|
2014-04-11 19:15:05 -07:00
|
|
|
}
|
|
|
|
|
2014-06-24 15:34:58 -07:00
|
|
|
void CanvasContext::processLayerUpdate(DeferredLayerUpdater* layerUpdater) {
|
|
|
|
bool success = layerUpdater->apply();
|
2014-05-29 18:56:11 -07:00
|
|
|
LOG_ALWAYS_FATAL_IF(!success, "Failed to update layer!");
|
|
|
|
if (layerUpdater->backingLayer()->deferredUpdateScheduled) {
|
|
|
|
mCanvas->pushLayerUpdate(layerUpdater->backingLayer());
|
2014-02-14 20:03:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 09:50:16 -07:00
|
|
|
void CanvasContext::prepareTree(TreeInfo& info) {
|
2014-05-02 18:21:16 -07:00
|
|
|
mRenderThread.removeFrameCallback(this);
|
2014-05-02 16:46:41 -07:00
|
|
|
|
2014-06-03 15:53:15 -07:00
|
|
|
info.damageAccumulator = &mDamageAccumulator;
|
2014-06-12 13:46:45 -07:00
|
|
|
info.renderer = mCanvas;
|
2014-08-28 15:35:53 -07:00
|
|
|
if (mPrefetechedLayers.size() && info.mode == TreeInfo::MODE_FULL) {
|
|
|
|
info.canvasContext = this;
|
|
|
|
}
|
2014-09-05 15:23:38 -07:00
|
|
|
mAnimationContext->startFrame(info.mode);
|
2014-04-15 09:50:16 -07:00
|
|
|
mRootRenderNode->prepareTree(info);
|
2014-08-14 09:02:01 -07:00
|
|
|
mAnimationContext->runRemainingAnimations(info);
|
2014-04-15 09:50:16 -07:00
|
|
|
|
2014-08-28 15:35:53 -07:00
|
|
|
if (info.canvasContext) {
|
|
|
|
freePrefetechedLayers();
|
|
|
|
}
|
|
|
|
|
2014-11-07 11:02:07 -08:00
|
|
|
if (CC_UNLIKELY(!mNativeWindow.get())) {
|
|
|
|
info.out.canDrawThisFrame = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-22 15:43:54 -07:00
|
|
|
int runningBehind = 0;
|
|
|
|
// TODO: This query is moderately expensive, investigate adding some sort
|
|
|
|
// of fast-path based off when we last called eglSwapBuffers() as well as
|
|
|
|
// last vsync time. Or something.
|
|
|
|
mNativeWindow->query(mNativeWindow.get(),
|
|
|
|
NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND, &runningBehind);
|
|
|
|
info.out.canDrawThisFrame = !runningBehind;
|
|
|
|
|
|
|
|
if (info.out.hasAnimations || !info.out.canDrawThisFrame) {
|
2014-06-24 08:44:29 -07:00
|
|
|
if (!info.out.requiresUiRedraw) {
|
2014-05-02 18:21:16 -07:00
|
|
|
// If animationsNeedsRedraw is set don't bother posting for an RT anim
|
|
|
|
// as we will just end up fighting the UI thread.
|
|
|
|
mRenderThread.postFrameCallback(this);
|
|
|
|
}
|
2014-04-15 09:50:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-30 16:20:04 -07:00
|
|
|
void CanvasContext::stopDrawing() {
|
|
|
|
mRenderThread.removeFrameCallback(this);
|
|
|
|
}
|
|
|
|
|
2014-05-22 15:43:54 -07:00
|
|
|
void CanvasContext::notifyFramePending() {
|
|
|
|
ATRACE_CALL();
|
|
|
|
mRenderThread.pushBackFrameCallback(this);
|
|
|
|
}
|
|
|
|
|
2014-06-03 15:53:15 -07:00
|
|
|
void CanvasContext::draw() {
|
2014-01-03 18:09:17 -08:00
|
|
|
LOG_ALWAYS_FATAL_IF(!mCanvas || mEglSurface == EGL_NO_SURFACE,
|
2014-06-20 16:01:00 -07:00
|
|
|
"drawRenderNode called on a context with no canvas or surface!");
|
2014-01-03 18:09:17 -08:00
|
|
|
|
2014-05-23 17:42:28 -07:00
|
|
|
profiler().markPlaybackStart();
|
|
|
|
|
2014-06-03 15:53:15 -07:00
|
|
|
SkRect dirty;
|
|
|
|
mDamageAccumulator.finish(&dirty);
|
|
|
|
|
2014-01-03 18:09:17 -08:00
|
|
|
EGLint width, height;
|
2014-06-23 13:13:08 -07:00
|
|
|
mEglManager.beginFrame(mEglSurface, &width, &height);
|
2014-01-03 18:09:17 -08:00
|
|
|
if (width != mCanvas->getViewportWidth() || height != mCanvas->getViewportHeight()) {
|
|
|
|
mCanvas->setViewport(width, height);
|
2014-06-03 15:53:15 -07:00
|
|
|
dirty.setEmpty();
|
2014-10-23 11:02:19 -07:00
|
|
|
} else if (!mBufferPreserved || mHaveNewSurface) {
|
2014-06-03 15:53:15 -07:00
|
|
|
dirty.setEmpty();
|
2014-05-23 17:42:28 -07:00
|
|
|
} else {
|
2014-07-17 11:00:36 -07:00
|
|
|
if (!dirty.isEmpty() && !dirty.intersect(0, 0, width, height)) {
|
2014-07-16 13:29:45 -07:00
|
|
|
ALOGW("Dirty " RECT_STRING " doesn't intersect with 0 0 %d %d ?",
|
|
|
|
SK_RECT_ARGS(dirty), width, height);
|
|
|
|
dirty.setEmpty();
|
|
|
|
}
|
2014-06-03 15:53:15 -07:00
|
|
|
profiler().unionDirty(&dirty);
|
2014-01-03 18:09:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t status;
|
2014-06-03 15:53:15 -07:00
|
|
|
if (!dirty.isEmpty()) {
|
|
|
|
status = mCanvas->prepareDirty(dirty.fLeft, dirty.fTop,
|
|
|
|
dirty.fRight, dirty.fBottom, mOpaque);
|
2014-01-03 18:09:17 -08:00
|
|
|
} else {
|
|
|
|
status = mCanvas->prepare(mOpaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect outBounds;
|
2014-06-20 16:01:00 -07:00
|
|
|
status |= mCanvas->drawRenderNode(mRootRenderNode.get(), outBounds);
|
2014-01-03 18:09:17 -08:00
|
|
|
|
2014-05-23 17:42:28 -07:00
|
|
|
profiler().draw(mCanvas);
|
2014-01-03 18:09:17 -08:00
|
|
|
|
|
|
|
mCanvas->finish();
|
|
|
|
|
2014-05-23 17:42:28 -07:00
|
|
|
profiler().markPlaybackEnd();
|
|
|
|
|
2014-01-03 18:09:17 -08:00
|
|
|
if (status & DrawGlInfo::kStatusDrew) {
|
|
|
|
swapBuffers();
|
2014-10-31 14:49:06 -07:00
|
|
|
} else {
|
|
|
|
mEglManager.cancelFrame();
|
2014-01-03 18:08:34 -08:00
|
|
|
}
|
2014-05-23 17:42:28 -07:00
|
|
|
|
|
|
|
profiler().finishFrame();
|
2014-01-03 18:08:34 -08:00
|
|
|
}
|
|
|
|
|
2014-04-15 09:50:16 -07:00
|
|
|
// Called by choreographer to do an RT-driven animation
|
2014-05-02 16:46:41 -07:00
|
|
|
void CanvasContext::doFrame() {
|
2014-05-07 13:11:00 -07:00
|
|
|
if (CC_UNLIKELY(!mCanvas || mEglSurface == EGL_NO_SURFACE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-15 09:50:16 -07:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2014-05-23 17:42:28 -07:00
|
|
|
profiler().startFrame();
|
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
TreeInfo info(TreeInfo::MODE_RT_ONLY, mRenderThread.renderState());
|
2014-04-15 09:50:16 -07:00
|
|
|
prepareTree(info);
|
2014-05-22 15:43:54 -07:00
|
|
|
if (info.out.canDrawThisFrame) {
|
2014-06-03 15:53:15 -07:00
|
|
|
draw();
|
2014-05-22 15:43:54 -07:00
|
|
|
}
|
2014-04-15 09:50:16 -07:00
|
|
|
}
|
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
void CanvasContext::invokeFunctor(RenderThread& thread, Functor* functor) {
|
2014-04-10 15:00:13 -07:00
|
|
|
ATRACE_CALL();
|
2014-03-28 20:30:27 -07:00
|
|
|
DrawGlInfo::Mode mode = DrawGlInfo::kModeProcessNoContext;
|
2014-06-23 13:13:08 -07:00
|
|
|
if (thread.eglManager().hasEglContext()) {
|
|
|
|
thread.eglManager().requireGlContext();
|
2014-03-28 20:30:27 -07:00
|
|
|
mode = DrawGlInfo::kModeProcess;
|
|
|
|
}
|
2014-04-16 21:31:25 -07:00
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
thread.renderState().invokeFunctor(functor, mode, NULL);
|
2014-01-03 18:08:34 -08:00
|
|
|
}
|
|
|
|
|
2014-08-28 15:35:53 -07:00
|
|
|
void CanvasContext::markLayerInUse(RenderNode* node) {
|
|
|
|
if (mPrefetechedLayers.erase(node)) {
|
|
|
|
node->decStrong(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroyPrefetechedNode(RenderNode* node) {
|
|
|
|
ALOGW("Incorrectly called buildLayer on View: %s, destroying layer...", node->getName());
|
|
|
|
node->destroyHardwareResources();
|
|
|
|
node->decStrong(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasContext::freePrefetechedLayers() {
|
|
|
|
if (mPrefetechedLayers.size()) {
|
|
|
|
requireGlContext();
|
|
|
|
std::for_each(mPrefetechedLayers.begin(), mPrefetechedLayers.end(), destroyPrefetechedNode);
|
|
|
|
mPrefetechedLayers.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-20 10:08:39 -07:00
|
|
|
void CanvasContext::buildLayer(RenderNode* node) {
|
|
|
|
ATRACE_CALL();
|
|
|
|
if (!mEglManager.hasEglContext() || !mCanvas) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
requireGlContext();
|
|
|
|
// buildLayer() will leave the tree in an unknown state, so we must stop drawing
|
|
|
|
stopDrawing();
|
|
|
|
|
|
|
|
TreeInfo info(TreeInfo::MODE_FULL, mRenderThread.renderState());
|
|
|
|
info.damageAccumulator = &mDamageAccumulator;
|
|
|
|
info.renderer = mCanvas;
|
2014-08-21 11:23:05 -07:00
|
|
|
info.runAnimations = false;
|
2014-08-20 10:08:39 -07:00
|
|
|
node->prepareTree(info);
|
|
|
|
SkRect ignore;
|
|
|
|
mDamageAccumulator.finish(&ignore);
|
|
|
|
// Tickle the GENERIC property on node to mark it as dirty for damaging
|
|
|
|
// purposes when the frame is actually drawn
|
|
|
|
node->setPropertyFieldsDirty(RenderNode::GENERIC);
|
|
|
|
|
2014-09-04 17:40:05 -07:00
|
|
|
mCanvas->markLayersAsBuildLayers();
|
2014-08-20 10:08:39 -07:00
|
|
|
mCanvas->flushLayerUpdates();
|
2014-08-28 15:35:53 -07:00
|
|
|
|
|
|
|
node->incStrong(0);
|
|
|
|
mPrefetechedLayers.insert(node);
|
2014-08-20 10:08:39 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 20:03:38 -08:00
|
|
|
bool CanvasContext::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) {
|
|
|
|
requireGlContext();
|
2014-06-24 15:34:58 -07:00
|
|
|
layer->apply();
|
2014-06-23 13:13:08 -07:00
|
|
|
return LayerRenderer::copyLayer(mRenderThread.renderState(), layer->backingLayer(), bitmap);
|
2014-02-14 20:03:38 -08:00
|
|
|
}
|
|
|
|
|
2014-06-30 16:20:04 -07:00
|
|
|
void CanvasContext::destroyHardwareResources() {
|
|
|
|
stopDrawing();
|
2014-06-23 13:13:08 -07:00
|
|
|
if (mEglManager.hasEglContext()) {
|
2014-05-23 15:11:19 -07:00
|
|
|
requireGlContext();
|
2014-08-29 09:59:43 -07:00
|
|
|
freePrefetechedLayers();
|
2014-07-08 13:59:49 -07:00
|
|
|
mRootRenderNode->destroyHardwareResources();
|
2014-06-30 16:20:04 -07:00
|
|
|
Caches::getInstance().flush(Caches::kFlushMode_Layers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasContext::trimMemory(RenderThread& thread, int level) {
|
|
|
|
// No context means nothing to free
|
|
|
|
if (!thread.eglManager().hasEglContext()) return;
|
|
|
|
|
2014-09-25 02:41:29 +02:00
|
|
|
ATRACE_CALL();
|
2014-07-07 09:16:54 -07:00
|
|
|
thread.eglManager().requireGlContext();
|
2014-06-30 16:20:04 -07:00
|
|
|
if (level >= TRIM_MEMORY_COMPLETE) {
|
|
|
|
Caches::getInstance().flush(Caches::kFlushMode_Full);
|
|
|
|
thread.eglManager().destroy();
|
|
|
|
} else if (level >= TRIM_MEMORY_UI_HIDDEN) {
|
|
|
|
Caches::getInstance().flush(Caches::kFlushMode_Moderate);
|
2014-05-23 15:11:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-11 10:40:25 -08:00
|
|
|
void CanvasContext::runWithGlContext(RenderTask* task) {
|
2014-02-14 20:03:38 -08:00
|
|
|
requireGlContext();
|
|
|
|
task->run();
|
|
|
|
}
|
|
|
|
|
2014-04-08 15:18:56 -07:00
|
|
|
Layer* CanvasContext::createTextureLayer() {
|
2014-04-09 10:01:03 -07:00
|
|
|
requireSurface();
|
2014-06-23 13:13:08 -07:00
|
|
|
return LayerRenderer::createTextureLayer(mRenderThread.renderState());
|
2014-04-08 15:18:56 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 20:03:38 -08:00
|
|
|
void CanvasContext::requireGlContext() {
|
2014-06-30 16:20:04 -07:00
|
|
|
mEglManager.requireGlContext();
|
2014-02-11 10:40:25 -08:00
|
|
|
}
|
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
void CanvasContext::setTextureAtlas(RenderThread& thread,
|
|
|
|
const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize) {
|
|
|
|
thread.eglManager().setTextureAtlas(buffer, map, mapSize);
|
2014-05-13 13:39:31 -07:00
|
|
|
}
|
|
|
|
|
2014-01-03 18:08:34 -08:00
|
|
|
} /* namespace renderthread */
|
|
|
|
} /* namespace uirenderer */
|
|
|
|
} /* namespace android */
|