2010-06-16 18:44:05 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 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.
|
|
|
|
*/
|
|
|
|
|
2010-06-22 13:11:24 -07:00
|
|
|
#define LOG_TAG "OpenGLRenderer"
|
2010-06-16 18:44:05 -07:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2010-06-26 00:13:53 -07:00
|
|
|
#include <SkCanvas.h>
|
2012-02-24 17:54:07 -08:00
|
|
|
#include <SkPathMeasure.h>
|
2010-07-21 21:33:20 -07:00
|
|
|
#include <SkTypeface.h>
|
2010-06-27 22:59:20 -07:00
|
|
|
|
|
|
|
#include <utils/Log.h>
|
2010-09-24 18:39:22 -07:00
|
|
|
#include <utils/StopWatch.h>
|
2010-06-22 13:11:24 -07:00
|
|
|
|
2011-03-17 11:06:57 -07:00
|
|
|
#include <private/hwui/DrawGlInfo.h>
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#include <ui/Rect.h>
|
|
|
|
|
2010-06-22 13:11:24 -07:00
|
|
|
#include "OpenGLRenderer.h"
|
2010-11-08 12:08:41 -08:00
|
|
|
#include "DisplayListRenderer.h"
|
2010-12-08 18:34:42 -08:00
|
|
|
#include "Vector.h"
|
2010-06-16 18:44:05 -07:00
|
|
|
|
|
|
|
namespace android {
|
2010-06-24 19:30:36 -07:00
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Defines
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-09-16 20:49:46 -07:00
|
|
|
#define RAD_TO_DEG (180.0f / 3.14159265f)
|
|
|
|
#define MIN_ANGLE 0.001f
|
|
|
|
|
2010-10-11 17:58:29 -07:00
|
|
|
// TODO: This should be set in properties
|
|
|
|
#define ALPHA_THRESHOLD (0x7f / PANEL_BIT_DEPTH)
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
#define FILTER(paint) (paint && paint->isFilterBitmap() ? GL_LINEAR : GL_NEAREST)
|
|
|
|
|
2010-06-24 19:30:36 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Globals
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-07-29 14:37:42 -07:00
|
|
|
/**
|
|
|
|
* Structure mapping Skia xfermodes to OpenGL blending factors.
|
|
|
|
*/
|
|
|
|
struct Blender {
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
GLenum src;
|
|
|
|
GLenum dst;
|
|
|
|
}; // struct Blender
|
|
|
|
|
2010-06-28 17:12:22 -07:00
|
|
|
// In this array, the index of each Blender equals the value of the first
|
|
|
|
// entry. For instance, gBlends[1] == gBlends[SkXfermode::kSrc_Mode]
|
|
|
|
static const Blender gBlends[] = {
|
2011-09-08 15:33:03 -07:00
|
|
|
{ SkXfermode::kClear_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kSrc_Mode, GL_ONE, GL_ZERO },
|
|
|
|
{ SkXfermode::kDst_Mode, GL_ZERO, GL_ONE },
|
|
|
|
{ SkXfermode::kSrcOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kDstOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE },
|
|
|
|
{ SkXfermode::kSrcIn_Mode, GL_DST_ALPHA, GL_ZERO },
|
|
|
|
{ SkXfermode::kDstIn_Mode, GL_ZERO, GL_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kSrcOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO },
|
|
|
|
{ SkXfermode::kDstOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kSrcATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kDstATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kPlus_Mode, GL_ONE, GL_ONE },
|
|
|
|
{ SkXfermode::kMultiply_Mode, GL_ZERO, GL_SRC_COLOR },
|
|
|
|
{ SkXfermode::kScreen_Mode, GL_ONE, GL_ONE_MINUS_SRC_COLOR }
|
2010-06-28 17:12:22 -07:00
|
|
|
};
|
2010-06-16 18:44:05 -07:00
|
|
|
|
2010-09-13 18:11:21 -07:00
|
|
|
// This array contains the swapped version of each SkXfermode. For instance
|
|
|
|
// this array's SrcOver blending mode is actually DstOver. You can refer to
|
|
|
|
// createLayer() for more information on the purpose of this array.
|
2010-09-10 19:20:06 -07:00
|
|
|
static const Blender gBlendsSwap[] = {
|
2011-09-08 15:33:03 -07:00
|
|
|
{ SkXfermode::kClear_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO },
|
|
|
|
{ SkXfermode::kSrc_Mode, GL_ZERO, GL_ONE },
|
|
|
|
{ SkXfermode::kDst_Mode, GL_ONE, GL_ZERO },
|
|
|
|
{ SkXfermode::kSrcOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE },
|
|
|
|
{ SkXfermode::kDstOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kSrcIn_Mode, GL_ZERO, GL_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kDstIn_Mode, GL_DST_ALPHA, GL_ZERO },
|
|
|
|
{ SkXfermode::kSrcOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kDstOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO },
|
|
|
|
{ SkXfermode::kSrcATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kDstATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
|
|
|
|
{ SkXfermode::kPlus_Mode, GL_ONE, GL_ONE },
|
|
|
|
{ SkXfermode::kMultiply_Mode, GL_DST_COLOR, GL_ZERO },
|
|
|
|
{ SkXfermode::kScreen_Mode, GL_ONE_MINUS_DST_COLOR, GL_ONE }
|
2010-09-10 19:20:06 -07:00
|
|
|
};
|
|
|
|
|
2010-06-23 17:47:49 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constructors/destructor
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-08-23 21:05:08 -07:00
|
|
|
OpenGLRenderer::OpenGLRenderer(): mCaches(Caches::getInstance()) {
|
2010-07-30 19:18:16 -07:00
|
|
|
mShader = NULL;
|
2010-08-02 18:50:22 -07:00
|
|
|
mColorFilter = NULL;
|
2010-08-13 19:39:53 -07:00
|
|
|
mHasShadow = false;
|
2012-01-23 17:09:05 -08:00
|
|
|
mHasDrawFilter = false;
|
2010-06-28 17:12:22 -07:00
|
|
|
|
2010-07-27 17:39:27 -07:00
|
|
|
memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices));
|
|
|
|
|
2010-07-29 18:48:04 -07:00
|
|
|
mFirstSnapshot = new Snapshot;
|
2010-06-16 18:44:05 -07:00
|
|
|
}
|
|
|
|
|
2010-06-22 13:11:24 -07:00
|
|
|
OpenGLRenderer::~OpenGLRenderer() {
|
2010-09-22 16:10:57 -07:00
|
|
|
// The context has already been destroyed at this point, do not call
|
|
|
|
// GL APIs. All GL state should be kept in Caches.h
|
2010-06-16 18:44:05 -07:00
|
|
|
}
|
|
|
|
|
2012-01-30 17:41:55 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Debug
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OpenGLRenderer::startMark(const char* name) const {
|
|
|
|
mCaches.startMark(0, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::endMark() const {
|
|
|
|
mCaches.endMark();
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:47:49 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Setup
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-25 18:56:29 -08:00
|
|
|
uint32_t OpenGLRenderer::getStencilSize() {
|
|
|
|
return STENCIL_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2010-06-22 13:11:24 -07:00
|
|
|
void OpenGLRenderer::setViewport(int width, int height) {
|
2010-07-12 14:41:06 -07:00
|
|
|
mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
|
2010-06-22 18:56:38 -07:00
|
|
|
|
|
|
|
mWidth = width;
|
|
|
|
mHeight = height;
|
2010-10-05 18:14:38 -07:00
|
|
|
|
|
|
|
mFirstSnapshot->height = height;
|
|
|
|
mFirstSnapshot->viewport.set(0, 0, width, height);
|
2010-10-26 16:27:31 -07:00
|
|
|
|
2011-12-12 16:47:48 -08:00
|
|
|
glDisable(GL_DITHER);
|
2011-12-12 18:14:06 -08:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2011-12-12 16:47:48 -08:00
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
2011-12-13 13:11:32 -08:00
|
|
|
|
2011-12-12 16:47:48 -08:00
|
|
|
glEnableVertexAttribArray(Program::kBindingPosition);
|
2010-06-16 18:44:05 -07:00
|
|
|
}
|
|
|
|
|
2010-10-06 19:49:23 -07:00
|
|
|
void OpenGLRenderer::prepare(bool opaque) {
|
2011-01-24 16:33:45 -08:00
|
|
|
prepareDirty(0.0f, 0.0f, mWidth, mHeight, opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::prepareDirty(float left, float top, float right, float bottom, bool opaque) {
|
2010-11-11 15:36:56 -08:00
|
|
|
mCaches.clearGarbage();
|
|
|
|
|
2010-09-01 15:13:49 -07:00
|
|
|
mSnapshot = new Snapshot(mFirstSnapshot,
|
|
|
|
SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
|
2011-03-02 15:43:44 -08:00
|
|
|
mSnapshot->fbo = getTargetFbo();
|
2010-08-17 18:38:51 -07:00
|
|
|
mSaveCount = 1;
|
2010-06-23 17:47:49 -07:00
|
|
|
|
2011-12-12 18:14:06 -08:00
|
|
|
glViewport(0, 0, mWidth, mHeight);
|
2011-12-14 19:23:32 -08:00
|
|
|
mCaches.setScissor(left, mSnapshot->height - bottom, right - left, bottom - top);
|
2011-12-12 18:14:06 -08:00
|
|
|
|
2011-01-24 16:33:45 -08:00
|
|
|
mSnapshot->setClip(left, top, right, bottom);
|
2011-12-12 18:14:06 -08:00
|
|
|
mDirtyClip = false;
|
2011-01-24 16:33:45 -08:00
|
|
|
|
2010-10-06 19:49:23 -07:00
|
|
|
if (!opaque) {
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
2010-06-22 18:56:38 -07:00
|
|
|
}
|
|
|
|
|
2010-09-16 14:16:48 -07:00
|
|
|
void OpenGLRenderer::finish() {
|
|
|
|
#if DEBUG_OPENGL
|
|
|
|
GLenum status = GL_NO_ERROR;
|
|
|
|
while ((status = glGetError()) != GL_NO_ERROR) {
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("GL error from OpenGLRenderer: 0x%x", status);
|
2011-01-10 21:14:18 -08:00
|
|
|
switch (status) {
|
|
|
|
case GL_OUT_OF_MEMORY:
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE(" OpenGLRenderer is out of memory!");
|
2011-01-10 21:14:18 -08:00
|
|
|
break;
|
|
|
|
}
|
2010-09-16 14:16:48 -07:00
|
|
|
}
|
|
|
|
#endif
|
2010-11-10 11:59:15 -08:00
|
|
|
#if DEBUG_MEMORY_USAGE
|
|
|
|
mCaches.dumpMemoryUsage();
|
2010-11-10 19:01:29 -08:00
|
|
|
#else
|
|
|
|
if (mCaches.getDebugLevel() & kDebugMemory) {
|
|
|
|
mCaches.dumpMemoryUsage();
|
|
|
|
}
|
2010-11-10 11:59:15 -08:00
|
|
|
#endif
|
2010-09-16 14:16:48 -07:00
|
|
|
}
|
|
|
|
|
2011-01-11 14:29:25 -08:00
|
|
|
void OpenGLRenderer::interrupt() {
|
2010-08-31 11:50:35 -07:00
|
|
|
if (mCaches.currentProgram) {
|
|
|
|
if (mCaches.currentProgram->isInUse()) {
|
|
|
|
mCaches.currentProgram->remove();
|
|
|
|
mCaches.currentProgram = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-10-19 11:42:22 -07:00
|
|
|
mCaches.unbindMeshBuffer();
|
2011-12-13 13:11:32 -08:00
|
|
|
mCaches.unbindIndicesBuffer();
|
2011-12-12 20:35:21 -08:00
|
|
|
mCaches.resetVertexPointers();
|
2011-12-13 13:11:32 -08:00
|
|
|
mCaches.disbaleTexCoordsVertexArray();
|
2010-08-31 11:50:35 -07:00
|
|
|
}
|
|
|
|
|
2011-01-11 14:29:25 -08:00
|
|
|
void OpenGLRenderer::resume() {
|
2011-11-28 11:53:21 -08:00
|
|
|
sp<Snapshot> snapshot = (mSnapshot != NULL) ? mSnapshot : mFirstSnapshot;
|
|
|
|
|
|
|
|
glViewport(0, 0, snapshot->viewport.getWidth(), snapshot->viewport.getHeight());
|
2011-12-12 16:47:48 -08:00
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
|
2010-08-31 11:50:35 -07:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2012-01-03 14:13:39 -08:00
|
|
|
mCaches.resetScissor();
|
2010-10-26 16:27:31 -07:00
|
|
|
dirtyClip();
|
2010-08-31 11:50:35 -07:00
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2011-11-28 11:53:21 -08:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, snapshot->fbo);
|
2010-10-19 11:42:22 -07:00
|
|
|
|
|
|
|
mCaches.blend = true;
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(mCaches.lastSrcMode, mCaches.lastDstMode);
|
|
|
|
glBlendEquation(GL_FUNC_ADD);
|
2010-08-31 11:50:35 -07:00
|
|
|
}
|
|
|
|
|
2011-03-07 18:06:46 -08:00
|
|
|
bool OpenGLRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
|
2011-01-10 14:10:36 -08:00
|
|
|
interrupt();
|
2011-01-25 22:53:24 -08:00
|
|
|
if (mDirtyClip) {
|
|
|
|
setScissorFromClip();
|
|
|
|
}
|
2011-03-01 14:55:21 -08:00
|
|
|
|
2011-03-16 15:30:12 -07:00
|
|
|
Rect clip(*mSnapshot->clipRect);
|
|
|
|
clip.snapToPixelBoundaries();
|
|
|
|
|
2011-03-01 14:55:21 -08:00
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
// Since we don't know what the functor will draw, let's dirty
|
|
|
|
// tne entire clip region
|
|
|
|
if (hasLayer()) {
|
|
|
|
dirtyLayerUnchecked(clip, getRegion());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-17 11:06:57 -07:00
|
|
|
DrawGlInfo info;
|
|
|
|
info.clipLeft = clip.left;
|
|
|
|
info.clipTop = clip.top;
|
|
|
|
info.clipRight = clip.right;
|
|
|
|
info.clipBottom = clip.bottom;
|
|
|
|
info.isLayer = hasLayer();
|
|
|
|
getSnapshot()->transform->copyTo(&info.transform[0]);
|
2011-03-16 15:30:12 -07:00
|
|
|
|
2011-03-17 11:06:57 -07:00
|
|
|
status_t result = (*functor)(0, &info);
|
2011-03-07 18:06:46 -08:00
|
|
|
|
|
|
|
if (result != 0) {
|
2011-03-17 11:06:57 -07:00
|
|
|
Rect localDirty(info.dirtyLeft, info.dirtyTop, info.dirtyRight, info.dirtyBottom);
|
2011-03-07 18:06:46 -08:00
|
|
|
dirty.unionWith(localDirty);
|
|
|
|
}
|
|
|
|
|
2011-01-10 14:10:36 -08:00
|
|
|
resume();
|
2011-03-07 18:06:46 -08:00
|
|
|
return result != 0;
|
2011-01-10 14:10:36 -08:00
|
|
|
}
|
|
|
|
|
2010-06-23 17:47:49 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// State management
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-22 18:56:38 -07:00
|
|
|
int OpenGLRenderer::getSaveCount() const {
|
2010-06-25 13:46:18 -07:00
|
|
|
return mSaveCount;
|
2010-06-22 18:56:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int OpenGLRenderer::save(int flags) {
|
2010-09-01 15:13:49 -07:00
|
|
|
return saveSnapshot(flags);
|
2010-06-22 18:56:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::restore() {
|
2010-08-18 11:47:12 -07:00
|
|
|
if (mSaveCount > 1) {
|
|
|
|
restoreSnapshot();
|
2010-06-25 13:46:18 -07:00
|
|
|
}
|
2010-06-22 18:56:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::restoreToCount(int saveCount) {
|
2010-08-17 18:38:51 -07:00
|
|
|
if (saveCount < 1) saveCount = 1;
|
2010-06-22 18:56:38 -07:00
|
|
|
|
2010-08-17 18:38:51 -07:00
|
|
|
while (mSaveCount > saveCount) {
|
2010-08-18 11:47:12 -07:00
|
|
|
restoreSnapshot();
|
2010-06-25 13:46:18 -07:00
|
|
|
}
|
2010-06-22 18:56:38 -07:00
|
|
|
}
|
|
|
|
|
2010-09-01 15:13:49 -07:00
|
|
|
int OpenGLRenderer::saveSnapshot(int flags) {
|
|
|
|
mSnapshot = new Snapshot(mSnapshot, flags);
|
2010-08-17 18:38:51 -07:00
|
|
|
return mSaveCount++;
|
2010-06-22 18:56:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenGLRenderer::restoreSnapshot() {
|
2010-06-25 13:46:18 -07:00
|
|
|
bool restoreClip = mSnapshot->flags & Snapshot::kFlagClipSet;
|
2010-06-26 00:13:53 -07:00
|
|
|
bool restoreLayer = mSnapshot->flags & Snapshot::kFlagIsLayer;
|
2010-10-05 18:14:38 -07:00
|
|
|
bool restoreOrtho = mSnapshot->flags & Snapshot::kFlagDirtyOrtho;
|
2010-06-22 18:56:38 -07:00
|
|
|
|
2010-06-26 00:13:53 -07:00
|
|
|
sp<Snapshot> current = mSnapshot;
|
2010-06-25 13:46:18 -07:00
|
|
|
sp<Snapshot> previous = mSnapshot->previous;
|
2010-06-26 00:13:53 -07:00
|
|
|
|
2010-10-05 18:14:38 -07:00
|
|
|
if (restoreOrtho) {
|
|
|
|
Rect& r = previous->viewport;
|
|
|
|
glViewport(r.left, r.top, r.right, r.bottom);
|
|
|
|
mOrthoMatrix.load(current->orthoMatrix);
|
|
|
|
}
|
|
|
|
|
2010-08-18 17:10:07 -07:00
|
|
|
mSaveCount--;
|
|
|
|
mSnapshot = previous;
|
|
|
|
|
2010-08-18 11:47:12 -07:00
|
|
|
if (restoreClip) {
|
2010-10-26 16:27:31 -07:00
|
|
|
dirtyClip();
|
2010-08-17 18:38:51 -07:00
|
|
|
}
|
2010-08-18 11:47:12 -07:00
|
|
|
|
2010-11-03 16:19:08 -07:00
|
|
|
if (restoreLayer) {
|
|
|
|
composeLayer(current, previous);
|
|
|
|
}
|
|
|
|
|
2010-08-18 11:47:12 -07:00
|
|
|
return restoreClip;
|
2010-06-28 17:42:46 -07:00
|
|
|
}
|
2010-06-27 22:59:20 -07:00
|
|
|
|
2010-06-26 00:13:53 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Layers
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
|
2010-10-08 08:37:55 -07:00
|
|
|
SkPaint* p, int flags) {
|
2010-10-05 18:14:38 -07:00
|
|
|
const GLuint previousFbo = mSnapshot->fbo;
|
|
|
|
const int count = saveSnapshot(flags);
|
2010-06-28 17:42:46 -07:00
|
|
|
|
2010-12-09 17:47:21 -08:00
|
|
|
if (!mSnapshot->isIgnored()) {
|
2010-11-03 19:58:32 -07:00
|
|
|
int alpha = 255;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
alpha = p->getAlpha();
|
|
|
|
if (!mCaches.extensions.hasFramebufferFetch()) {
|
|
|
|
const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
|
|
|
|
if (!isMode) {
|
|
|
|
// Assume SRC_OVER
|
|
|
|
mode = SkXfermode::kSrcOver_Mode;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mode = getXfermode(p->getXfermode());
|
2010-09-09 14:42:43 -07:00
|
|
|
}
|
|
|
|
} else {
|
2010-11-03 19:58:32 -07:00
|
|
|
mode = SkXfermode::kSrcOver_Mode;
|
2010-06-28 17:42:46 -07:00
|
|
|
}
|
|
|
|
|
2010-10-11 17:58:29 -07:00
|
|
|
createLayer(mSnapshot, left, top, right, bottom, alpha, mode, flags, previousFbo);
|
|
|
|
}
|
2010-06-28 17:42:46 -07:00
|
|
|
|
|
|
|
return count;
|
2010-06-26 00:13:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
|
|
|
|
int alpha, int flags) {
|
2010-10-27 18:57:51 -07:00
|
|
|
if (alpha >= 255 - ALPHA_THRESHOLD) {
|
2010-09-01 15:13:49 -07:00
|
|
|
return saveLayer(left, top, right, bottom, NULL, flags);
|
2010-08-18 17:10:07 -07:00
|
|
|
} else {
|
2010-09-01 15:13:49 -07:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAlpha(alpha);
|
|
|
|
return saveLayer(left, top, right, bottom, &paint, flags);
|
2010-08-18 17:10:07 -07:00
|
|
|
}
|
2010-06-28 17:42:46 -07:00
|
|
|
}
|
2010-06-26 00:13:53 -07:00
|
|
|
|
2010-09-13 18:00:09 -07:00
|
|
|
/**
|
|
|
|
* Layers are viewed by Skia are slightly different than layers in image editing
|
|
|
|
* programs (for instance.) When a layer is created, previously created layers
|
|
|
|
* and the frame buffer still receive every drawing command. For instance, if a
|
|
|
|
* layer is created and a shape intersecting the bounds of the layers and the
|
|
|
|
* framebuffer is draw, the shape will be drawn on both (unless the layer was
|
|
|
|
* created with the SkCanvas::kClipToLayer_SaveFlag flag.)
|
|
|
|
*
|
|
|
|
* A way to implement layers is to create an FBO for each layer, backed by an RGBA
|
|
|
|
* texture. Unfortunately, this is inefficient as it requires every primitive to
|
|
|
|
* be drawn n + 1 times, where n is the number of active layers. In practice this
|
|
|
|
* means, for every primitive:
|
|
|
|
* - Switch active frame buffer
|
|
|
|
* - Change viewport, clip and projection matrix
|
|
|
|
* - Issue the drawing
|
|
|
|
*
|
|
|
|
* Switching rendering target n + 1 times per drawn primitive is extremely costly.
|
2010-10-06 19:49:23 -07:00
|
|
|
* To avoid this, layers are implemented in a different way here, at least in the
|
|
|
|
* general case. FBOs are used, as an optimization, when the "clip to layer" flag
|
|
|
|
* is set. When this flag is set we can redirect all drawing operations into a
|
|
|
|
* single FBO.
|
2010-09-13 18:00:09 -07:00
|
|
|
*
|
|
|
|
* This implementation relies on the frame buffer being at least RGBA 8888. When
|
|
|
|
* a layer is created, only a texture is created, not an FBO. The content of the
|
|
|
|
* frame buffer contained within the layer's bounds is copied into this texture
|
2010-09-13 18:11:21 -07:00
|
|
|
* using glCopyTexImage2D(). The layer's region is then cleared(1) in the frame
|
2010-09-13 18:00:09 -07:00
|
|
|
* buffer and drawing continues as normal. This technique therefore treats the
|
|
|
|
* frame buffer as a scratch buffer for the layers.
|
|
|
|
*
|
|
|
|
* To compose the layers back onto the frame buffer, each layer texture
|
|
|
|
* (containing the original frame buffer data) is drawn as a simple quad over
|
|
|
|
* the frame buffer. The trick is that the quad is set as the composition
|
|
|
|
* destination in the blending equation, and the frame buffer becomes the source
|
|
|
|
* of the composition.
|
|
|
|
*
|
|
|
|
* Drawing layers with an alpha value requires an extra step before composition.
|
|
|
|
* An empty quad is drawn over the layer's region in the frame buffer. This quad
|
|
|
|
* is drawn with the rgba color (0,0,0,alpha). The alpha value offered by the
|
|
|
|
* quad is used to multiply the colors in the frame buffer. This is achieved by
|
|
|
|
* changing the GL blend functions for the GL_FUNC_ADD blend equation to
|
|
|
|
* GL_ZERO, GL_SRC_ALPHA.
|
|
|
|
*
|
|
|
|
* Because glCopyTexImage2D() can be slow, an alternative implementation might
|
|
|
|
* be use to draw a single clipped layer. The implementation described above
|
|
|
|
* is correct in every case.
|
2010-09-13 18:11:21 -07:00
|
|
|
*
|
|
|
|
* (1) The frame buffer is actually not cleared right away. To allow the GPU
|
|
|
|
* to potentially optimize series of calls to glCopyTexImage2D, the frame
|
|
|
|
* buffer is left untouched until the first drawing operation. Only when
|
|
|
|
* something actually gets drawn are the layers regions cleared.
|
2010-09-13 18:00:09 -07:00
|
|
|
*/
|
2010-06-28 17:42:46 -07:00
|
|
|
bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
|
2010-10-05 18:14:38 -07:00
|
|
|
float right, float bottom, int alpha, SkXfermode::Mode mode,
|
|
|
|
int flags, GLuint previousFbo) {
|
|
|
|
LAYER_LOGD("Requesting layer %.2fx%.2f", right - left, bottom - top);
|
2010-08-23 21:05:08 -07:00
|
|
|
LAYER_LOGD("Layer cache size = %d", mCaches.layerCache.getSize());
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2010-10-05 18:14:38 -07:00
|
|
|
const bool fboLayer = flags & SkCanvas::kClipToLayer_SaveFlag;
|
|
|
|
|
2010-09-10 19:20:06 -07:00
|
|
|
// Window coordinates of the layer
|
2010-09-01 15:13:49 -07:00
|
|
|
Rect bounds(left, top, right, bottom);
|
2011-03-14 18:05:08 -07:00
|
|
|
if (!fboLayer) {
|
2010-10-05 18:14:38 -07:00
|
|
|
mSnapshot->transform->mapRect(bounds);
|
2010-10-22 10:40:27 -07:00
|
|
|
|
2010-10-05 18:14:38 -07:00
|
|
|
// Layers only make sense if they are in the framebuffer's bounds
|
2011-03-15 11:12:25 -07:00
|
|
|
if (bounds.intersect(*snapshot->clipRect)) {
|
|
|
|
// We cannot work with sub-pixels in this case
|
|
|
|
bounds.snapToPixelBoundaries();
|
|
|
|
|
|
|
|
// When the layer is not an FBO, we may use glCopyTexImage so we
|
|
|
|
// need to make sure the layer does not extend outside the bounds
|
|
|
|
// of the framebuffer
|
|
|
|
if (!bounds.intersect(snapshot->previous->viewport)) {
|
|
|
|
bounds.setEmpty();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bounds.setEmpty();
|
|
|
|
}
|
2010-10-05 18:14:38 -07:00
|
|
|
}
|
2010-09-16 14:40:17 -07:00
|
|
|
|
2010-10-26 16:27:31 -07:00
|
|
|
if (bounds.isEmpty() || bounds.getWidth() > mCaches.maxTextureSize ||
|
|
|
|
bounds.getHeight() > mCaches.maxTextureSize) {
|
2010-12-10 14:43:41 -08:00
|
|
|
snapshot->empty = fboLayer;
|
2010-10-11 17:58:29 -07:00
|
|
|
} else {
|
2010-11-03 19:58:32 -07:00
|
|
|
snapshot->invisible = snapshot->invisible || (alpha <= ALPHA_THRESHOLD && fboLayer);
|
2010-10-11 17:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bail out if we won't draw in this snapshot
|
2010-12-09 17:47:21 -08:00
|
|
|
if (snapshot->invisible || snapshot->empty) {
|
2010-09-16 14:16:48 -07:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2010-10-08 15:49:53 -07:00
|
|
|
Layer* layer = mCaches.layerCache.get(bounds.getWidth(), bounds.getHeight());
|
2010-07-08 11:45:51 -07:00
|
|
|
if (!layer) {
|
|
|
|
return false;
|
2010-06-26 00:13:53 -07:00
|
|
|
}
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->setAlpha(alpha, mode);
|
2010-09-01 15:13:49 -07:00
|
|
|
layer->layer.set(bounds);
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->texCoords.set(0.0f, bounds.getHeight() / float(layer->getHeight()),
|
|
|
|
bounds.getWidth() / float(layer->getWidth()), 0.0f);
|
|
|
|
layer->setColorFilter(mColorFilter);
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2010-08-17 18:38:51 -07:00
|
|
|
// Save the layer in the snapshot
|
|
|
|
snapshot->flags |= Snapshot::kFlagIsLayer;
|
2010-07-06 11:39:32 -07:00
|
|
|
snapshot->layer = layer;
|
2010-08-17 11:37:00 -07:00
|
|
|
|
2010-10-05 18:14:38 -07:00
|
|
|
if (fboLayer) {
|
2010-10-27 18:57:51 -07:00
|
|
|
return createFboLayer(layer, bounds, snapshot, previousFbo);
|
2010-10-05 18:14:38 -07:00
|
|
|
} else {
|
|
|
|
// Copy the framebuffer into the layer
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->bindTexture();
|
2011-01-19 14:38:29 -08:00
|
|
|
if (!bounds.isEmpty()) {
|
2011-07-07 20:50:11 -07:00
|
|
|
if (layer->isEmpty()) {
|
|
|
|
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
|
|
|
bounds.left, snapshot->height - bounds.bottom,
|
|
|
|
layer->getWidth(), layer->getHeight(), 0);
|
|
|
|
layer->setEmpty(false);
|
2011-01-19 14:38:29 -08:00
|
|
|
} else {
|
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bounds.left,
|
|
|
|
snapshot->height - bounds.bottom, bounds.getWidth(), bounds.getHeight());
|
|
|
|
}
|
2011-03-14 18:05:08 -07:00
|
|
|
|
2011-06-13 19:04:27 -07:00
|
|
|
// Enqueue the buffer coordinates to clear the corresponding region later
|
|
|
|
mLayers.push(new Rect(bounds));
|
2010-10-22 17:49:18 -07:00
|
|
|
}
|
2010-10-05 18:14:38 -07:00
|
|
|
}
|
2010-07-01 11:05:42 -07:00
|
|
|
|
2010-06-28 17:42:46 -07:00
|
|
|
return true;
|
2010-06-26 00:13:53 -07:00
|
|
|
}
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
|
|
|
|
GLuint previousFbo) {
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->setFbo(mCaches.fboCache.get());
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
snapshot->region = &snapshot->layer->region;
|
|
|
|
snapshot->flags |= Snapshot::kFlagFboTarget;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Rect clip(bounds);
|
|
|
|
snapshot->transform->mapRect(clip);
|
|
|
|
clip.intersect(*snapshot->clipRect);
|
|
|
|
clip.snapToPixelBoundaries();
|
|
|
|
clip.intersect(snapshot->previous->viewport);
|
|
|
|
|
|
|
|
mat4 inverse;
|
|
|
|
inverse.loadInverse(*mSnapshot->transform);
|
|
|
|
|
|
|
|
inverse.mapRect(clip);
|
|
|
|
clip.snapToPixelBoundaries();
|
|
|
|
clip.intersect(bounds);
|
2010-11-03 16:19:08 -07:00
|
|
|
clip.translate(-bounds.left, -bounds.top);
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
snapshot->flags |= Snapshot::kFlagIsFboLayer;
|
2011-07-07 20:50:11 -07:00
|
|
|
snapshot->fbo = layer->getFbo();
|
2010-10-27 18:57:51 -07:00
|
|
|
snapshot->resetTransform(-bounds.left, -bounds.top, 0.0f);
|
|
|
|
snapshot->resetClip(clip.left, clip.top, clip.right, clip.bottom);
|
|
|
|
snapshot->viewport.set(0.0f, 0.0f, bounds.getWidth(), bounds.getHeight());
|
|
|
|
snapshot->height = bounds.getHeight();
|
|
|
|
snapshot->flags |= Snapshot::kFlagDirtyOrtho;
|
|
|
|
snapshot->orthoMatrix.load(mOrthoMatrix);
|
|
|
|
|
|
|
|
// Bind texture to FBO
|
2011-07-07 20:50:11 -07:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, layer->getFbo());
|
|
|
|
layer->bindTexture();
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
// Initialize the texture if needed
|
2011-07-07 20:50:11 -07:00
|
|
|
if (layer->isEmpty()) {
|
|
|
|
layer->allocateTexture(GL_RGBA, GL_UNSIGNED_BYTE);
|
|
|
|
layer->setEmpty(false);
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->getTexture(), 0);
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
#if DEBUG_LAYERS_AS_REGIONS
|
|
|
|
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Framebuffer incomplete (GL error code 0x%x)", status);
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->deleteTexture();
|
|
|
|
mCaches.fboCache.put(layer->getFbo());
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
delete layer;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Clear the FBO, expand the clear region by 1 to get nice bilinear filtering
|
2011-12-14 19:23:32 -08:00
|
|
|
mCaches.setScissor(clip.left - 1.0f, bounds.getHeight() - clip.bottom - 1.0f,
|
2010-10-27 18:57:51 -07:00
|
|
|
clip.getWidth() + 2.0f, clip.getHeight() + 2.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
dirtyClip();
|
|
|
|
|
|
|
|
// Change the ortho projection
|
|
|
|
glViewport(0, 0, bounds.getWidth(), bounds.getHeight());
|
|
|
|
mOrthoMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-13 18:00:09 -07:00
|
|
|
/**
|
|
|
|
* Read the documentation of createLayer() before doing anything in this method.
|
|
|
|
*/
|
2010-08-17 11:37:00 -07:00
|
|
|
void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
|
|
|
|
if (!current->layer) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Attempting to compose a layer that does not exist");
|
2010-08-17 11:37:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
const bool fboLayer = current->flags & Snapshot::kFlagIsFboLayer;
|
2010-10-05 18:14:38 -07:00
|
|
|
|
|
|
|
if (fboLayer) {
|
|
|
|
// Unbind current FBO and restore previous one
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, previous->fbo);
|
|
|
|
}
|
|
|
|
|
2010-08-17 11:37:00 -07:00
|
|
|
Layer* layer = current->layer;
|
|
|
|
const Rect& rect = layer->layer;
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
if (!fboLayer && layer->getAlpha() < 255) {
|
2010-09-10 19:20:06 -07:00
|
|
|
drawColorRect(rect.left, rect.top, rect.right, rect.bottom,
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->getAlpha() << 24, SkXfermode::kDstIn_Mode, true);
|
2010-10-27 18:57:51 -07:00
|
|
|
// Required below, composeLayerRect() will divide by 255
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->setAlpha(255);
|
2010-09-10 19:20:06 -07:00
|
|
|
}
|
|
|
|
|
2010-10-18 14:06:08 -07:00
|
|
|
mCaches.unbindMeshBuffer();
|
2010-08-18 17:10:07 -07:00
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
// When the layer is stored in an FBO, we can save a bit of fillrate by
|
|
|
|
// drawing only the dirty region
|
2010-10-05 18:14:38 -07:00
|
|
|
if (fboLayer) {
|
2010-10-27 18:57:51 -07:00
|
|
|
dirtyLayer(rect.left, rect.top, rect.right, rect.bottom, *previous->transform);
|
2011-07-07 20:50:11 -07:00
|
|
|
if (layer->getColorFilter()) {
|
|
|
|
setupColorFilter(layer->getColorFilter());
|
2011-01-06 10:04:23 -08:00
|
|
|
}
|
2010-10-27 18:57:51 -07:00
|
|
|
composeLayerRegion(layer, rect);
|
2011-07-07 20:50:11 -07:00
|
|
|
if (layer->getColorFilter()) {
|
2011-01-06 10:04:23 -08:00
|
|
|
resetColorFilter();
|
|
|
|
}
|
2011-07-07 20:50:11 -07:00
|
|
|
} else if (!rect.isEmpty()) {
|
|
|
|
dirtyLayer(rect.left, rect.top, rect.right, rect.bottom);
|
|
|
|
composeLayerRect(layer, rect, true);
|
2010-10-05 18:14:38 -07:00
|
|
|
}
|
2010-08-17 11:37:00 -07:00
|
|
|
|
2010-10-05 18:14:38 -07:00
|
|
|
if (fboLayer) {
|
2011-11-10 19:23:58 -08:00
|
|
|
// Note: No need to use glDiscardFramebufferEXT() since we never
|
|
|
|
// create/compose layers that are not on screen with this
|
|
|
|
// code path
|
|
|
|
// See LayerRenderer::destroyLayer(Layer*)
|
|
|
|
|
2010-10-05 18:14:38 -07:00
|
|
|
// Detach the texture from the FBO
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, current->fbo);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, previous->fbo);
|
|
|
|
|
|
|
|
// Put the FBO name back in the cache, if it doesn't fit, it will be destroyed
|
|
|
|
mCaches.fboCache.put(current->fbo);
|
|
|
|
}
|
|
|
|
|
2010-10-26 16:27:31 -07:00
|
|
|
dirtyClip();
|
|
|
|
|
2010-10-05 18:14:38 -07:00
|
|
|
// Failing to add the layer to the cache should happen only if the layer is too large
|
2010-10-08 15:49:53 -07:00
|
|
|
if (!mCaches.layerCache.put(layer)) {
|
2010-08-17 11:37:00 -07:00
|
|
|
LAYER_LOGD("Deleting layer");
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->deleteTexture();
|
2010-08-17 11:37:00 -07:00
|
|
|
delete layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
void OpenGLRenderer::drawTextureLayer(Layer* layer, const Rect& rect) {
|
2011-07-07 20:50:11 -07:00
|
|
|
float alpha = layer->getAlpha() / 255.0f;
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
|
2011-08-16 13:55:02 -07:00
|
|
|
mat4& transform = layer->getTransform();
|
|
|
|
if (!transform.isIdentity()) {
|
|
|
|
save(0);
|
|
|
|
mSnapshot->transform->multiply(transform);
|
|
|
|
}
|
|
|
|
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
setupDraw();
|
2011-07-07 20:50:11 -07:00
|
|
|
if (layer->getRenderTarget() == GL_TEXTURE_2D) {
|
2011-05-02 17:24:22 -07:00
|
|
|
setupDrawWithTexture();
|
|
|
|
} else {
|
|
|
|
setupDrawWithExternalTexture();
|
|
|
|
}
|
|
|
|
setupDrawTextureTransform();
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
setupDrawColor(alpha, alpha, alpha, alpha);
|
|
|
|
setupDrawColorFilter();
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawBlending(layer->isBlend() || alpha < 1.0f, layer->getMode());
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawPureColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
2011-07-07 20:50:11 -07:00
|
|
|
if (layer->getRenderTarget() == GL_TEXTURE_2D) {
|
|
|
|
setupDrawTexture(layer->getTexture());
|
2011-05-02 17:24:22 -07:00
|
|
|
} else {
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawExternalTexture(layer->getTexture());
|
2011-05-02 17:24:22 -07:00
|
|
|
}
|
2011-07-07 21:05:04 -07:00
|
|
|
if (mSnapshot->transform->isPureTranslate() &&
|
|
|
|
layer->getWidth() == (uint32_t) rect.getWidth() &&
|
|
|
|
layer->getHeight() == (uint32_t) rect.getHeight()) {
|
2011-07-07 20:50:11 -07:00
|
|
|
const float x = (int) floorf(rect.left + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
const float y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
layer->setFilter(GL_NEAREST);
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawModelView(x, y, x + rect.getWidth(), y + rect.getHeight(), true);
|
|
|
|
} else {
|
2011-11-30 20:21:23 -08:00
|
|
|
layer->setFilter(GL_LINEAR);
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawModelView(rect.left, rect.top, rect.right, rect.bottom);
|
|
|
|
}
|
|
|
|
setupDrawTextureTransformUniforms(layer->getTexTransform());
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
setupDrawMesh(&mMeshVertices[0].position[0], &mMeshVertices[0].texture[0]);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
|
|
|
|
|
|
|
|
finishDrawTexture();
|
2011-08-16 13:55:02 -07:00
|
|
|
|
|
|
|
if (!transform.isIdentity()) {
|
|
|
|
restore();
|
|
|
|
}
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
}
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect, bool swap) {
|
2011-07-07 20:50:11 -07:00
|
|
|
if (!layer->isTextureLayer()) {
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
const Rect& texCoords = layer->texCoords;
|
|
|
|
resetDrawTextureTexCoords(texCoords.left, texCoords.top,
|
|
|
|
texCoords.right, texCoords.bottom);
|
2010-10-27 18:57:51 -07:00
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
float x = rect.left;
|
|
|
|
float y = rect.top;
|
2011-07-08 11:57:29 -07:00
|
|
|
bool simpleTransform = mSnapshot->transform->isPureTranslate() &&
|
2011-07-07 21:05:04 -07:00
|
|
|
layer->getWidth() == (uint32_t) rect.getWidth() &&
|
2011-07-08 11:57:29 -07:00
|
|
|
layer->getHeight() == (uint32_t) rect.getHeight();
|
|
|
|
|
|
|
|
if (simpleTransform) {
|
2011-07-07 20:50:11 -07:00
|
|
|
// When we're swapping, the layer is already in screen coordinates
|
|
|
|
if (!swap) {
|
|
|
|
x = (int) floorf(rect.left + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
layer->setFilter(GL_NEAREST, true);
|
2011-07-07 20:50:11 -07:00
|
|
|
} else {
|
2011-11-30 20:21:23 -08:00
|
|
|
layer->setFilter(GL_LINEAR, true);
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
drawTextureMesh(x, y, x + rect.getWidth(), y + rect.getHeight(),
|
|
|
|
layer->getTexture(), layer->getAlpha() / 255.0f,
|
|
|
|
layer->getMode(), layer->isBlend(),
|
|
|
|
&mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
|
|
|
|
GL_TRIANGLE_STRIP, gMeshCount, swap, swap || simpleTransform);
|
2010-10-27 18:57:51 -07:00
|
|
|
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
|
|
|
|
} else {
|
|
|
|
resetDrawTextureTexCoords(0.0f, 1.0f, 1.0f, 0.0f);
|
|
|
|
drawTextureLayer(layer, rect);
|
|
|
|
resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
|
|
|
|
}
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::composeLayerRegion(Layer* layer, const Rect& rect) {
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
if (layer->region.isRect()) {
|
2011-04-27 14:21:41 -07:00
|
|
|
layer->setRegionAsRect();
|
|
|
|
|
2011-03-18 14:34:03 -07:00
|
|
|
composeLayerRect(layer, layer->regionRect);
|
2011-04-27 14:21:41 -07:00
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
layer->region.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-07 17:55:15 -07:00
|
|
|
// TODO: See LayerRenderer.cpp::generateMesh() for important
|
|
|
|
// information about this implementation
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(!layer->region.isEmpty())) {
|
2010-10-27 18:57:51 -07:00
|
|
|
size_t count;
|
|
|
|
const android::Rect* rects = layer->region.getArray(&count);
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
const float alpha = layer->getAlpha() / 255.0f;
|
|
|
|
const float texX = 1.0f / float(layer->getWidth());
|
|
|
|
const float texY = 1.0f / float(layer->getHeight());
|
2011-01-16 12:54:25 -08:00
|
|
|
const float height = rect.getHeight();
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
TextureVertex* mesh = mCaches.getRegionMesh();
|
|
|
|
GLsizei numQuads = 0;
|
|
|
|
|
2011-01-10 22:26:16 -08:00
|
|
|
setupDraw();
|
|
|
|
setupDrawWithTexture();
|
|
|
|
setupDrawColor(alpha, alpha, alpha, alpha);
|
2011-01-13 12:13:20 -08:00
|
|
|
setupDrawColorFilter();
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawBlending(layer->isBlend() || alpha < 1.0f, layer->getMode(), false);
|
2011-01-10 22:26:16 -08:00
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawDirtyRegionsDisabled();
|
|
|
|
setupDrawPureColorUniforms();
|
2011-01-13 12:13:20 -08:00
|
|
|
setupDrawColorFilterUniforms();
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawTexture(layer->getTexture());
|
|
|
|
if (mSnapshot->transform->isPureTranslate()) {
|
|
|
|
const float x = (int) floorf(rect.left + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
const float y = (int) floorf(rect.top + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
layer->setFilter(GL_NEAREST);
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawModelViewTranslate(x, y, x + rect.getWidth(), y + rect.getHeight(), true);
|
|
|
|
} else {
|
2011-11-30 20:21:23 -08:00
|
|
|
layer->setFilter(GL_LINEAR);
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawModelViewTranslate(rect.left, rect.top, rect.right, rect.bottom);
|
|
|
|
}
|
2011-12-13 13:11:32 -08:00
|
|
|
setupDrawMeshIndices(&mesh[0].position[0], &mesh[0].texture[0]);
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
const android::Rect* r = &rects[i];
|
|
|
|
|
|
|
|
const float u1 = r->left * texX;
|
2011-01-16 12:54:25 -08:00
|
|
|
const float v1 = (height - r->top) * texY;
|
2010-10-27 18:57:51 -07:00
|
|
|
const float u2 = r->right * texX;
|
2011-01-16 12:54:25 -08:00
|
|
|
const float v2 = (height - r->bottom) * texY;
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
// TODO: Reject quads outside of the clip
|
|
|
|
TextureVertex::set(mesh++, r->left, r->top, u1, v1);
|
|
|
|
TextureVertex::set(mesh++, r->right, r->top, u2, v1);
|
|
|
|
TextureVertex::set(mesh++, r->left, r->bottom, u1, v2);
|
|
|
|
TextureVertex::set(mesh++, r->right, r->bottom, u2, v2);
|
|
|
|
|
|
|
|
numQuads++;
|
|
|
|
|
|
|
|
if (numQuads >= REGION_MESH_QUAD_COUNT) {
|
|
|
|
glDrawElements(GL_TRIANGLES, numQuads * 6, GL_UNSIGNED_SHORT, NULL);
|
|
|
|
numQuads = 0;
|
|
|
|
mesh = mCaches.getRegionMesh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numQuads > 0) {
|
|
|
|
glDrawElements(GL_TRIANGLES, numQuads * 6, GL_UNSIGNED_SHORT, NULL);
|
|
|
|
}
|
|
|
|
|
2011-01-10 22:26:16 -08:00
|
|
|
finishDrawTexture();
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
#if DEBUG_LAYERS_AS_REGIONS
|
2011-02-01 22:59:58 -08:00
|
|
|
drawRegionRects(layer->region);
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
layer->region.clear();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
composeLayerRect(layer, rect);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-02-01 22:59:58 -08:00
|
|
|
void OpenGLRenderer::drawRegionRects(const Region& region) {
|
|
|
|
#if DEBUG_LAYERS_AS_REGIONS
|
|
|
|
size_t count;
|
|
|
|
const android::Rect* rects = region.getArray(&count);
|
|
|
|
|
|
|
|
uint32_t colors[] = {
|
|
|
|
0x7fff0000, 0x7f00ff00,
|
|
|
|
0x7f0000ff, 0x7fff00ff,
|
|
|
|
};
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
int32_t top = rects[0].top;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
if (top != rects[i].top) {
|
|
|
|
offset ^= 0x2;
|
|
|
|
top = rects[i].top;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect r(rects[i].left, rects[i].top, rects[i].right, rects[i].bottom);
|
|
|
|
drawColorRect(r.left, r.top, r.right, r.bottom, colors[offset + (i & 0x1)],
|
|
|
|
SkXfermode::kSrcOver_Mode);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
void OpenGLRenderer::dirtyLayer(const float left, const float top,
|
|
|
|
const float right, const float bottom, const mat4 transform) {
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
2011-01-16 12:54:25 -08:00
|
|
|
if (hasLayer()) {
|
2010-10-27 18:57:51 -07:00
|
|
|
Rect bounds(left, top, right, bottom);
|
|
|
|
transform.mapRect(bounds);
|
2011-01-16 12:54:25 -08:00
|
|
|
dirtyLayerUnchecked(bounds, getRegion());
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::dirtyLayer(const float left, const float top,
|
|
|
|
const float right, const float bottom) {
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
2011-01-16 12:54:25 -08:00
|
|
|
if (hasLayer()) {
|
2010-10-27 18:57:51 -07:00
|
|
|
Rect bounds(left, top, right, bottom);
|
2011-01-16 12:54:25 -08:00
|
|
|
dirtyLayerUnchecked(bounds, getRegion());
|
2011-01-14 20:07:20 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::dirtyLayerUnchecked(Rect& bounds, Region* region) {
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
if (bounds.intersect(*mSnapshot->clipRect)) {
|
|
|
|
bounds.snapToPixelBoundaries();
|
|
|
|
android::Rect dirty(bounds.left, bounds.top, bounds.right, bounds.bottom);
|
|
|
|
if (!dirty.isEmpty()) {
|
|
|
|
region->orSelf(dirty);
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-06-13 19:04:27 -07:00
|
|
|
void OpenGLRenderer::clearLayerRegions() {
|
|
|
|
const size_t count = mLayers.size();
|
|
|
|
if (count == 0) return;
|
|
|
|
|
|
|
|
if (!mSnapshot->isIgnored()) {
|
|
|
|
// Doing several glScissor/glClear here can negatively impact
|
|
|
|
// GPUs with a tiler architecture, instead we draw quads with
|
|
|
|
// the Clear blending mode
|
|
|
|
|
|
|
|
// The list contains bounds that have already been clipped
|
|
|
|
// against their initial clip rect, and the current clip
|
|
|
|
// is likely different so we need to disable clipping here
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
Vertex mesh[count * 6];
|
|
|
|
Vertex* vertex = mesh;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
Rect* bounds = mLayers.itemAt(i);
|
|
|
|
|
|
|
|
Vertex::set(vertex++, bounds->left, bounds->bottom);
|
|
|
|
Vertex::set(vertex++, bounds->left, bounds->top);
|
|
|
|
Vertex::set(vertex++, bounds->right, bounds->top);
|
|
|
|
Vertex::set(vertex++, bounds->left, bounds->bottom);
|
|
|
|
Vertex::set(vertex++, bounds->right, bounds->top);
|
|
|
|
Vertex::set(vertex++, bounds->right, bounds->bottom);
|
|
|
|
|
|
|
|
delete bounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
setupDraw(false);
|
|
|
|
setupDrawColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
setupDrawBlending(true, SkXfermode::kClear_Mode);
|
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawPureColorUniforms();
|
|
|
|
setupDrawModelViewTranslate(0.0f, 0.0f, 0.0f, 0.0f, true);
|
2011-12-12 18:14:06 -08:00
|
|
|
setupDrawVertices(&mesh[0].position[0]);
|
2011-06-13 19:04:27 -07:00
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, count * 6);
|
|
|
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
} else {
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
delete mLayers.itemAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mLayers.clear();
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:47:49 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Transforms
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OpenGLRenderer::translate(float dx, float dy) {
|
2010-09-01 15:13:49 -07:00
|
|
|
mSnapshot->transform->translate(dx, dy, 0.0f);
|
2010-06-23 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::rotate(float degrees) {
|
2010-09-01 15:13:49 -07:00
|
|
|
mSnapshot->transform->rotate(degrees, 0.0f, 0.0f, 1.0f);
|
2010-06-23 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::scale(float sx, float sy) {
|
2010-09-01 15:13:49 -07:00
|
|
|
mSnapshot->transform->scale(sx, sy, 1.0f);
|
2010-06-23 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2011-01-18 11:19:19 -08:00
|
|
|
void OpenGLRenderer::skew(float sx, float sy) {
|
|
|
|
mSnapshot->transform->skew(sx, sy);
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:47:49 -07:00
|
|
|
void OpenGLRenderer::setMatrix(SkMatrix* matrix) {
|
2011-10-28 14:32:20 -07:00
|
|
|
if (matrix) {
|
|
|
|
mSnapshot->transform->load(*matrix);
|
|
|
|
} else {
|
|
|
|
mSnapshot->transform->loadIdentity();
|
|
|
|
}
|
2010-06-23 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::getMatrix(SkMatrix* matrix) {
|
2010-09-01 15:13:49 -07:00
|
|
|
mSnapshot->transform->copyTo(*matrix);
|
2010-06-23 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::concatMatrix(SkMatrix* matrix) {
|
2010-10-15 13:57:28 -07:00
|
|
|
SkMatrix transform;
|
|
|
|
mSnapshot->transform->copyTo(transform);
|
|
|
|
transform.preConcat(*matrix);
|
|
|
|
mSnapshot->transform->load(transform);
|
2010-06-23 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Clipping
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-22 18:56:38 -07:00
|
|
|
void OpenGLRenderer::setScissorFromClip() {
|
2010-10-15 13:57:28 -07:00
|
|
|
Rect clip(*mSnapshot->clipRect);
|
|
|
|
clip.snapToPixelBoundaries();
|
2011-12-14 19:23:32 -08:00
|
|
|
|
|
|
|
mCaches.setScissor(clip.left, mSnapshot->height - clip.bottom,
|
|
|
|
clip.getWidth(), clip.getHeight());
|
|
|
|
|
2010-10-26 16:27:31 -07:00
|
|
|
mDirtyClip = false;
|
2010-06-24 19:30:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const Rect& OpenGLRenderer::getClipBounds() {
|
2010-07-16 14:12:24 -07:00
|
|
|
return mSnapshot->getLocalClip();
|
2010-06-22 18:56:38 -07:00
|
|
|
}
|
|
|
|
|
2010-06-25 13:41:57 -07:00
|
|
|
bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
|
2010-12-09 17:47:21 -08:00
|
|
|
if (mSnapshot->isIgnored()) {
|
2010-10-11 17:58:29 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-17 11:37:00 -07:00
|
|
|
Rect r(left, top, right, bottom);
|
2010-09-01 15:13:49 -07:00
|
|
|
mSnapshot->transform->mapRect(r);
|
2010-10-14 14:46:44 -07:00
|
|
|
r.snapToPixelBoundaries();
|
|
|
|
|
|
|
|
Rect clipRect(*mSnapshot->clipRect);
|
|
|
|
clipRect.snapToPixelBoundaries();
|
|
|
|
|
|
|
|
return !clipRect.intersects(r);
|
2010-06-25 13:41:57 -07:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:12:24 -07:00
|
|
|
bool OpenGLRenderer::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
|
|
|
|
bool clipped = mSnapshot->clip(left, top, right, bottom, op);
|
2010-06-25 13:46:18 -07:00
|
|
|
if (clipped) {
|
2010-10-26 16:27:31 -07:00
|
|
|
dirtyClip();
|
2010-06-25 13:46:18 -07:00
|
|
|
}
|
2010-09-01 15:13:49 -07:00
|
|
|
return !mSnapshot->clipRect->isEmpty();
|
2010-06-16 18:44:05 -07:00
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Drawing commands
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-06-13 19:04:27 -07:00
|
|
|
void OpenGLRenderer::setupDraw(bool clear) {
|
|
|
|
if (clear) clearLayerRegions();
|
2010-12-13 18:24:33 -08:00
|
|
|
if (mDirtyClip) {
|
|
|
|
setScissorFromClip();
|
|
|
|
}
|
|
|
|
mDescription.reset();
|
|
|
|
mSetShaderColor = false;
|
|
|
|
mColorSet = false;
|
|
|
|
mColorA = mColorR = mColorG = mColorB = 0.0f;
|
|
|
|
mTextureUnit = 0;
|
|
|
|
mTrackDirtyRegions = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawWithTexture(bool isAlpha8) {
|
|
|
|
mDescription.hasTexture = true;
|
|
|
|
mDescription.hasAlpha8Texture = isAlpha8;
|
|
|
|
}
|
|
|
|
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
void OpenGLRenderer::setupDrawWithExternalTexture() {
|
|
|
|
mDescription.hasExternalTexture = true;
|
|
|
|
}
|
|
|
|
|
2011-12-13 13:11:32 -08:00
|
|
|
void OpenGLRenderer::setupDrawNoTexture() {
|
|
|
|
mCaches.disbaleTexCoordsVertexArray();
|
|
|
|
}
|
|
|
|
|
2011-04-13 17:58:08 -07:00
|
|
|
void OpenGLRenderer::setupDrawAALine() {
|
2011-05-02 15:00:16 -07:00
|
|
|
mDescription.isAA = true;
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
|
|
|
|
2011-03-21 13:11:28 -07:00
|
|
|
void OpenGLRenderer::setupDrawPoint(float pointSize) {
|
|
|
|
mDescription.isPoint = true;
|
|
|
|
mDescription.pointSize = pointSize;
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawColor(int color) {
|
2010-12-14 20:13:35 -08:00
|
|
|
setupDrawColor(color, (color >> 24) & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawColor(int color, int alpha) {
|
|
|
|
mColorA = alpha / 255.0f;
|
2011-04-22 16:42:10 -07:00
|
|
|
// Second divide of a by 255 is an optimization, allowing us to simply multiply
|
|
|
|
// the rgb values by a instead of also dividing by 255
|
2010-12-13 18:24:33 -08:00
|
|
|
const float a = mColorA / 255.0f;
|
2010-12-14 13:45:54 -08:00
|
|
|
mColorR = a * ((color >> 16) & 0xFF);
|
|
|
|
mColorG = a * ((color >> 8) & 0xFF);
|
|
|
|
mColorB = a * ((color ) & 0xFF);
|
2010-12-13 18:24:33 -08:00
|
|
|
mColorSet = true;
|
|
|
|
mSetShaderColor = mDescription.setColor(mColorR, mColorG, mColorB, mColorA);
|
|
|
|
}
|
|
|
|
|
2010-12-14 15:55:39 -08:00
|
|
|
void OpenGLRenderer::setupDrawAlpha8Color(int color, int alpha) {
|
|
|
|
mColorA = alpha / 255.0f;
|
2011-04-22 16:42:10 -07:00
|
|
|
// Double-divide of a by 255 is an optimization, allowing us to simply multiply
|
|
|
|
// the rgb values by a instead of also dividing by 255
|
2010-12-14 15:55:39 -08:00
|
|
|
const float a = mColorA / 255.0f;
|
|
|
|
mColorR = a * ((color >> 16) & 0xFF);
|
|
|
|
mColorG = a * ((color >> 8) & 0xFF);
|
|
|
|
mColorB = a * ((color ) & 0xFF);
|
|
|
|
mColorSet = true;
|
|
|
|
mSetShaderColor = mDescription.setAlpha8Color(mColorR, mColorG, mColorB, mColorA);
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawColor(float r, float g, float b, float a) {
|
|
|
|
mColorA = a;
|
|
|
|
mColorR = r;
|
|
|
|
mColorG = g;
|
|
|
|
mColorB = b;
|
|
|
|
mColorSet = true;
|
|
|
|
mSetShaderColor = mDescription.setColor(r, g, b, a);
|
|
|
|
}
|
|
|
|
|
2010-12-14 15:55:39 -08:00
|
|
|
void OpenGLRenderer::setupDrawAlpha8Color(float r, float g, float b, float a) {
|
|
|
|
mColorA = a;
|
|
|
|
mColorR = r;
|
|
|
|
mColorG = g;
|
|
|
|
mColorB = b;
|
|
|
|
mColorSet = true;
|
|
|
|
mSetShaderColor = mDescription.setAlpha8Color(r, g, b, a);
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawShader() {
|
|
|
|
if (mShader) {
|
|
|
|
mShader->describe(mDescription, mCaches.extensions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawColorFilter() {
|
|
|
|
if (mColorFilter) {
|
|
|
|
mColorFilter->describe(mDescription, mCaches.extensions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 11:43:46 -07:00
|
|
|
void OpenGLRenderer::accountForClear(SkXfermode::Mode mode) {
|
|
|
|
if (mColorSet && mode == SkXfermode::kClear_Mode) {
|
|
|
|
mColorA = 1.0f;
|
|
|
|
mColorR = mColorG = mColorB = 0.0f;
|
2011-06-13 19:04:27 -07:00
|
|
|
mSetShaderColor = mDescription.modulate = true;
|
2011-05-27 11:43:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawBlending(SkXfermode::Mode mode, bool swapSrcDst) {
|
2011-05-27 11:43:46 -07:00
|
|
|
// When the blending mode is kClear_Mode, we need to use a modulate color
|
|
|
|
// argb=1,0,0,0
|
|
|
|
accountForClear(mode);
|
2010-12-13 18:24:33 -08:00
|
|
|
chooseBlending((mColorSet && mColorA < 1.0f) || (mShader && mShader->blend()), mode,
|
|
|
|
mDescription, swapSrcDst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawBlending(bool blend, SkXfermode::Mode mode, bool swapSrcDst) {
|
2011-05-27 11:43:46 -07:00
|
|
|
// When the blending mode is kClear_Mode, we need to use a modulate color
|
|
|
|
// argb=1,0,0,0
|
|
|
|
accountForClear(mode);
|
2010-12-13 18:24:33 -08:00
|
|
|
chooseBlending(blend || (mColorSet && mColorA < 1.0f) || (mShader && mShader->blend()), mode,
|
|
|
|
mDescription, swapSrcDst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawProgram() {
|
|
|
|
useProgram(mCaches.programCache.get(mDescription));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawDirtyRegionsDisabled() {
|
|
|
|
mTrackDirtyRegions = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawModelViewTranslate(float left, float top, float right, float bottom,
|
|
|
|
bool ignoreTransform) {
|
|
|
|
mModelView.loadTranslate(left, top, 0.0f);
|
|
|
|
if (!ignoreTransform) {
|
|
|
|
mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
|
|
|
|
if (mTrackDirtyRegions) dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
|
|
|
|
} else {
|
|
|
|
mCaches.currentProgram->set(mOrthoMatrix, mModelView, mIdentity);
|
|
|
|
if (mTrackDirtyRegions) dirtyLayer(left, top, right, bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-26 07:28:09 -07:00
|
|
|
void OpenGLRenderer::setupDrawModelViewIdentity(bool offset) {
|
|
|
|
mCaches.currentProgram->set(mOrthoMatrix, mIdentity, *mSnapshot->transform, offset);
|
2010-12-14 20:13:35 -08:00
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawModelView(float left, float top, float right, float bottom,
|
|
|
|
bool ignoreTransform, bool ignoreModelView) {
|
|
|
|
if (!ignoreModelView) {
|
|
|
|
mModelView.loadTranslate(left, top, 0.0f);
|
|
|
|
mModelView.scale(right - left, bottom - top, 1.0f);
|
|
|
|
} else {
|
|
|
|
mModelView.loadIdentity();
|
|
|
|
}
|
2010-12-14 15:55:39 -08:00
|
|
|
bool dirty = right - left > 0.0f && bottom - top > 0.0f;
|
|
|
|
if (!ignoreTransform) {
|
|
|
|
mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
|
|
|
|
if (mTrackDirtyRegions && dirty) {
|
|
|
|
dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mCaches.currentProgram->set(mOrthoMatrix, mModelView, mIdentity);
|
|
|
|
if (mTrackDirtyRegions && dirty) dirtyLayer(left, top, right, bottom);
|
|
|
|
}
|
2010-12-13 18:24:33 -08:00
|
|
|
}
|
|
|
|
|
2011-03-21 13:11:28 -07:00
|
|
|
void OpenGLRenderer::setupDrawPointUniforms() {
|
|
|
|
int slot = mCaches.currentProgram->getUniform("pointSize");
|
|
|
|
glUniform1f(slot, mDescription.pointSize);
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawColorUniforms() {
|
2012-03-09 17:36:01 -08:00
|
|
|
if ((mColorSet && !mShader) || (mShader && mSetShaderColor)) {
|
2010-12-13 18:24:33 -08:00
|
|
|
mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-14 15:55:39 -08:00
|
|
|
void OpenGLRenderer::setupDrawPureColorUniforms() {
|
2010-12-14 10:59:41 -08:00
|
|
|
if (mSetShaderColor) {
|
2010-12-14 15:55:39 -08:00
|
|
|
mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA);
|
2010-12-14 10:59:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawShaderUniforms(bool ignoreTransform) {
|
|
|
|
if (mShader) {
|
|
|
|
if (ignoreTransform) {
|
|
|
|
mModelView.loadInverse(*mSnapshot->transform);
|
|
|
|
}
|
|
|
|
mShader->setupProgram(mCaches.currentProgram, mModelView, *mSnapshot, &mTextureUnit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-14 20:13:35 -08:00
|
|
|
void OpenGLRenderer::setupDrawShaderIdentityUniforms() {
|
|
|
|
if (mShader) {
|
|
|
|
mShader->setupProgram(mCaches.currentProgram, mIdentity, *mSnapshot, &mTextureUnit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawColorFilterUniforms() {
|
|
|
|
if (mColorFilter) {
|
|
|
|
mColorFilter->setupProgram(mCaches.currentProgram);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawSimpleMesh() {
|
2011-12-12 20:35:21 -08:00
|
|
|
bool force = mCaches.bindMeshBuffer();
|
|
|
|
mCaches.bindPositionVertexPointer(force, mCaches.currentProgram->position, 0);
|
2011-12-13 13:11:32 -08:00
|
|
|
mCaches.unbindIndicesBuffer();
|
2010-12-13 18:24:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawTexture(GLuint texture) {
|
|
|
|
bindTexture(texture);
|
2011-12-13 22:00:19 -08:00
|
|
|
mTextureUnit++;
|
2011-12-13 13:11:32 -08:00
|
|
|
mCaches.enableTexCoordsVertexArray();
|
2010-12-13 18:24:33 -08:00
|
|
|
}
|
|
|
|
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
void OpenGLRenderer::setupDrawExternalTexture(GLuint texture) {
|
|
|
|
bindExternalTexture(texture);
|
2011-12-13 22:00:19 -08:00
|
|
|
mTextureUnit++;
|
2011-12-13 13:11:32 -08:00
|
|
|
mCaches.enableTexCoordsVertexArray();
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
}
|
|
|
|
|
2011-05-02 17:24:22 -07:00
|
|
|
void OpenGLRenderer::setupDrawTextureTransform() {
|
|
|
|
mDescription.hasTextureTransform = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawTextureTransformUniforms(mat4& transform) {
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
glUniformMatrix4fv(mCaches.currentProgram->getUniform("mainTextureTransform"), 1,
|
|
|
|
GL_FALSE, &transform.data[0]);
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLuint vbo) {
|
2011-12-12 20:35:21 -08:00
|
|
|
bool force = false;
|
2010-12-13 18:24:33 -08:00
|
|
|
if (!vertices) {
|
2011-12-12 20:35:21 -08:00
|
|
|
force = mCaches.bindMeshBuffer(vbo == 0 ? mCaches.meshBuffer : vbo);
|
2010-12-13 18:24:33 -08:00
|
|
|
} else {
|
2011-12-12 20:35:21 -08:00
|
|
|
force = mCaches.unbindMeshBuffer();
|
2010-12-13 18:24:33 -08:00
|
|
|
}
|
2011-12-12 19:03:35 -08:00
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
mCaches.bindPositionVertexPointer(force, mCaches.currentProgram->position, vertices);
|
2011-12-13 13:11:32 -08:00
|
|
|
if (mCaches.currentProgram->texCoords >= 0) {
|
|
|
|
mCaches.bindTexCoordsVertexPointer(force, mCaches.currentProgram->texCoords, texCoords);
|
|
|
|
}
|
|
|
|
|
|
|
|
mCaches.unbindIndicesBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords) {
|
|
|
|
bool force = mCaches.unbindMeshBuffer();
|
|
|
|
mCaches.bindPositionVertexPointer(force, mCaches.currentProgram->position, vertices);
|
|
|
|
if (mCaches.currentProgram->texCoords >= 0) {
|
|
|
|
mCaches.bindTexCoordsVertexPointer(force, mCaches.currentProgram->texCoords, texCoords);
|
2010-12-14 20:13:35 -08:00
|
|
|
}
|
2010-12-13 18:24:33 -08:00
|
|
|
}
|
|
|
|
|
2011-04-13 17:58:08 -07:00
|
|
|
void OpenGLRenderer::setupDrawVertices(GLvoid* vertices) {
|
2011-12-12 20:35:21 -08:00
|
|
|
bool force = mCaches.unbindMeshBuffer();
|
|
|
|
mCaches.bindPositionVertexPointer(force, mCaches.currentProgram->position,
|
|
|
|
vertices, gVertexStride);
|
2011-12-13 13:11:32 -08:00
|
|
|
mCaches.unbindIndicesBuffer();
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the shader to draw an AA line. We draw AA lines with quads, where there is an
|
2011-05-02 15:00:16 -07:00
|
|
|
* outer boundary that fades out to 0. The variables set in the shader define the proportion of
|
|
|
|
* the width and length of the primitive occupied by the AA region. The vtxWidth and vtxLength
|
|
|
|
* attributes (one per vertex) are values from zero to one that tells the fragment
|
|
|
|
* shader where the fragment is in relation to the line width/length overall; these values are
|
|
|
|
* then used to compute the proper color, based on whether the fragment lies in the fading AA
|
|
|
|
* region of the line.
|
|
|
|
* Note that we only pass down the width values in this setup function. The length coordinates
|
|
|
|
* are set up for each individual segment.
|
2011-04-13 17:58:08 -07:00
|
|
|
*/
|
2011-05-02 15:00:16 -07:00
|
|
|
void OpenGLRenderer::setupDrawAALine(GLvoid* vertices, GLvoid* widthCoords,
|
2011-05-06 12:06:34 -07:00
|
|
|
GLvoid* lengthCoords, float boundaryWidthProportion) {
|
2011-12-12 20:35:21 -08:00
|
|
|
bool force = mCaches.unbindMeshBuffer();
|
|
|
|
mCaches.bindPositionVertexPointer(force, mCaches.currentProgram->position,
|
|
|
|
vertices, gAAVertexStride);
|
|
|
|
mCaches.resetTexCoordsVertexPointer();
|
2011-12-13 13:11:32 -08:00
|
|
|
mCaches.unbindIndicesBuffer();
|
2011-12-12 19:03:35 -08:00
|
|
|
|
2011-05-02 15:00:16 -07:00
|
|
|
int widthSlot = mCaches.currentProgram->getAttrib("vtxWidth");
|
|
|
|
glEnableVertexAttribArray(widthSlot);
|
|
|
|
glVertexAttribPointer(widthSlot, 1, GL_FLOAT, GL_FALSE, gAAVertexStride, widthCoords);
|
2011-12-12 19:03:35 -08:00
|
|
|
|
2011-05-02 15:00:16 -07:00
|
|
|
int lengthSlot = mCaches.currentProgram->getAttrib("vtxLength");
|
|
|
|
glEnableVertexAttribArray(lengthSlot);
|
|
|
|
glVertexAttribPointer(lengthSlot, 1, GL_FLOAT, GL_FALSE, gAAVertexStride, lengthCoords);
|
2011-12-12 19:03:35 -08:00
|
|
|
|
2011-04-13 17:58:08 -07:00
|
|
|
int boundaryWidthSlot = mCaches.currentProgram->getUniform("boundaryWidth");
|
2011-05-06 12:06:34 -07:00
|
|
|
glUniform1f(boundaryWidthSlot, boundaryWidthProportion);
|
2011-12-12 19:03:35 -08:00
|
|
|
|
2011-05-02 15:00:16 -07:00
|
|
|
// Setting the inverse value saves computations per-fragment in the shader
|
2011-04-13 17:58:08 -07:00
|
|
|
int inverseBoundaryWidthSlot = mCaches.currentProgram->getUniform("inverseBoundaryWidth");
|
2011-05-06 12:06:34 -07:00
|
|
|
glUniform1f(inverseBoundaryWidthSlot, (1 / boundaryWidthProportion));
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
void OpenGLRenderer::finishDrawTexture() {
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:47:49 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Drawing
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-14 18:05:08 -07:00
|
|
|
bool OpenGLRenderer::drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
|
2012-02-16 19:24:51 -08:00
|
|
|
Rect& dirty, int32_t flags, uint32_t level) {
|
2012-02-21 13:43:44 -08:00
|
|
|
float top = 0;
|
|
|
|
float left = 0;
|
|
|
|
float right = width;
|
|
|
|
float bottom = height;
|
|
|
|
if (USE_DISPLAY_LIST_PROPERTIES) {
|
|
|
|
Rect transformedRect;
|
|
|
|
displayList->transformRect(left, top, right, bottom, transformedRect);
|
|
|
|
left = transformedRect.left;
|
|
|
|
top = transformedRect.top;
|
|
|
|
right = transformedRect.right;
|
|
|
|
bottom = transformedRect.bottom;
|
|
|
|
}
|
|
|
|
if (quickReject(left, top, right, bottom)) {
|
2011-03-14 18:05:08 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-08 12:08:41 -08:00
|
|
|
// All the usual checks and setup operations (quickReject, setupDraw, etc.)
|
|
|
|
// will be performed by the display list itself
|
2011-08-25 14:01:48 -07:00
|
|
|
if (displayList && displayList->isRenderable()) {
|
2012-02-21 13:43:44 -08:00
|
|
|
return displayList->replay(*this, width, height, dirty, flags, level);
|
2010-11-08 12:08:41 -08:00
|
|
|
}
|
2011-03-14 18:05:08 -07:00
|
|
|
|
2011-01-10 14:10:36 -08:00
|
|
|
return false;
|
2010-11-08 12:08:41 -08:00
|
|
|
}
|
|
|
|
|
2011-04-22 16:18:45 -07:00
|
|
|
void OpenGLRenderer::outputDisplayList(DisplayList* displayList, uint32_t level) {
|
|
|
|
if (displayList) {
|
|
|
|
displayList->output(*this, level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 16:50:13 -07:00
|
|
|
void OpenGLRenderer::drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint) {
|
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
|
|
|
float x = left;
|
|
|
|
float y = top;
|
|
|
|
|
2011-07-25 16:36:01 -07:00
|
|
|
GLenum filter = GL_LINEAR;
|
2011-03-18 16:50:13 -07:00
|
|
|
bool ignoreTransform = false;
|
|
|
|
if (mSnapshot->transform->isPureTranslate()) {
|
|
|
|
x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
ignoreTransform = true;
|
2011-07-25 16:36:01 -07:00
|
|
|
filter = GL_NEAREST;
|
2011-11-30 20:21:23 -08:00
|
|
|
} else {
|
|
|
|
filter = FILTER(paint);
|
2011-03-18 16:50:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
setupDraw();
|
|
|
|
setupDrawWithTexture(true);
|
2011-03-23 17:15:38 -07:00
|
|
|
if (paint) {
|
|
|
|
setupDrawAlpha8Color(paint->getColor(), alpha);
|
|
|
|
}
|
2011-03-18 16:50:13 -07:00
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
|
|
|
setupDrawBlending(true, mode);
|
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawModelView(x, y, x + texture->width, y + texture->height, ignoreTransform);
|
2011-07-25 16:36:01 -07:00
|
|
|
|
2011-03-18 16:50:13 -07:00
|
|
|
setupDrawTexture(texture->id);
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setWrap(GL_CLAMP_TO_EDGE);
|
|
|
|
texture->setFilter(filter);
|
2011-07-25 16:36:01 -07:00
|
|
|
|
2011-03-18 16:50:13 -07:00
|
|
|
setupDrawPureColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawShaderUniforms();
|
|
|
|
setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
|
|
|
|
|
|
|
|
finishDrawTexture();
|
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
|
2010-07-12 20:20:03 -07:00
|
|
|
const float right = left + bitmap->width();
|
|
|
|
const float bottom = top + bitmap->height();
|
|
|
|
|
|
|
|
if (quickReject(left, top, right, bottom)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2010-10-25 18:03:28 -07:00
|
|
|
Texture* texture = mCaches.textureCache.get(bitmap);
|
2010-08-07 23:46:15 -07:00
|
|
|
if (!texture) return;
|
2010-08-06 11:18:34 -07:00
|
|
|
const AutoTexture autoCleanup(texture);
|
|
|
|
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_UNLIKELY(bitmap->getConfig() == SkBitmap::kA8_Config)) {
|
2011-03-18 16:50:13 -07:00
|
|
|
drawAlphaBitmap(texture, left, top, paint);
|
|
|
|
} else {
|
|
|
|
drawTextureRect(left, top, right, bottom, texture, paint);
|
|
|
|
}
|
2010-06-30 19:21:21 -07:00
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
|
2010-07-01 11:05:42 -07:00
|
|
|
Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
|
|
|
|
const mat4 transform(*matrix);
|
|
|
|
transform.mapRect(r);
|
|
|
|
|
2010-07-12 20:20:03 -07:00
|
|
|
if (quickReject(r.left, r.top, r.right, r.bottom)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2010-10-25 18:03:28 -07:00
|
|
|
Texture* texture = mCaches.textureCache.get(bitmap);
|
2010-08-07 23:46:15 -07:00
|
|
|
if (!texture) return;
|
2010-08-06 11:18:34 -07:00
|
|
|
const AutoTexture autoCleanup(texture);
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
// This could be done in a cheaper way, all we need is pass the matrix
|
|
|
|
// to the vertex shader. The save/restore is a bit overkill.
|
|
|
|
save(SkCanvas::kMatrix_SaveFlag);
|
|
|
|
concatMatrix(matrix);
|
|
|
|
drawTextureRect(0.0f, 0.0f, bitmap->width(), bitmap->height(), texture, paint);
|
|
|
|
restore();
|
2010-07-01 11:05:42 -07:00
|
|
|
}
|
|
|
|
|
2011-01-20 19:09:30 -08:00
|
|
|
void OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
|
|
|
|
float* vertices, int* colors, SkPaint* paint) {
|
|
|
|
// TODO: Do a quickReject
|
|
|
|
if (!vertices || mSnapshot->isIgnored()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2011-01-20 19:09:30 -08:00
|
|
|
Texture* texture = mCaches.textureCache.get(bitmap);
|
|
|
|
if (!texture) return;
|
|
|
|
const AutoTexture autoCleanup(texture);
|
2011-07-25 16:36:01 -07:00
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setWrap(GL_CLAMP_TO_EDGE, true);
|
|
|
|
texture->setFilter(FILTER(paint), true);
|
2011-01-20 19:09:30 -08:00
|
|
|
|
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
|
|
|
const uint32_t count = meshWidth * meshHeight * 6;
|
|
|
|
|
2011-02-10 15:52:54 -08:00
|
|
|
float left = FLT_MAX;
|
|
|
|
float top = FLT_MAX;
|
|
|
|
float right = FLT_MIN;
|
|
|
|
float bottom = FLT_MIN;
|
|
|
|
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
2012-02-01 16:10:55 -08:00
|
|
|
const bool hasActiveLayer = hasLayer();
|
2011-02-10 15:52:54 -08:00
|
|
|
#else
|
2012-02-01 16:10:55 -08:00
|
|
|
const bool hasActiveLayer = false;
|
2011-02-10 15:52:54 -08:00
|
|
|
#endif
|
|
|
|
|
2011-01-23 16:36:11 -08:00
|
|
|
// TODO: Support the colors array
|
|
|
|
TextureVertex mesh[count];
|
2011-01-20 19:09:30 -08:00
|
|
|
TextureVertex* vertex = mesh;
|
|
|
|
for (int32_t y = 0; y < meshHeight; y++) {
|
|
|
|
for (int32_t x = 0; x < meshWidth; x++) {
|
|
|
|
uint32_t i = (y * (meshWidth + 1) + x) * 2;
|
|
|
|
|
|
|
|
float u1 = float(x) / meshWidth;
|
|
|
|
float u2 = float(x + 1) / meshWidth;
|
|
|
|
float v1 = float(y) / meshHeight;
|
|
|
|
float v2 = float(y + 1) / meshHeight;
|
|
|
|
|
|
|
|
int ax = i + (meshWidth + 1) * 2;
|
|
|
|
int ay = ax + 1;
|
|
|
|
int bx = i;
|
|
|
|
int by = bx + 1;
|
|
|
|
int cx = i + 2;
|
|
|
|
int cy = cx + 1;
|
|
|
|
int dx = i + (meshWidth + 1) * 2 + 2;
|
|
|
|
int dy = dx + 1;
|
|
|
|
|
|
|
|
TextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2);
|
|
|
|
TextureVertex::set(vertex++, vertices[bx], vertices[by], u1, v1);
|
|
|
|
TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
|
|
|
|
|
|
|
|
TextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2);
|
|
|
|
TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
|
|
|
|
TextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2);
|
2011-02-10 15:52:54 -08:00
|
|
|
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
if (hasActiveLayer) {
|
|
|
|
// TODO: This could be optimized to avoid unnecessary ops
|
|
|
|
left = fminf(left, fminf(vertices[ax], fminf(vertices[bx], vertices[cx])));
|
|
|
|
top = fminf(top, fminf(vertices[ay], fminf(vertices[by], vertices[cy])));
|
|
|
|
right = fmaxf(right, fmaxf(vertices[ax], fmaxf(vertices[bx], vertices[cx])));
|
|
|
|
bottom = fmaxf(bottom, fmaxf(vertices[ay], fmaxf(vertices[by], vertices[cy])));
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-20 19:09:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-10 15:52:54 -08:00
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
if (hasActiveLayer) {
|
|
|
|
dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-20 19:09:30 -08:00
|
|
|
drawTextureMesh(0.0f, 0.0f, 1.0f, 1.0f, texture->id, alpha / 255.0f,
|
|
|
|
mode, texture->blend, &mesh[0].position[0], &mesh[0].texture[0],
|
2011-02-10 15:52:54 -08:00
|
|
|
GL_TRIANGLES, count, false, false, 0, false, false);
|
2011-01-20 19:09:30 -08:00
|
|
|
}
|
|
|
|
|
2010-06-30 19:21:21 -07:00
|
|
|
void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
|
|
|
|
float srcLeft, float srcTop, float srcRight, float srcBottom,
|
|
|
|
float dstLeft, float dstTop, float dstRight, float dstBottom,
|
2010-10-08 08:37:55 -07:00
|
|
|
SkPaint* paint) {
|
2010-07-12 20:20:03 -07:00
|
|
|
if (quickReject(dstLeft, dstTop, dstRight, dstBottom)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2010-10-25 18:03:28 -07:00
|
|
|
Texture* texture = mCaches.textureCache.get(bitmap);
|
2010-08-07 23:46:15 -07:00
|
|
|
if (!texture) return;
|
2010-08-06 11:18:34 -07:00
|
|
|
const AutoTexture autoCleanup(texture);
|
2010-06-30 19:21:21 -07:00
|
|
|
|
|
|
|
const float width = texture->width;
|
|
|
|
const float height = texture->height;
|
2010-06-30 17:56:19 -07:00
|
|
|
|
2011-08-22 17:33:33 -07:00
|
|
|
const float u1 = fmax(0.0f, srcLeft / width);
|
|
|
|
const float v1 = fmax(0.0f, srcTop / height);
|
|
|
|
const float u2 = fmin(1.0f, srcRight / width);
|
|
|
|
const float v2 = fmin(1.0f, srcBottom / height);
|
2010-06-30 17:56:19 -07:00
|
|
|
|
2010-10-18 14:06:08 -07:00
|
|
|
mCaches.unbindMeshBuffer();
|
2010-06-30 19:21:21 -07:00
|
|
|
resetDrawTextureTexCoords(u1, v1, u2, v2);
|
|
|
|
|
2010-10-18 14:06:08 -07:00
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setWrap(GL_CLAMP_TO_EDGE, true);
|
|
|
|
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(mSnapshot->transform->isPureTranslate())) {
|
2010-12-06 18:07:02 -08:00
|
|
|
const float x = (int) floorf(dstLeft + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
const float y = (int) floorf(dstTop + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
|
2011-07-28 15:39:12 -07:00
|
|
|
GLenum filter = GL_NEAREST;
|
2011-08-24 11:51:35 -07:00
|
|
|
// Enable linear filtering if the source rectangle is scaled
|
|
|
|
if (srcRight - srcLeft != dstRight - dstLeft || srcBottom - srcTop != dstBottom - dstTop) {
|
2011-11-30 20:21:23 -08:00
|
|
|
filter = FILTER(paint);
|
2011-07-28 15:39:12 -07:00
|
|
|
}
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setFilter(filter, true);
|
2010-12-06 18:07:02 -08:00
|
|
|
drawTextureMesh(x, y, x + (dstRight - dstLeft), y + (dstBottom - dstTop),
|
|
|
|
texture->id, alpha / 255.0f, mode, texture->blend,
|
|
|
|
&mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
|
|
|
|
GL_TRIANGLE_STRIP, gMeshCount, false, true);
|
|
|
|
} else {
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setFilter(FILTER(paint), true);
|
2010-12-06 18:07:02 -08:00
|
|
|
drawTextureMesh(dstLeft, dstTop, dstRight, dstBottom, texture->id, alpha / 255.0f,
|
|
|
|
mode, texture->blend, &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
|
|
|
|
GL_TRIANGLE_STRIP, gMeshCount);
|
|
|
|
}
|
2010-06-30 19:21:21 -07:00
|
|
|
|
|
|
|
resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
|
2010-06-29 21:05:21 -07:00
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
void OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
|
2010-10-12 15:59:26 -07:00
|
|
|
const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
|
2010-10-08 08:37:55 -07:00
|
|
|
float left, float top, float right, float bottom, SkPaint* paint) {
|
2010-07-12 20:20:03 -07:00
|
|
|
if (quickReject(left, top, right, bottom)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2010-10-25 18:03:28 -07:00
|
|
|
Texture* texture = mCaches.textureCache.get(bitmap);
|
2010-08-07 23:46:15 -07:00
|
|
|
if (!texture) return;
|
2010-08-06 11:18:34 -07:00
|
|
|
const AutoTexture autoCleanup(texture);
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setWrap(GL_CLAMP_TO_EDGE, true);
|
|
|
|
texture->setFilter(GL_LINEAR, true);
|
2010-07-08 19:17:03 -07:00
|
|
|
|
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
2010-10-08 18:36:15 -07:00
|
|
|
const Patch* mesh = mCaches.patchCache.get(bitmap->width(), bitmap->height(),
|
2010-10-12 15:59:26 -07:00
|
|
|
right - left, bottom - top, xDivs, yDivs, colors, width, height, numColors);
|
2010-07-08 19:17:03 -07:00
|
|
|
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(mesh && mesh->verticesCount > 0)) {
|
2010-12-06 18:07:02 -08:00
|
|
|
const bool pureTranslate = mSnapshot->transform->isPureTranslate();
|
2010-12-03 16:48:20 -08:00
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
2010-10-27 18:57:51 -07:00
|
|
|
// Mark the current layer dirty where we are going to draw the patch
|
2011-01-24 20:40:18 -08:00
|
|
|
if (hasLayer() && mesh->hasEmptyQuads) {
|
2011-02-04 14:00:42 -08:00
|
|
|
const float offsetX = left + mSnapshot->transform->getTranslateX();
|
|
|
|
const float offsetY = top + mSnapshot->transform->getTranslateY();
|
2010-10-27 18:57:51 -07:00
|
|
|
const size_t count = mesh->quads.size();
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
2010-12-07 13:30:10 -08:00
|
|
|
const Rect& bounds = mesh->quads.itemAt(i);
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(pureTranslate)) {
|
2011-02-04 14:00:42 -08:00
|
|
|
const float x = (int) floorf(bounds.left + offsetX + 0.5f);
|
|
|
|
const float y = (int) floorf(bounds.top + offsetY + 0.5f);
|
|
|
|
dirtyLayer(x, y, x + bounds.getWidth(), y + bounds.getHeight());
|
2010-12-06 18:07:02 -08:00
|
|
|
} else {
|
2011-02-04 14:00:42 -08:00
|
|
|
dirtyLayer(left + bounds.left, top + bounds.top,
|
|
|
|
left + bounds.right, top + bounds.bottom, *mSnapshot->transform);
|
2010-12-06 18:07:02 -08:00
|
|
|
}
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
}
|
2010-12-03 16:48:20 -08:00
|
|
|
#endif
|
2010-10-27 18:57:51 -07:00
|
|
|
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(pureTranslate)) {
|
2010-12-06 18:07:02 -08:00
|
|
|
const float x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
const float y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
|
|
|
|
drawTextureMesh(x, y, x + right - left, y + bottom - top, texture->id, alpha / 255.0f,
|
|
|
|
mode, texture->blend, (GLvoid*) 0, (GLvoid*) gMeshTextureOffset,
|
|
|
|
GL_TRIANGLES, mesh->verticesCount, false, true, mesh->meshBuffer,
|
|
|
|
true, !mesh->hasEmptyQuads);
|
|
|
|
} else {
|
|
|
|
drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f,
|
|
|
|
mode, texture->blend, (GLvoid*) 0, (GLvoid*) gMeshTextureOffset,
|
|
|
|
GL_TRIANGLES, mesh->verticesCount, false, false, mesh->meshBuffer,
|
|
|
|
true, !mesh->hasEmptyQuads);
|
|
|
|
}
|
2010-10-15 17:55:25 -07:00
|
|
|
}
|
2010-07-08 19:17:03 -07:00
|
|
|
}
|
|
|
|
|
2011-05-12 09:06:00 -07:00
|
|
|
/**
|
|
|
|
* This function uses a similar approach to that of AA lines in the drawLines() function.
|
|
|
|
* We expand the rectangle by a half pixel in screen space on all sides, and use a fragment
|
|
|
|
* shader to compute the translucency of the color, determined by whether a given pixel is
|
|
|
|
* within that boundary region and how far into the region it is.
|
|
|
|
*/
|
|
|
|
void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom,
|
2011-06-09 18:52:38 -07:00
|
|
|
int color, SkXfermode::Mode mode) {
|
2011-05-12 09:06:00 -07:00
|
|
|
float inverseScaleX = 1.0f;
|
|
|
|
float inverseScaleY = 1.0f;
|
|
|
|
// The quad that we use needs to account for scaling.
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_UNLIKELY(!mSnapshot->transform->isPureTranslate())) {
|
2011-05-12 09:06:00 -07:00
|
|
|
Matrix4 *mat = mSnapshot->transform;
|
|
|
|
float m00 = mat->data[Matrix4::kScaleX];
|
|
|
|
float m01 = mat->data[Matrix4::kSkewY];
|
|
|
|
float m02 = mat->data[2];
|
|
|
|
float m10 = mat->data[Matrix4::kSkewX];
|
|
|
|
float m11 = mat->data[Matrix4::kScaleX];
|
|
|
|
float m12 = mat->data[6];
|
|
|
|
float scaleX = sqrt(m00 * m00 + m01 * m01);
|
|
|
|
float scaleY = sqrt(m10 * m10 + m11 * m11);
|
|
|
|
inverseScaleX = (scaleX != 0) ? (inverseScaleX / scaleX) : 0;
|
|
|
|
inverseScaleY = (scaleY != 0) ? (inverseScaleY / scaleY) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setupDraw();
|
2011-12-13 13:11:32 -08:00
|
|
|
setupDrawNoTexture();
|
2011-05-12 09:06:00 -07:00
|
|
|
setupDrawAALine();
|
|
|
|
setupDrawColor(color);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
|
|
|
setupDrawBlending(true, mode);
|
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawModelViewIdentity(true);
|
|
|
|
setupDrawColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawShaderIdentityUniforms();
|
|
|
|
|
|
|
|
AAVertex rects[4];
|
|
|
|
AAVertex* aaVertices = &rects[0];
|
|
|
|
void* widthCoords = ((GLbyte*) aaVertices) + gVertexAAWidthOffset;
|
|
|
|
void* lengthCoords = ((GLbyte*) aaVertices) + gVertexAALengthOffset;
|
|
|
|
|
|
|
|
float boundarySizeX = .5 * inverseScaleX;
|
|
|
|
float boundarySizeY = .5 * inverseScaleY;
|
|
|
|
|
|
|
|
// Adjust the rect by the AA boundary padding
|
|
|
|
left -= boundarySizeX;
|
|
|
|
right += boundarySizeX;
|
|
|
|
top -= boundarySizeY;
|
|
|
|
bottom += boundarySizeY;
|
|
|
|
|
|
|
|
float width = right - left;
|
|
|
|
float height = bottom - top;
|
|
|
|
|
|
|
|
float boundaryWidthProportion = (width != 0) ? (2 * boundarySizeX) / width : 0;
|
|
|
|
float boundaryHeightProportion = (height != 0) ? (2 * boundarySizeY) / height : 0;
|
|
|
|
setupDrawAALine((void*) aaVertices, widthCoords, lengthCoords, boundaryWidthProportion);
|
|
|
|
int boundaryLengthSlot = mCaches.currentProgram->getUniform("boundaryLength");
|
|
|
|
int inverseBoundaryLengthSlot = mCaches.currentProgram->getUniform("inverseBoundaryLength");
|
|
|
|
glUniform1f(boundaryLengthSlot, boundaryHeightProportion);
|
|
|
|
glUniform1f(inverseBoundaryLengthSlot, (1 / boundaryHeightProportion));
|
|
|
|
|
|
|
|
if (!quickReject(left, top, right, bottom)) {
|
|
|
|
AAVertex::set(aaVertices++, left, bottom, 1, 1);
|
|
|
|
AAVertex::set(aaVertices++, left, top, 1, 0);
|
|
|
|
AAVertex::set(aaVertices++, right, bottom, 0, 1);
|
|
|
|
AAVertex::set(aaVertices++, right, top, 0, 0);
|
|
|
|
dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 12:06:34 -07:00
|
|
|
/**
|
|
|
|
* We draw lines as quads (tristrips). Using GL_LINES can be difficult because the rasterization
|
|
|
|
* rules for those lines produces some unexpected results, and may vary between hardware devices.
|
|
|
|
* The basics of lines-as-quads is easy; we simply find the normal to the line and position the
|
|
|
|
* corners of the quads on either side of each line endpoint, separated by the strokeWidth
|
|
|
|
* of the line. Hairlines are more involved because we need to account for transform scaling
|
|
|
|
* to end up with a one-pixel-wide line in screen space..
|
|
|
|
* Anti-aliased lines add another factor to the approach. We use a specialized fragment shader
|
|
|
|
* in combination with values that we calculate and pass down in this method. The basic approach
|
|
|
|
* is that the quad we create contains both the core line area plus a bounding area in which
|
|
|
|
* the translucent/AA pixels are drawn. The values we calculate tell the shader what
|
|
|
|
* proportion of the width and the length of a given segment is represented by the boundary
|
|
|
|
* region. The quad ends up being exactly .5 pixel larger in all directions than the non-AA quad.
|
|
|
|
* The bounding region is actually 1 pixel wide on all sides (half pixel on the outside, half pixel
|
|
|
|
* on the inside). This ends up giving the result we want, with pixels that are completely
|
|
|
|
* 'inside' the line area being filled opaquely and the other pixels being filled according to
|
|
|
|
* how far into the boundary region they are, which is determined by shader interpolation.
|
|
|
|
*/
|
2011-04-26 07:28:09 -07:00
|
|
|
void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
|
|
|
|
if (mSnapshot->isIgnored()) return;
|
|
|
|
|
|
|
|
const bool isAA = paint->isAntiAlias();
|
2011-05-06 12:06:34 -07:00
|
|
|
// We use half the stroke width here because we're going to position the quad
|
|
|
|
// corner vertices half of the width away from the line endpoints
|
|
|
|
float halfStrokeWidth = paint->getStrokeWidth() * 0.5f;
|
2011-04-26 07:28:09 -07:00
|
|
|
// A stroke width of 0 has a special meaning in Skia:
|
|
|
|
// it draws a line 1 px wide regardless of current transform
|
|
|
|
bool isHairLine = paint->getStrokeWidth() == 0.0f;
|
2011-05-06 12:06:34 -07:00
|
|
|
float inverseScaleX = 1.0f;
|
|
|
|
float inverseScaleY = 1.0f;
|
|
|
|
bool scaled = false;
|
2011-04-26 07:28:09 -07:00
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
int generatedVerticesCount = 0;
|
2011-04-13 17:58:08 -07:00
|
|
|
int verticesCount = count;
|
|
|
|
if (count > 4) {
|
2011-05-06 14:13:05 -07:00
|
|
|
// Polyline: account for extra vertices needed for continuous tri-strip
|
2011-05-06 12:06:34 -07:00
|
|
|
verticesCount += (count - 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isHairLine || isAA) {
|
|
|
|
// The quad that we use for AA and hairlines needs to account for scaling. For hairlines
|
|
|
|
// the line on the screen should always be one pixel wide regardless of scale. For
|
|
|
|
// AA lines, we only want one pixel of translucent boundary around the quad.
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_UNLIKELY(!mSnapshot->transform->isPureTranslate())) {
|
2011-05-06 12:06:34 -07:00
|
|
|
Matrix4 *mat = mSnapshot->transform;
|
|
|
|
float m00 = mat->data[Matrix4::kScaleX];
|
|
|
|
float m01 = mat->data[Matrix4::kSkewY];
|
|
|
|
float m02 = mat->data[2];
|
|
|
|
float m10 = mat->data[Matrix4::kSkewX];
|
|
|
|
float m11 = mat->data[Matrix4::kScaleX];
|
|
|
|
float m12 = mat->data[6];
|
2012-02-01 16:10:55 -08:00
|
|
|
float scaleX = sqrtf(m00 * m00 + m01 * m01);
|
|
|
|
float scaleY = sqrtf(m10 * m10 + m11 * m11);
|
2011-05-06 12:06:34 -07:00
|
|
|
inverseScaleX = (scaleX != 0) ? (inverseScaleX / scaleX) : 0;
|
|
|
|
inverseScaleY = (scaleY != 0) ? (inverseScaleY / scaleY) : 0;
|
|
|
|
if (inverseScaleX != 1.0f || inverseScaleY != 1.0f) {
|
|
|
|
scaled = true;
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
2011-04-26 07:28:09 -07:00
|
|
|
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
setupDraw();
|
2011-12-13 13:11:32 -08:00
|
|
|
setupDrawNoTexture();
|
2011-04-26 07:28:09 -07:00
|
|
|
if (isAA) {
|
|
|
|
setupDrawAALine();
|
|
|
|
}
|
|
|
|
setupDrawColor(paint->getColor(), alpha);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
2012-02-01 16:10:55 -08:00
|
|
|
setupDrawBlending(isAA, mode);
|
2011-04-26 07:28:09 -07:00
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawModelViewIdentity(true);
|
|
|
|
setupDrawColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawShaderIdentityUniforms();
|
|
|
|
|
|
|
|
if (isHairLine) {
|
|
|
|
// Set a real stroke width to be used in quad construction
|
2011-05-06 12:06:34 -07:00
|
|
|
halfStrokeWidth = isAA? 1 : .5;
|
|
|
|
} else if (isAA && !scaled) {
|
2011-04-13 17:58:08 -07:00
|
|
|
// Expand boundary to enable AA calculations on the quad border
|
2011-05-06 12:06:34 -07:00
|
|
|
halfStrokeWidth += .5f;
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
|
|
|
Vertex lines[verticesCount];
|
|
|
|
Vertex* vertices = &lines[0];
|
2011-05-02 15:00:16 -07:00
|
|
|
AAVertex wLines[verticesCount];
|
|
|
|
AAVertex* aaVertices = &wLines[0];
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_UNLIKELY(!isAA)) {
|
2011-04-13 17:58:08 -07:00
|
|
|
setupDrawVertices(vertices);
|
|
|
|
} else {
|
2011-05-02 15:00:16 -07:00
|
|
|
void* widthCoords = ((GLbyte*) aaVertices) + gVertexAAWidthOffset;
|
|
|
|
void* lengthCoords = ((GLbyte*) aaVertices) + gVertexAALengthOffset;
|
2011-05-06 12:06:34 -07:00
|
|
|
// innerProportion is the ratio of the inner (non-AA) part of the line to the total
|
2011-04-13 17:58:08 -07:00
|
|
|
// AA stroke width (the base stroke width expanded by a half pixel on either side).
|
|
|
|
// This value is used in the fragment shader to determine how to fill fragments.
|
2011-05-06 12:06:34 -07:00
|
|
|
// We will need to calculate the actual width proportion on each segment for
|
|
|
|
// scaled non-hairlines, since the boundary proportion may differ per-axis when scaled.
|
|
|
|
float boundaryWidthProportion = 1 / (2 * halfStrokeWidth);
|
|
|
|
setupDrawAALine((void*) aaVertices, widthCoords, lengthCoords, boundaryWidthProportion);
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
|
|
|
|
2011-05-06 12:06:34 -07:00
|
|
|
AAVertex* prevAAVertex = NULL;
|
|
|
|
Vertex* prevVertex = NULL;
|
2011-04-26 15:33:10 -07:00
|
|
|
|
2011-05-02 15:00:16 -07:00
|
|
|
int boundaryLengthSlot = -1;
|
|
|
|
int inverseBoundaryLengthSlot = -1;
|
2011-05-06 12:06:34 -07:00
|
|
|
int boundaryWidthSlot = -1;
|
|
|
|
int inverseBoundaryWidthSlot = -1;
|
2011-04-13 17:58:08 -07:00
|
|
|
for (int i = 0; i < count; i += 4) {
|
|
|
|
// a = start point, b = end point
|
|
|
|
vec2 a(points[i], points[i + 1]);
|
|
|
|
vec2 b(points[i + 2], points[i + 3]);
|
2011-05-02 15:00:16 -07:00
|
|
|
float length = 0;
|
2011-05-06 12:06:34 -07:00
|
|
|
float boundaryLengthProportion = 0;
|
|
|
|
float boundaryWidthProportion = 0;
|
2011-04-13 17:58:08 -07:00
|
|
|
|
|
|
|
// Find the normal to the line
|
2011-05-06 12:06:34 -07:00
|
|
|
vec2 n = (b - a).copyNormalized() * halfStrokeWidth;
|
2011-04-26 07:28:09 -07:00
|
|
|
if (isHairLine) {
|
|
|
|
if (isAA) {
|
|
|
|
float wideningFactor;
|
|
|
|
if (fabs(n.x) >= fabs(n.y)) {
|
|
|
|
wideningFactor = fabs(1.0f / n.x);
|
|
|
|
} else {
|
|
|
|
wideningFactor = fabs(1.0f / n.y);
|
|
|
|
}
|
|
|
|
n *= wideningFactor;
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
2011-05-06 12:06:34 -07:00
|
|
|
if (scaled) {
|
|
|
|
n.x *= inverseScaleX;
|
|
|
|
n.y *= inverseScaleY;
|
|
|
|
}
|
|
|
|
} else if (scaled) {
|
|
|
|
// Extend n by .5 pixel on each side, post-transform
|
|
|
|
vec2 extendedN = n.copyNormalized();
|
|
|
|
extendedN /= 2;
|
|
|
|
extendedN.x *= inverseScaleX;
|
|
|
|
extendedN.y *= inverseScaleY;
|
|
|
|
float extendedNLength = extendedN.length();
|
|
|
|
// We need to set this value on the shader prior to drawing
|
|
|
|
boundaryWidthProportion = extendedNLength / (halfStrokeWidth + extendedNLength);
|
|
|
|
n += extendedN;
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
|
|
|
float x = n.x;
|
|
|
|
n.x = -n.y;
|
|
|
|
n.y = x;
|
|
|
|
|
2011-05-02 15:00:16 -07:00
|
|
|
// aa lines expand the endpoint vertices to encompass the AA boundary
|
|
|
|
if (isAA) {
|
|
|
|
vec2 abVector = (b - a);
|
|
|
|
length = abVector.length();
|
|
|
|
abVector.normalize();
|
2011-05-06 12:06:34 -07:00
|
|
|
if (scaled) {
|
|
|
|
abVector.x *= inverseScaleX;
|
|
|
|
abVector.y *= inverseScaleY;
|
|
|
|
float abLength = abVector.length();
|
|
|
|
boundaryLengthProportion = abLength / (length + abLength);
|
|
|
|
} else {
|
|
|
|
boundaryLengthProportion = .5 / (length + 1);
|
|
|
|
}
|
|
|
|
abVector /= 2;
|
2011-05-02 15:00:16 -07:00
|
|
|
a -= abVector;
|
|
|
|
b += abVector;
|
|
|
|
}
|
|
|
|
|
2011-04-13 17:58:08 -07:00
|
|
|
// Four corners of the rectangle defining a thick line
|
|
|
|
vec2 p1 = a - n;
|
|
|
|
vec2 p2 = a + n;
|
|
|
|
vec2 p3 = b + n;
|
|
|
|
vec2 p4 = b - n;
|
|
|
|
|
2011-05-02 15:00:16 -07:00
|
|
|
|
2011-04-13 17:58:08 -07:00
|
|
|
const float left = fmin(p1.x, fmin(p2.x, fmin(p3.x, p4.x)));
|
|
|
|
const float right = fmax(p1.x, fmax(p2.x, fmax(p3.x, p4.x)));
|
|
|
|
const float top = fmin(p1.y, fmin(p2.y, fmin(p3.y, p4.y)));
|
|
|
|
const float bottom = fmax(p1.y, fmax(p2.y, fmax(p3.y, p4.y)));
|
|
|
|
|
|
|
|
if (!quickReject(left, top, right, bottom)) {
|
|
|
|
if (!isAA) {
|
|
|
|
if (prevVertex != NULL) {
|
|
|
|
// Issue two repeat vertices to create degenerate triangles to bridge
|
|
|
|
// between the previous line and the new one. This is necessary because
|
|
|
|
// we are creating a single triangle_strip which will contain
|
|
|
|
// potentially discontinuous line segments.
|
|
|
|
Vertex::set(vertices++, prevVertex->position[0], prevVertex->position[1]);
|
|
|
|
Vertex::set(vertices++, p1.x, p1.y);
|
|
|
|
generatedVerticesCount += 2;
|
|
|
|
}
|
|
|
|
Vertex::set(vertices++, p1.x, p1.y);
|
|
|
|
Vertex::set(vertices++, p2.x, p2.y);
|
|
|
|
Vertex::set(vertices++, p4.x, p4.y);
|
|
|
|
Vertex::set(vertices++, p3.x, p3.y);
|
|
|
|
prevVertex = vertices - 1;
|
|
|
|
generatedVerticesCount += 4;
|
|
|
|
} else {
|
2011-05-06 12:06:34 -07:00
|
|
|
if (!isHairLine && scaled) {
|
|
|
|
// Must set width proportions per-segment for scaled non-hairlines to use the
|
|
|
|
// correct AA boundary dimensions
|
|
|
|
if (boundaryWidthSlot < 0) {
|
|
|
|
boundaryWidthSlot =
|
|
|
|
mCaches.currentProgram->getUniform("boundaryWidth");
|
|
|
|
inverseBoundaryWidthSlot =
|
|
|
|
mCaches.currentProgram->getUniform("inverseBoundaryWidth");
|
|
|
|
}
|
|
|
|
glUniform1f(boundaryWidthSlot, boundaryWidthProportion);
|
|
|
|
glUniform1f(inverseBoundaryWidthSlot, (1 / boundaryWidthProportion));
|
|
|
|
}
|
2011-05-02 15:00:16 -07:00
|
|
|
if (boundaryLengthSlot < 0) {
|
|
|
|
boundaryLengthSlot = mCaches.currentProgram->getUniform("boundaryLength");
|
|
|
|
inverseBoundaryLengthSlot =
|
|
|
|
mCaches.currentProgram->getUniform("inverseBoundaryLength");
|
|
|
|
}
|
2011-05-06 12:06:34 -07:00
|
|
|
glUniform1f(boundaryLengthSlot, boundaryLengthProportion);
|
|
|
|
glUniform1f(inverseBoundaryLengthSlot, (1 / boundaryLengthProportion));
|
2011-05-02 15:00:16 -07:00
|
|
|
|
2011-04-13 17:58:08 -07:00
|
|
|
if (prevAAVertex != NULL) {
|
|
|
|
// Issue two repeat vertices to create degenerate triangles to bridge
|
|
|
|
// between the previous line and the new one. This is necessary because
|
|
|
|
// we are creating a single triangle_strip which will contain
|
|
|
|
// potentially discontinuous line segments.
|
2011-05-02 15:00:16 -07:00
|
|
|
AAVertex::set(aaVertices++,prevAAVertex->position[0],
|
|
|
|
prevAAVertex->position[1], prevAAVertex->width, prevAAVertex->length);
|
|
|
|
AAVertex::set(aaVertices++, p4.x, p4.y, 1, 1);
|
2011-04-13 17:58:08 -07:00
|
|
|
generatedVerticesCount += 2;
|
|
|
|
}
|
2011-05-02 15:00:16 -07:00
|
|
|
AAVertex::set(aaVertices++, p4.x, p4.y, 1, 1);
|
|
|
|
AAVertex::set(aaVertices++, p1.x, p1.y, 1, 0);
|
|
|
|
AAVertex::set(aaVertices++, p3.x, p3.y, 0, 1);
|
|
|
|
AAVertex::set(aaVertices++, p2.x, p2.y, 0, 0);
|
2011-04-13 17:58:08 -07:00
|
|
|
prevAAVertex = aaVertices - 1;
|
|
|
|
generatedVerticesCount += 4;
|
|
|
|
}
|
2011-05-02 15:00:16 -07:00
|
|
|
dirtyLayer(a.x == b.x ? left - 1 : left, a.y == b.y ? top - 1 : top,
|
|
|
|
a.x == b.x ? right: right, a.y == b.y ? bottom: bottom,
|
|
|
|
*mSnapshot->transform);
|
2011-04-13 17:58:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (generatedVerticesCount > 0) {
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, generatedVerticesCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-21 13:11:28 -07:00
|
|
|
void OpenGLRenderer::drawPoints(float* points, int count, SkPaint* paint) {
|
|
|
|
if (mSnapshot->isIgnored()) return;
|
|
|
|
|
|
|
|
// TODO: The paint's cap style defines whether the points are square or circular
|
|
|
|
// TODO: Handle AA for round points
|
|
|
|
|
2011-04-13 17:58:08 -07:00
|
|
|
// A stroke width of 0 has a special meaning in Skia:
|
2011-03-21 13:11:28 -07:00
|
|
|
// it draws an unscaled 1px point
|
2011-04-26 07:28:09 -07:00
|
|
|
float strokeWidth = paint->getStrokeWidth();
|
2011-03-21 13:11:28 -07:00
|
|
|
const bool isHairLine = paint->getStrokeWidth() == 0.0f;
|
2011-04-26 07:28:09 -07:00
|
|
|
if (isHairLine) {
|
|
|
|
// Now that we know it's hairline, we can set the effective width, to be used later
|
|
|
|
strokeWidth = 1.0f;
|
|
|
|
}
|
|
|
|
const float halfWidth = strokeWidth / 2;
|
2011-03-21 13:11:28 -07:00
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
|
|
|
int verticesCount = count >> 1;
|
|
|
|
int generatedVerticesCount = 0;
|
|
|
|
|
|
|
|
TextureVertex pointsData[verticesCount];
|
|
|
|
TextureVertex* vertex = &pointsData[0];
|
|
|
|
|
|
|
|
setupDraw();
|
2011-12-13 13:11:32 -08:00
|
|
|
setupDrawNoTexture();
|
2011-04-26 07:28:09 -07:00
|
|
|
setupDrawPoint(strokeWidth);
|
2011-03-21 13:11:28 -07:00
|
|
|
setupDrawColor(paint->getColor(), alpha);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
|
|
|
setupDrawBlending(mode);
|
|
|
|
setupDrawProgram();
|
2011-04-26 07:28:09 -07:00
|
|
|
setupDrawModelViewIdentity(true);
|
2011-03-21 13:11:28 -07:00
|
|
|
setupDrawColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawPointUniforms();
|
|
|
|
setupDrawShaderIdentityUniforms();
|
|
|
|
setupDrawMesh(vertex);
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i += 2) {
|
|
|
|
TextureVertex::set(vertex++, points[i], points[i + 1], 0.0f, 0.0f);
|
|
|
|
generatedVerticesCount++;
|
2011-04-26 07:28:09 -07:00
|
|
|
float left = points[i] - halfWidth;
|
|
|
|
float right = points[i] + halfWidth;
|
|
|
|
float top = points[i + 1] - halfWidth;
|
|
|
|
float bottom = points [i + 1] + halfWidth;
|
|
|
|
dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
|
2011-03-21 13:11:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
glDrawArrays(GL_POINTS, 0, generatedVerticesCount);
|
|
|
|
}
|
|
|
|
|
2010-06-22 13:11:24 -07:00
|
|
|
void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
|
2010-11-03 19:58:32 -07:00
|
|
|
// No need to check against the clip, we fill the clip region
|
2010-12-09 17:47:21 -08:00
|
|
|
if (mSnapshot->isIgnored()) return;
|
2010-11-03 19:58:32 -07:00
|
|
|
|
2010-10-22 17:49:18 -07:00
|
|
|
Rect& clip(*mSnapshot->clipRect);
|
|
|
|
clip.snapToPixelBoundaries();
|
2010-12-13 18:24:33 -08:00
|
|
|
|
2010-07-14 16:34:53 -07:00
|
|
|
drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode, true);
|
2010-06-25 13:41:57 -07:00
|
|
|
}
|
2010-06-24 19:30:36 -07:00
|
|
|
|
2011-01-23 14:18:41 -08:00
|
|
|
void OpenGLRenderer::drawShape(float left, float top, const PathTexture* texture, SkPaint* paint) {
|
2011-01-19 21:54:02 -08:00
|
|
|
if (!texture) return;
|
|
|
|
const AutoTexture autoCleanup(texture);
|
|
|
|
|
|
|
|
const float x = left + texture->left - texture->offset;
|
|
|
|
const float y = top + texture->top - texture->offset;
|
|
|
|
|
|
|
|
drawPathTexture(texture, x, y, paint);
|
|
|
|
}
|
|
|
|
|
2011-01-23 14:18:41 -08:00
|
|
|
void OpenGLRenderer::drawRoundRect(float left, float top, float right, float bottom,
|
|
|
|
float rx, float ry, SkPaint* paint) {
|
2011-01-19 21:54:02 -08:00
|
|
|
if (mSnapshot->isIgnored()) return;
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2011-01-23 14:18:41 -08:00
|
|
|
const PathTexture* texture = mCaches.roundRectShapeCache.getRoundRect(
|
|
|
|
right - left, bottom - top, rx, ry, paint);
|
|
|
|
drawShape(left, top, texture, paint);
|
|
|
|
}
|
2011-01-19 21:54:02 -08:00
|
|
|
|
2011-01-23 14:18:41 -08:00
|
|
|
void OpenGLRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
|
|
|
|
if (mSnapshot->isIgnored()) return;
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2011-01-19 21:54:02 -08:00
|
|
|
const PathTexture* texture = mCaches.circleShapeCache.getCircle(radius, paint);
|
2011-01-23 14:18:41 -08:00
|
|
|
drawShape(x - radius, y - radius, texture, paint);
|
|
|
|
}
|
2011-01-19 21:54:02 -08:00
|
|
|
|
2011-01-23 14:18:41 -08:00
|
|
|
void OpenGLRenderer::drawOval(float left, float top, float right, float bottom, SkPaint* paint) {
|
|
|
|
if (mSnapshot->isIgnored()) return;
|
2011-01-19 21:54:02 -08:00
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2011-01-23 14:18:41 -08:00
|
|
|
const PathTexture* texture = mCaches.ovalShapeCache.getOval(right - left, bottom - top, paint);
|
|
|
|
drawShape(left, top, texture, paint);
|
|
|
|
}
|
|
|
|
|
2011-01-23 16:15:02 -08:00
|
|
|
void OpenGLRenderer::drawArc(float left, float top, float right, float bottom,
|
|
|
|
float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
|
|
|
|
if (mSnapshot->isIgnored()) return;
|
|
|
|
|
|
|
|
if (fabs(sweepAngle) >= 360.0f) {
|
|
|
|
drawOval(left, top, right, bottom, paint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2011-01-23 16:15:02 -08:00
|
|
|
const PathTexture* texture = mCaches.arcShapeCache.getArc(right - left, bottom - top,
|
|
|
|
startAngle, sweepAngle, useCenter, paint);
|
|
|
|
drawShape(left, top, texture, paint);
|
|
|
|
}
|
|
|
|
|
2011-01-23 14:18:41 -08:00
|
|
|
void OpenGLRenderer::drawRectAsShape(float left, float top, float right, float bottom,
|
|
|
|
SkPaint* paint) {
|
|
|
|
if (mSnapshot->isIgnored()) return;
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2011-01-23 14:18:41 -08:00
|
|
|
const PathTexture* texture = mCaches.rectShapeCache.getRect(right - left, bottom - top, paint);
|
|
|
|
drawShape(left, top, texture, paint);
|
2011-01-19 21:54:02 -08:00
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, SkPaint* p) {
|
2011-01-23 14:18:41 -08:00
|
|
|
if (p->getStyle() != SkPaint::kFill_Style) {
|
|
|
|
drawRectAsShape(left, top, right, bottom, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:20:03 -07:00
|
|
|
if (quickReject(left, top, right, bottom)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-28 17:12:22 -07:00
|
|
|
SkXfermode::Mode mode;
|
2010-10-26 16:27:31 -07:00
|
|
|
if (!mCaches.extensions.hasFramebufferFetch()) {
|
2010-09-09 14:42:43 -07:00
|
|
|
const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
|
|
|
|
if (!isMode) {
|
|
|
|
// Assume SRC_OVER
|
|
|
|
mode = SkXfermode::kSrcOver_Mode;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mode = getXfermode(p->getXfermode());
|
2010-06-28 17:12:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int color = p->getColor();
|
2011-06-09 18:52:38 -07:00
|
|
|
if (p->isAntiAlias() && !mSnapshot->transform->isSimple()) {
|
2011-05-12 09:06:00 -07:00
|
|
|
drawAARect(left, top, right, bottom, color, mode);
|
|
|
|
} else {
|
|
|
|
drawColorRect(left, top, right, bottom, color, mode);
|
|
|
|
}
|
2010-06-25 13:41:57 -07:00
|
|
|
}
|
2010-06-24 19:30:36 -07:00
|
|
|
|
2012-01-17 17:39:26 -08:00
|
|
|
void OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count,
|
|
|
|
const float* positions, SkPaint* paint) {
|
2012-01-18 12:39:17 -08:00
|
|
|
if (text == NULL || count == 0 || mSnapshot->isIgnored() ||
|
|
|
|
(paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
|
2012-01-17 17:39:26 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-18 12:39:17 -08:00
|
|
|
// NOTE: Skia does not support perspective transform on drawPosText yet
|
|
|
|
if (!mSnapshot->transform->isSimple()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float x = 0.0f;
|
|
|
|
float y = 0.0f;
|
|
|
|
const bool pureTranslate = mSnapshot->transform->isPureTranslate();
|
|
|
|
if (pureTranslate) {
|
|
|
|
x = (int) floorf(x + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
|
|
|
|
fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
|
|
|
|
paint->getTextSize());
|
|
|
|
|
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
|
|
|
// Pick the appropriate texture filtering
|
|
|
|
bool linearFilter = mSnapshot->transform->changesBounds();
|
|
|
|
if (pureTranslate && !linearFilter) {
|
|
|
|
linearFilter = fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCaches.activeTexture(0);
|
|
|
|
setupDraw();
|
|
|
|
setupDrawDirtyRegionsDisabled();
|
|
|
|
setupDrawWithTexture(true);
|
|
|
|
setupDrawAlpha8Color(paint->getColor(), alpha);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
|
|
|
setupDrawBlending(true, mode);
|
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawModelView(x, y, x, y, pureTranslate, true);
|
|
|
|
setupDrawTexture(fontRenderer.getTexture(linearFilter));
|
|
|
|
setupDrawPureColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawShaderUniforms(pureTranslate);
|
|
|
|
|
|
|
|
const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip();
|
|
|
|
Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f);
|
|
|
|
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
2012-02-01 16:10:55 -08:00
|
|
|
const bool hasActiveLayer = hasLayer();
|
2012-01-18 12:39:17 -08:00
|
|
|
#else
|
2012-02-01 16:10:55 -08:00
|
|
|
const bool hasActiveLayer = false;
|
2012-01-18 12:39:17 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fontRenderer.renderPosText(paint, clip, text, 0, bytesCount, count, x, y,
|
|
|
|
positions, hasActiveLayer ? &bounds : NULL)) {
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
if (hasActiveLayer) {
|
|
|
|
if (!pureTranslate) {
|
|
|
|
mSnapshot->transform->mapRect(bounds);
|
|
|
|
}
|
|
|
|
dirtyLayerUnchecked(bounds, getRegion());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2012-01-17 17:39:26 -08:00
|
|
|
}
|
|
|
|
|
2010-07-23 18:55:21 -07:00
|
|
|
void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
|
2011-12-01 20:08:50 -08:00
|
|
|
float x, float y, SkPaint* paint, float length) {
|
2012-01-18 12:39:17 -08:00
|
|
|
if (text == NULL || count == 0 || mSnapshot->isIgnored() ||
|
|
|
|
(paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
|
2010-07-23 18:55:21 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:43:44 -08:00
|
|
|
if (length < 0.0f) length = paint->measureText(text, bytesCount);
|
2010-07-23 18:55:21 -07:00
|
|
|
switch (paint->getTextAlign()) {
|
|
|
|
case SkPaint::kCenter_Align:
|
|
|
|
x -= length / 2.0f;
|
|
|
|
break;
|
|
|
|
case SkPaint::kRight_Align:
|
|
|
|
x -= length;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-01 20:08:50 -08:00
|
|
|
SkPaint::FontMetrics metrics;
|
|
|
|
paint->getFontMetrics(&metrics, 0.0f);
|
2012-02-16 19:24:51 -08:00
|
|
|
if (quickReject(x, y + metrics.fTop, x + length, y + metrics.fBottom)) {
|
2011-12-01 20:08:50 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-06 18:47:50 -08:00
|
|
|
const float oldX = x;
|
|
|
|
const float oldY = y;
|
2010-12-06 18:07:02 -08:00
|
|
|
const bool pureTranslate = mSnapshot->transform->isPureTranslate();
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(pureTranslate)) {
|
2010-12-06 18:07:02 -08:00
|
|
|
x = (int) floorf(x + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
}
|
|
|
|
|
2011-10-17 11:06:46 -07:00
|
|
|
#if DEBUG_GLYPHS
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("OpenGLRenderer drawText() with FontID=%d", SkTypeface::UniqueID(paint->getTypeface()));
|
2011-10-17 11:06:46 -07:00
|
|
|
#endif
|
2012-01-17 17:39:26 -08:00
|
|
|
|
|
|
|
FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
|
2010-08-26 20:35:23 -07:00
|
|
|
fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
|
2010-08-23 21:05:08 -07:00
|
|
|
paint->getTextSize());
|
2010-09-24 18:39:22 -07:00
|
|
|
|
2010-12-14 15:55:39 -08:00
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
2010-10-15 16:06:03 -07:00
|
|
|
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_UNLIKELY(mHasShadow)) {
|
2011-12-13 22:00:19 -08:00
|
|
|
mCaches.activeTexture(0);
|
|
|
|
|
2010-08-26 20:35:23 -07:00
|
|
|
mCaches.dropShadowCache.setFontRenderer(fontRenderer);
|
2011-06-03 18:50:11 -07:00
|
|
|
const ShadowTexture* shadow = mCaches.dropShadowCache.get(
|
|
|
|
paint, text, bytesCount, count, mShadowRadius);
|
2010-08-13 19:39:53 -07:00
|
|
|
const AutoTexture autoCleanup(shadow);
|
2010-08-16 20:26:20 -07:00
|
|
|
|
2011-04-26 15:33:10 -07:00
|
|
|
const float sx = oldX - shadow->left + mShadowDx;
|
|
|
|
const float sy = oldY - shadow->top + mShadowDy;
|
2010-12-14 15:55:39 -08:00
|
|
|
|
|
|
|
const int shadowAlpha = ((mShadowColor >> 24) & 0xFF);
|
2011-04-26 15:33:10 -07:00
|
|
|
int shadowColor = mShadowColor;
|
|
|
|
if (mShader) {
|
|
|
|
shadowColor = 0xffffffff;
|
|
|
|
}
|
2010-12-14 15:55:39 -08:00
|
|
|
|
|
|
|
setupDraw();
|
|
|
|
setupDrawWithTexture(true);
|
2011-04-26 15:33:10 -07:00
|
|
|
setupDrawAlpha8Color(shadowColor, shadowAlpha < 255 ? shadowAlpha : alpha);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
2010-12-14 15:55:39 -08:00
|
|
|
setupDrawBlending(true, mode);
|
|
|
|
setupDrawProgram();
|
2011-04-26 15:33:10 -07:00
|
|
|
setupDrawModelView(sx, sy, sx + shadow->width, sy + shadow->height);
|
2010-12-14 15:55:39 -08:00
|
|
|
setupDrawTexture(shadow->id);
|
|
|
|
setupDrawPureColorUniforms();
|
2011-04-26 15:33:10 -07:00
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawShaderUniforms();
|
2010-12-14 15:55:39 -08:00
|
|
|
setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
|
2010-08-16 20:26:20 -07:00
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
|
2010-08-13 19:39:53 -07:00
|
|
|
}
|
|
|
|
|
2010-12-06 18:07:02 -08:00
|
|
|
// Pick the appropriate texture filtering
|
|
|
|
bool linearFilter = mSnapshot->transform->changesBounds();
|
|
|
|
if (pureTranslate && !linearFilter) {
|
|
|
|
linearFilter = fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f;
|
|
|
|
}
|
2010-10-27 18:57:51 -07:00
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2010-12-14 15:55:39 -08:00
|
|
|
setupDraw();
|
|
|
|
setupDrawDirtyRegionsDisabled();
|
|
|
|
setupDrawWithTexture(true);
|
|
|
|
setupDrawAlpha8Color(paint->getColor(), alpha);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
|
|
|
setupDrawBlending(true, mode);
|
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawModelView(x, y, x, y, pureTranslate, true);
|
|
|
|
setupDrawTexture(fontRenderer.getTexture(linearFilter));
|
|
|
|
setupDrawPureColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawShaderUniforms(pureTranslate);
|
2010-07-30 19:18:16 -07:00
|
|
|
|
2010-12-06 18:07:02 -08:00
|
|
|
const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip();
|
2010-10-27 18:57:51 -07:00
|
|
|
Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f);
|
|
|
|
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
2012-02-01 16:10:55 -08:00
|
|
|
const bool hasActiveLayer = hasLayer();
|
2010-10-27 18:57:51 -07:00
|
|
|
#else
|
2012-02-01 16:10:55 -08:00
|
|
|
const bool hasActiveLayer = false;
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif
|
2011-02-17 16:45:37 -08:00
|
|
|
|
2010-12-06 18:07:02 -08:00
|
|
|
if (fontRenderer.renderText(paint, clip, text, 0, bytesCount, count, x, y,
|
2011-01-16 12:54:25 -08:00
|
|
|
hasActiveLayer ? &bounds : NULL)) {
|
2010-10-27 18:57:51 -07:00
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
2011-01-16 12:54:25 -08:00
|
|
|
if (hasActiveLayer) {
|
2010-12-06 18:07:02 -08:00
|
|
|
if (!pureTranslate) {
|
|
|
|
mSnapshot->transform->mapRect(bounds);
|
|
|
|
}
|
2011-01-16 12:54:25 -08:00
|
|
|
dirtyLayerUnchecked(bounds, getRegion());
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2010-12-06 18:47:50 -08:00
|
|
|
drawTextDecorations(text, bytesCount, length, oldX, oldY, paint);
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
2012-02-24 16:48:34 -08:00
|
|
|
void OpenGLRenderer::drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path,
|
|
|
|
float hOffset, float vOffset, SkPaint* paint) {
|
2012-02-24 17:54:07 -08:00
|
|
|
if (text == NULL || count == 0 || mSnapshot->isIgnored() ||
|
|
|
|
(paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
|
|
|
|
fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
|
|
|
|
paint->getTextSize());
|
|
|
|
|
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
|
|
|
mCaches.activeTexture(0);
|
|
|
|
setupDraw();
|
|
|
|
setupDrawDirtyRegionsDisabled();
|
|
|
|
setupDrawWithTexture(true);
|
|
|
|
setupDrawAlpha8Color(paint->getColor(), alpha);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
|
|
|
setupDrawBlending(true, mode);
|
|
|
|
setupDrawProgram();
|
2012-02-28 18:17:02 -08:00
|
|
|
setupDrawModelView(0.0f, 0.0f, 0.0f, 0.0f, false, true);
|
2012-02-24 17:54:07 -08:00
|
|
|
setupDrawTexture(fontRenderer.getTexture(true));
|
|
|
|
setupDrawPureColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
2012-02-28 18:17:02 -08:00
|
|
|
setupDrawShaderUniforms(false);
|
|
|
|
|
|
|
|
const Rect* clip = &mSnapshot->getLocalClip();
|
|
|
|
Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f);
|
2012-02-24 17:54:07 -08:00
|
|
|
|
2012-02-28 18:17:02 -08:00
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
const bool hasActiveLayer = hasLayer();
|
|
|
|
#else
|
|
|
|
const bool hasActiveLayer = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fontRenderer.renderTextOnPath(paint, clip, text, 0, bytesCount, count, path,
|
|
|
|
hOffset, vOffset, hasActiveLayer ? &bounds : NULL)) {
|
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
|
|
|
if (hasActiveLayer) {
|
|
|
|
mSnapshot->transform->mapRect(bounds);
|
|
|
|
dirtyLayerUnchecked(bounds, getRegion());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2012-02-24 16:48:34 -08:00
|
|
|
}
|
|
|
|
|
2010-08-04 15:40:07 -07:00
|
|
|
void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
|
2010-12-09 17:47:21 -08:00
|
|
|
if (mSnapshot->isIgnored()) return;
|
2010-10-11 17:58:29 -07:00
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2010-08-04 15:40:07 -07:00
|
|
|
|
2012-02-16 19:24:51 -08:00
|
|
|
// TODO: Perform early clip test before we rasterize the path
|
2010-08-23 21:05:08 -07:00
|
|
|
const PathTexture* texture = mCaches.pathCache.get(path, paint);
|
2010-08-07 23:46:15 -07:00
|
|
|
if (!texture) return;
|
2010-08-06 11:18:34 -07:00
|
|
|
const AutoTexture autoCleanup(texture);
|
2010-08-04 15:40:07 -07:00
|
|
|
|
2010-08-18 17:10:07 -07:00
|
|
|
const float x = texture->left - texture->offset;
|
|
|
|
const float y = texture->top - texture->offset;
|
|
|
|
|
2011-01-19 21:54:02 -08:00
|
|
|
drawPathTexture(texture, x, y, paint);
|
2010-08-04 15:40:07 -07:00
|
|
|
}
|
|
|
|
|
2011-01-13 12:13:20 -08:00
|
|
|
void OpenGLRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
|
|
|
|
if (!layer || quickReject(x, y, x + layer->layer.getWidth(), y + layer->layer.getHeight())) {
|
2011-01-11 14:29:25 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-02 13:37:47 -08:00
|
|
|
if (layer->deferredUpdateScheduled && layer->renderer && layer->displayList) {
|
|
|
|
OpenGLRenderer* renderer = layer->renderer;
|
|
|
|
Rect& dirty = layer->dirtyRect;
|
|
|
|
|
|
|
|
interrupt();
|
|
|
|
renderer->setViewport(layer->layer.getWidth(), layer->layer.getHeight());
|
|
|
|
renderer->prepareDirty(dirty.left, dirty.top, dirty.right, dirty.bottom, !layer->isBlend());
|
|
|
|
renderer->drawDisplayList(layer->displayList, layer->getWidth(), layer->getHeight(),
|
|
|
|
dirty, DisplayList::kReplayFlag_ClipChildren);
|
|
|
|
renderer->finish();
|
|
|
|
resume();
|
|
|
|
|
|
|
|
dirty.setEmpty();
|
|
|
|
layer->deferredUpdateScheduled = false;
|
|
|
|
layer->renderer = NULL;
|
|
|
|
layer->displayList = NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
mCaches.activeTexture(0);
|
2011-01-11 14:29:25 -08:00
|
|
|
|
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
layer->setAlpha(alpha, mode);
|
2011-01-11 14:29:25 -08:00
|
|
|
|
2011-01-16 12:54:25 -08:00
|
|
|
#if RENDER_LAYERS_AS_REGIONS
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(!layer->region.isEmpty())) {
|
2011-01-22 00:32:12 -08:00
|
|
|
if (layer->region.isRect()) {
|
2011-03-18 14:34:03 -07:00
|
|
|
composeLayerRect(layer, layer->regionRect);
|
2011-01-22 00:32:12 -08:00
|
|
|
} else if (layer->mesh) {
|
2011-01-24 20:40:18 -08:00
|
|
|
const float a = alpha / 255.0f;
|
2011-01-22 00:32:12 -08:00
|
|
|
const Rect& rect = layer->layer;
|
|
|
|
|
|
|
|
setupDraw();
|
|
|
|
setupDrawWithTexture();
|
2011-01-24 20:40:18 -08:00
|
|
|
setupDrawColor(a, a, a, a);
|
2011-01-22 00:32:12 -08:00
|
|
|
setupDrawColorFilter();
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawBlending(layer->isBlend() || a < 1.0f, layer->getMode(), false);
|
2011-01-22 00:32:12 -08:00
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawPureColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawTexture(layer->getTexture());
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(mSnapshot->transform->isPureTranslate())) {
|
2011-07-07 20:50:11 -07:00
|
|
|
x = (int) floorf(x + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
layer->setFilter(GL_NEAREST);
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawModelViewTranslate(x, y,
|
|
|
|
x + layer->layer.getWidth(), y + layer->layer.getHeight(), true);
|
|
|
|
} else {
|
2011-11-30 20:21:23 -08:00
|
|
|
layer->setFilter(GL_LINEAR);
|
2011-07-07 20:50:11 -07:00
|
|
|
setupDrawModelViewTranslate(x, y,
|
|
|
|
x + layer->layer.getWidth(), y + layer->layer.getHeight());
|
|
|
|
}
|
2011-01-22 00:32:12 -08:00
|
|
|
setupDrawMesh(&layer->mesh[0].position[0], &layer->mesh[0].texture[0]);
|
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLES, layer->meshElementCount,
|
|
|
|
GL_UNSIGNED_SHORT, layer->meshIndices);
|
|
|
|
|
|
|
|
finishDrawTexture();
|
2011-02-01 22:59:58 -08:00
|
|
|
|
|
|
|
#if DEBUG_LAYERS_AS_REGIONS
|
|
|
|
drawRegionRects(layer->region);
|
|
|
|
#endif
|
2011-01-22 00:32:12 -08:00
|
|
|
}
|
2011-01-16 12:54:25 -08:00
|
|
|
}
|
|
|
|
#else
|
2011-01-13 12:13:20 -08:00
|
|
|
const Rect r(x, y, x + layer->layer.getWidth(), y + layer->layer.getHeight());
|
|
|
|
composeLayerRect(layer, r);
|
2011-01-16 12:54:25 -08:00
|
|
|
#endif
|
2011-01-11 14:29:25 -08:00
|
|
|
}
|
|
|
|
|
2010-07-14 19:18:51 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Shaders
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OpenGLRenderer::resetShader() {
|
2010-07-30 19:18:16 -07:00
|
|
|
mShader = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupShader(SkiaShader* shader) {
|
|
|
|
mShader = shader;
|
|
|
|
if (mShader) {
|
2010-08-23 21:05:08 -07:00
|
|
|
mShader->set(&mCaches.textureCache, &mCaches.gradientCache);
|
2010-07-30 19:18:16 -07:00
|
|
|
}
|
2010-07-16 17:10:13 -07:00
|
|
|
}
|
|
|
|
|
2010-08-02 18:50:22 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Color filters
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OpenGLRenderer::resetColorFilter() {
|
|
|
|
mColorFilter = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupColorFilter(SkiaColorFilter* filter) {
|
|
|
|
mColorFilter = filter;
|
|
|
|
}
|
|
|
|
|
2010-08-13 19:39:53 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Drop shadow
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OpenGLRenderer::resetShadow() {
|
|
|
|
mHasShadow = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupShadow(float radius, float dx, float dy, int color) {
|
|
|
|
mHasShadow = true;
|
|
|
|
mShadowRadius = radius;
|
|
|
|
mShadowDx = dx;
|
|
|
|
mShadowDy = dy;
|
|
|
|
mShadowColor = color;
|
|
|
|
}
|
|
|
|
|
2012-01-23 17:09:05 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Draw filters
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OpenGLRenderer::resetPaintFilter() {
|
|
|
|
mHasDrawFilter = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::setupPaintFilter(int clearBits, int setBits) {
|
|
|
|
mHasDrawFilter = true;
|
|
|
|
mPaintFilterClearBits = clearBits & SkPaint::kAllFlags;
|
|
|
|
mPaintFilterSetBits = setBits & SkPaint::kAllFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint* OpenGLRenderer::filterPaint(SkPaint* paint) {
|
2012-03-01 12:08:38 -08:00
|
|
|
if (CC_LIKELY(!mHasDrawFilter || !paint)) return paint;
|
2012-01-23 17:09:05 -08:00
|
|
|
|
|
|
|
uint32_t flags = paint->getFlags();
|
|
|
|
|
|
|
|
mFilteredPaint = *paint;
|
|
|
|
mFilteredPaint.setFlags((flags & ~mPaintFilterClearBits) | mPaintFilterSetBits);
|
|
|
|
|
|
|
|
return &mFilteredPaint;
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:20:03 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Drawing implementation
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-01-19 21:54:02 -08:00
|
|
|
void OpenGLRenderer::drawPathTexture(const PathTexture* texture,
|
|
|
|
float x, float y, SkPaint* paint) {
|
|
|
|
if (quickReject(x, y, x + texture->width, y + texture->height)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
|
|
|
setupDraw();
|
|
|
|
setupDrawWithTexture(true);
|
|
|
|
setupDrawAlpha8Color(paint->getColor(), alpha);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawShader();
|
|
|
|
setupDrawBlending(true, mode);
|
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawModelView(x, y, x + texture->width, y + texture->height);
|
|
|
|
setupDrawTexture(texture->id);
|
|
|
|
setupDrawPureColorUniforms();
|
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawShaderUniforms();
|
|
|
|
setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
|
|
|
|
|
|
|
|
finishDrawTexture();
|
|
|
|
}
|
|
|
|
|
2010-09-10 19:20:06 -07:00
|
|
|
// Same values used by Skia
|
2010-08-16 20:26:20 -07:00
|
|
|
#define kStdStrikeThru_Offset (-6.0f / 21.0f)
|
|
|
|
#define kStdUnderline_Offset (1.0f / 9.0f)
|
|
|
|
#define kStdUnderline_Thickness (1.0f / 18.0f)
|
|
|
|
|
|
|
|
void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float length,
|
|
|
|
float x, float y, SkPaint* paint) {
|
|
|
|
// Handle underline and strike-through
|
|
|
|
uint32_t flags = paint->getFlags();
|
|
|
|
if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) {
|
2011-06-01 14:52:00 -07:00
|
|
|
SkPaint paintCopy(*paint);
|
2010-08-16 20:26:20 -07:00
|
|
|
float underlineWidth = length;
|
|
|
|
// If length is > 0.0f, we already measured the text for the text alignment
|
|
|
|
if (length <= 0.0f) {
|
2011-06-01 14:52:00 -07:00
|
|
|
underlineWidth = paintCopy.measureText(text, bytesCount);
|
2010-08-16 20:26:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
float offsetX = 0;
|
2011-06-01 14:52:00 -07:00
|
|
|
switch (paintCopy.getTextAlign()) {
|
2010-08-16 20:26:20 -07:00
|
|
|
case SkPaint::kCenter_Align:
|
|
|
|
offsetX = underlineWidth * 0.5f;
|
|
|
|
break;
|
|
|
|
case SkPaint::kRight_Align:
|
|
|
|
offsetX = underlineWidth;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(underlineWidth > 0.0f)) {
|
2011-06-01 14:52:00 -07:00
|
|
|
const float textSize = paintCopy.getTextSize();
|
2011-01-23 13:32:12 -08:00
|
|
|
const float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f);
|
2010-08-16 20:26:20 -07:00
|
|
|
|
2010-09-22 19:49:04 -07:00
|
|
|
const float left = x - offsetX;
|
2010-08-16 20:26:20 -07:00
|
|
|
float top = 0.0f;
|
2010-09-22 19:49:04 -07:00
|
|
|
|
2011-01-23 13:32:12 -08:00
|
|
|
int linesCount = 0;
|
|
|
|
if (flags & SkPaint::kUnderlineText_Flag) linesCount++;
|
|
|
|
if (flags & SkPaint::kStrikeThruText_Flag) linesCount++;
|
|
|
|
|
|
|
|
const int pointsCount = 4 * linesCount;
|
2010-09-22 19:49:04 -07:00
|
|
|
float points[pointsCount];
|
|
|
|
int currentPoint = 0;
|
2010-08-16 20:26:20 -07:00
|
|
|
|
|
|
|
if (flags & SkPaint::kUnderlineText_Flag) {
|
|
|
|
top = y + textSize * kStdUnderline_Offset;
|
2010-09-22 19:49:04 -07:00
|
|
|
points[currentPoint++] = left;
|
|
|
|
points[currentPoint++] = top;
|
|
|
|
points[currentPoint++] = left + underlineWidth;
|
|
|
|
points[currentPoint++] = top;
|
2010-08-16 20:26:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & SkPaint::kStrikeThruText_Flag) {
|
|
|
|
top = y + textSize * kStdStrikeThru_Offset;
|
2010-09-22 19:49:04 -07:00
|
|
|
points[currentPoint++] = left;
|
|
|
|
points[currentPoint++] = top;
|
|
|
|
points[currentPoint++] = left + underlineWidth;
|
|
|
|
points[currentPoint++] = top;
|
2010-08-16 20:26:20 -07:00
|
|
|
}
|
2010-09-22 19:49:04 -07:00
|
|
|
|
2011-06-01 14:52:00 -07:00
|
|
|
paintCopy.setStrokeWidth(strokeWidth);
|
2010-09-22 19:49:04 -07:00
|
|
|
|
2011-06-01 14:52:00 -07:00
|
|
|
drawLines(&points[0], pointsCount, &paintCopy);
|
2010-08-16 20:26:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-28 17:12:22 -07:00
|
|
|
void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom,
|
2010-09-13 18:00:09 -07:00
|
|
|
int color, SkXfermode::Mode mode, bool ignoreTransform) {
|
2010-07-14 19:18:51 -07:00
|
|
|
// If a shader is set, preserve only the alpha
|
2010-07-30 19:18:16 -07:00
|
|
|
if (mShader) {
|
2010-07-14 19:18:51 -07:00
|
|
|
color |= 0x00ffffff;
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
setupDraw();
|
2011-12-13 13:11:32 -08:00
|
|
|
setupDrawNoTexture();
|
2010-12-13 18:24:33 -08:00
|
|
|
setupDrawColor(color);
|
|
|
|
setupDrawShader();
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawBlending(mode);
|
|
|
|
setupDrawProgram();
|
|
|
|
setupDrawModelView(left, top, right, bottom, ignoreTransform);
|
|
|
|
setupDrawColorUniforms();
|
|
|
|
setupDrawShaderUniforms(ignoreTransform);
|
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawSimpleMesh();
|
2010-09-17 15:31:32 -07:00
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
|
|
|
|
}
|
|
|
|
|
2010-07-09 13:25:56 -07:00
|
|
|
void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
|
2010-10-25 18:03:28 -07:00
|
|
|
Texture* texture, SkPaint* paint) {
|
2010-07-09 13:25:56 -07:00
|
|
|
int alpha;
|
|
|
|
SkXfermode::Mode mode;
|
|
|
|
getAlphaAndMode(paint, &alpha, &mode);
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setWrap(GL_CLAMP_TO_EDGE, true);
|
2010-10-25 18:03:28 -07:00
|
|
|
|
2012-02-01 16:10:55 -08:00
|
|
|
if (CC_LIKELY(mSnapshot->transform->isPureTranslate())) {
|
2010-12-06 18:07:02 -08:00
|
|
|
const float x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
|
|
|
|
const float y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setFilter(GL_NEAREST, true);
|
2010-12-06 18:07:02 -08:00
|
|
|
drawTextureMesh(x, y, x + texture->width, y + texture->height, texture->id,
|
|
|
|
alpha / 255.0f, mode, texture->blend, (GLvoid*) NULL,
|
|
|
|
(GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount, false, true);
|
|
|
|
} else {
|
2011-11-30 20:21:23 -08:00
|
|
|
texture->setFilter(FILTER(paint), true);
|
2010-12-06 18:07:02 -08:00
|
|
|
drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode,
|
|
|
|
texture->blend, (GLvoid*) NULL, (GLvoid*) gMeshTextureOffset,
|
|
|
|
GL_TRIANGLE_STRIP, gMeshCount);
|
|
|
|
}
|
2010-06-22 13:11:24 -07:00
|
|
|
}
|
|
|
|
|
2010-06-26 00:13:53 -07:00
|
|
|
void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
|
2010-07-13 11:37:54 -07:00
|
|
|
GLuint texture, float alpha, SkXfermode::Mode mode, bool blend) {
|
|
|
|
drawTextureMesh(left, top, right, bottom, texture, alpha, mode, blend,
|
2010-10-18 14:06:08 -07:00
|
|
|
(GLvoid*) NULL, (GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount);
|
2010-07-08 19:17:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float bottom,
|
2010-07-13 11:37:54 -07:00
|
|
|
GLuint texture, float alpha, SkXfermode::Mode mode, bool blend,
|
2010-09-15 18:11:50 -07:00
|
|
|
GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
|
2010-10-27 18:57:51 -07:00
|
|
|
bool swapSrcDst, bool ignoreTransform, GLuint vbo, bool ignoreScale, bool dirty) {
|
2010-09-12 13:02:16 -07:00
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
setupDraw();
|
|
|
|
setupDrawWithTexture();
|
|
|
|
setupDrawColor(alpha, alpha, alpha, alpha);
|
|
|
|
setupDrawColorFilter();
|
|
|
|
setupDrawBlending(blend, mode, swapSrcDst);
|
|
|
|
setupDrawProgram();
|
|
|
|
if (!dirty) {
|
|
|
|
setupDrawDirtyRegionsDisabled();
|
2010-08-02 18:50:22 -07:00
|
|
|
}
|
2010-10-27 18:57:51 -07:00
|
|
|
if (!ignoreScale) {
|
2010-12-13 18:24:33 -08:00
|
|
|
setupDrawModelView(left, top, right, bottom, ignoreTransform);
|
2010-10-18 14:06:08 -07:00
|
|
|
} else {
|
2010-12-13 18:24:33 -08:00
|
|
|
setupDrawModelViewTranslate(left, top, right, bottom, ignoreTransform);
|
2010-08-02 18:50:22 -07:00
|
|
|
}
|
2010-12-14 15:55:39 -08:00
|
|
|
setupDrawPureColorUniforms();
|
2010-12-13 18:24:33 -08:00
|
|
|
setupDrawColorFilterUniforms();
|
|
|
|
setupDrawTexture(texture);
|
|
|
|
setupDrawMesh(vertices, texCoords, vbo);
|
2010-08-02 18:50:22 -07:00
|
|
|
|
2010-09-15 18:11:50 -07:00
|
|
|
glDrawArrays(drawMode, 0, elementsCount);
|
2010-12-13 18:24:33 -08:00
|
|
|
|
|
|
|
finishDrawTexture();
|
2010-07-09 13:25:56 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 14:42:43 -07:00
|
|
|
void OpenGLRenderer::chooseBlending(bool blend, SkXfermode::Mode mode,
|
2010-09-10 19:20:06 -07:00
|
|
|
ProgramDescription& description, bool swapSrcDst) {
|
2010-07-09 13:25:56 -07:00
|
|
|
blend = blend || mode != SkXfermode::kSrcOver_Mode;
|
|
|
|
if (blend) {
|
2012-01-03 14:13:39 -08:00
|
|
|
// These blend modes are not supported by OpenGL directly and have
|
|
|
|
// to be implemented using shaders. Since the shader will perform
|
|
|
|
// the blending, turn blending off here
|
|
|
|
// If the blend mode cannot be implemented using shaders, fall
|
|
|
|
// back to the default SrcOver blend mode instead
|
2012-02-01 16:10:55 -08:00
|
|
|
if CC_UNLIKELY((mode > SkXfermode::kScreen_Mode)) {
|
|
|
|
if (CC_UNLIKELY(mCaches.extensions.hasFramebufferFetch())) {
|
2010-09-09 14:42:43 -07:00
|
|
|
description.framebufferMode = mode;
|
2010-09-10 19:20:06 -07:00
|
|
|
description.swapSrcDst = swapSrcDst;
|
2010-09-09 14:42:43 -07:00
|
|
|
|
2012-01-03 14:13:39 -08:00
|
|
|
if (mCaches.blend) {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
mCaches.blend = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
mode = SkXfermode::kSrcOver_Mode;
|
2010-09-09 14:42:43 -07:00
|
|
|
}
|
2012-01-03 14:13:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCaches.blend) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum sourceMode = swapSrcDst ? gBlendsSwap[mode].src : gBlends[mode].src;
|
|
|
|
GLenum destMode = swapSrcDst ? gBlendsSwap[mode].dst : gBlends[mode].dst;
|
|
|
|
|
|
|
|
if (sourceMode != mCaches.lastSrcMode || destMode != mCaches.lastDstMode) {
|
|
|
|
glBlendFunc(sourceMode, destMode);
|
|
|
|
mCaches.lastSrcMode = sourceMode;
|
|
|
|
mCaches.lastDstMode = destMode;
|
2010-07-09 13:25:56 -07:00
|
|
|
}
|
2010-08-23 21:05:08 -07:00
|
|
|
} else if (mCaches.blend) {
|
2010-07-09 13:25:56 -07:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2010-08-23 21:05:08 -07:00
|
|
|
mCaches.blend = blend;
|
2010-06-26 00:13:53 -07:00
|
|
|
}
|
|
|
|
|
2010-07-29 14:37:42 -07:00
|
|
|
bool OpenGLRenderer::useProgram(Program* program) {
|
2010-07-14 19:18:51 -07:00
|
|
|
if (!program->isInUse()) {
|
2010-08-23 21:05:08 -07:00
|
|
|
if (mCaches.currentProgram != NULL) mCaches.currentProgram->remove();
|
2010-07-14 19:18:51 -07:00
|
|
|
program->use();
|
2010-08-23 21:05:08 -07:00
|
|
|
mCaches.currentProgram = program;
|
2010-07-12 20:20:03 -07:00
|
|
|
return false;
|
2010-07-12 14:41:06 -07:00
|
|
|
}
|
2010-07-12 20:20:03 -07:00
|
|
|
return true;
|
2010-07-12 14:41:06 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 17:12:22 -07:00
|
|
|
void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, float v2) {
|
2010-07-27 17:39:27 -07:00
|
|
|
TextureVertex* v = &mMeshVertices[0];
|
2010-07-09 13:25:56 -07:00
|
|
|
TextureVertex::setUV(v++, u1, v1);
|
|
|
|
TextureVertex::setUV(v++, u2, v1);
|
|
|
|
TextureVertex::setUV(v++, u1, v2);
|
|
|
|
TextureVertex::setUV(v++, u2, v2);
|
2010-06-30 19:21:21 -07:00
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void OpenGLRenderer::getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
|
2010-06-30 19:21:21 -07:00
|
|
|
if (paint) {
|
2011-09-08 15:33:03 -07:00
|
|
|
*mode = getXfermode(paint->getXfermode());
|
2010-06-30 19:21:21 -07:00
|
|
|
|
|
|
|
// Skia draws using the color's alpha channel if < 255
|
|
|
|
// Otherwise, it uses the paint's alpha
|
|
|
|
int color = paint->getColor();
|
|
|
|
*alpha = (color >> 24) & 0xFF;
|
|
|
|
if (*alpha == 255) {
|
|
|
|
*alpha = paint->getAlpha();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*mode = SkXfermode::kSrcOver_Mode;
|
|
|
|
*alpha = 255;
|
|
|
|
}
|
2010-06-28 17:12:22 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 14:42:43 -07:00
|
|
|
SkXfermode::Mode OpenGLRenderer::getXfermode(SkXfermode* mode) {
|
2011-05-16 13:09:42 -04:00
|
|
|
SkXfermode::Mode resultMode;
|
|
|
|
if (!SkXfermode::AsMode(mode, &resultMode)) {
|
|
|
|
resultMode = SkXfermode::kSrcOver_Mode;
|
2010-09-09 14:42:43 -07:00
|
|
|
}
|
2011-05-16 13:09:42 -04:00
|
|
|
return resultMode;
|
2010-09-09 14:42:43 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 19:30:36 -07:00
|
|
|
}; // namespace uirenderer
|
2010-06-16 18:44:05 -07:00
|
|
|
}; // namespace android
|