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-10-27 18:57:51 -07:00
|
|
|
#ifndef ANDROID_HWUI_OPENGL_RENDERER_H
|
|
|
|
#define ANDROID_HWUI_OPENGL_RENDERER_H
|
2010-06-24 19:30:36 -07:00
|
|
|
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
2010-06-22 13:11:24 -07:00
|
|
|
|
2010-06-29 21:05:21 -07:00
|
|
|
#include <SkBitmap.h>
|
2013-12-10 12:28:58 -05:00
|
|
|
#include <SkCanvas.h>
|
|
|
|
#include <SkColorFilter.h>
|
2010-06-23 17:47:49 -07:00
|
|
|
#include <SkMatrix.h>
|
2010-06-29 21:05:21 -07:00
|
|
|
#include <SkPaint.h>
|
2010-07-16 14:12:24 -07:00
|
|
|
#include <SkRegion.h>
|
2010-07-14 19:18:51 -07:00
|
|
|
#include <SkShader.h>
|
2010-06-22 13:11:24 -07:00
|
|
|
#include <SkXfermode.h>
|
2010-06-16 18:44:05 -07:00
|
|
|
|
2014-03-31 13:52:39 -04:00
|
|
|
#include <utils/Blur.h>
|
2011-01-10 14:10:36 -08:00
|
|
|
#include <utils/Functor.h>
|
2010-06-22 18:56:38 -07:00
|
|
|
#include <utils/RefBase.h>
|
2012-04-23 18:22:09 -07:00
|
|
|
#include <utils/SortedVector.h>
|
2010-09-12 13:02:16 -07:00
|
|
|
#include <utils/Vector.h>
|
2010-06-22 18:56:38 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
#include <cutils/compiler.h>
|
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
#include <androidfw/ResourceTypes.h>
|
|
|
|
|
2010-11-10 11:59:15 -08:00
|
|
|
#include "Debug.h"
|
2010-07-23 00:28:00 -07:00
|
|
|
#include "Extensions.h"
|
2010-06-23 17:47:49 -07:00
|
|
|
#include "Matrix.h"
|
2010-06-27 22:59:20 -07:00
|
|
|
#include "Program.h"
|
2010-06-22 18:56:38 -07:00
|
|
|
#include "Rect.h"
|
2013-12-26 15:13:13 -08:00
|
|
|
#include "Renderer.h"
|
2013-12-30 15:32:54 -08:00
|
|
|
#include "StatefulBaseRenderer.h"
|
2013-12-26 15:13:13 -08:00
|
|
|
#include "Snapshot.h"
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
#include "UvMapper.h"
|
2013-12-26 15:13:13 -08:00
|
|
|
#include "Vertex.h"
|
2010-08-23 21:05:08 -07:00
|
|
|
#include "Caches.h"
|
2014-05-01 21:27:37 -07:00
|
|
|
#include "CanvasProperty.h"
|
2010-06-22 18:56:38 -07:00
|
|
|
|
2010-06-16 18:44:05 -07:00
|
|
|
namespace android {
|
2010-06-24 19:30:36 -07:00
|
|
|
namespace uirenderer {
|
2010-06-16 18:44:05 -07:00
|
|
|
|
2013-12-26 15:13:13 -08:00
|
|
|
class DeferredDisplayState;
|
2014-03-12 13:56:30 -07:00
|
|
|
class RenderNode;
|
2013-12-26 15:13:13 -08:00
|
|
|
class TextSetupFunctor;
|
|
|
|
class VertexBuffer;
|
|
|
|
class SkiaShader;
|
|
|
|
|
2013-02-04 16:16:33 -08:00
|
|
|
struct DrawModifiers {
|
2013-08-09 14:06:29 -07:00
|
|
|
DrawModifiers() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
memset(this, 0, sizeof(DrawModifiers));
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:16:33 -08:00
|
|
|
SkiaShader* mShader;
|
2013-03-29 10:59:59 -07:00
|
|
|
float mOverrideLayerAlpha;
|
2013-02-04 16:16:33 -08:00
|
|
|
|
|
|
|
// Draw filters
|
|
|
|
bool mHasDrawFilter;
|
|
|
|
int mPaintFilterClearBits;
|
|
|
|
int mPaintFilterSetBits;
|
|
|
|
};
|
|
|
|
|
2013-03-08 13:12:16 -08:00
|
|
|
enum StateDeferFlags {
|
|
|
|
kStateDeferFlag_Draw = 0x1,
|
|
|
|
kStateDeferFlag_Clip = 0x2
|
|
|
|
};
|
|
|
|
|
2013-05-31 11:38:03 -07:00
|
|
|
enum ClipSideFlags {
|
2013-06-14 13:43:58 -07:00
|
|
|
kClipSide_None = 0x0,
|
2013-05-31 11:38:03 -07:00
|
|
|
kClipSide_Left = 0x1,
|
|
|
|
kClipSide_Top = 0x2,
|
|
|
|
kClipSide_Right = 0x4,
|
|
|
|
kClipSide_Bottom = 0x8,
|
2013-06-17 13:52:06 -07:00
|
|
|
kClipSide_Full = 0xF,
|
|
|
|
kClipSide_ConservativeFull = 0x1F
|
2013-05-31 11:38:03 -07:00
|
|
|
};
|
|
|
|
|
2013-11-15 16:06:56 -08:00
|
|
|
/**
|
|
|
|
* Defines additional transformation that should be applied by the model view matrix, beyond that of
|
|
|
|
* the currentTransform()
|
|
|
|
*/
|
|
|
|
enum ModelViewMode {
|
|
|
|
/**
|
|
|
|
* Used when the model view should simply translate geometry passed to the shader. The resulting
|
|
|
|
* matrix will be a simple translation.
|
|
|
|
*/
|
|
|
|
kModelViewMode_Translate = 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used when the model view should translate and scale geometry. The resulting matrix will be a
|
|
|
|
* translation + scale. This is frequently used together with VBO 0, the (0,0,1,1) rect.
|
|
|
|
*/
|
|
|
|
kModelViewMode_TranslateAndScale = 1,
|
|
|
|
};
|
|
|
|
|
2014-02-14 13:13:41 -08:00
|
|
|
enum VertexBufferMode {
|
|
|
|
kVertexBufferMode_Standard = 0,
|
2014-03-11 16:52:30 -07:00
|
|
|
kVertexBufferMode_OnePolyRingShadow = 1,
|
|
|
|
kVertexBufferMode_TwoPolyRingShadow = 2
|
2014-02-14 13:13:41 -08:00
|
|
|
};
|
|
|
|
|
2010-06-23 17:47:49 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Renderer
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-06-27 22:59:20 -07:00
|
|
|
/**
|
2013-12-30 15:32:54 -08:00
|
|
|
* OpenGL Renderer implementation.
|
2010-06-27 22:59:20 -07:00
|
|
|
*/
|
2013-12-30 15:32:54 -08:00
|
|
|
class OpenGLRenderer : public StatefulBaseRenderer {
|
2010-06-16 18:44:05 -07:00
|
|
|
public:
|
2011-10-12 13:48:51 -07:00
|
|
|
ANDROID_API OpenGLRenderer();
|
2010-09-24 18:39:22 -07:00
|
|
|
virtual ~OpenGLRenderer();
|
2010-06-16 18:44:05 -07:00
|
|
|
|
2012-09-24 11:37:12 -07:00
|
|
|
ANDROID_API void initProperties();
|
|
|
|
|
2010-09-28 19:09:36 -07:00
|
|
|
virtual void setViewport(int width, int height);
|
2012-10-18 15:05:02 -07:00
|
|
|
virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
|
2012-08-07 11:24:39 -07:00
|
|
|
virtual void finish();
|
2012-08-08 14:53:48 -07:00
|
|
|
virtual void interrupt();
|
|
|
|
virtual void resume();
|
|
|
|
|
2013-05-03 14:24:16 -07:00
|
|
|
ANDROID_API void setCountOverdrawEnabled(bool enabled) {
|
|
|
|
mCountOverdraw = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANDROID_API float getOverdraw() {
|
|
|
|
return mCountOverdraw ? mOverdraw : 0.0f;
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:33:45 -07:00
|
|
|
virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
|
2010-06-21 19:35:50 -07:00
|
|
|
|
2012-09-21 00:39:43 -07:00
|
|
|
ANDROID_API void pushLayerUpdate(Layer* layer);
|
2013-06-17 13:14:51 -07:00
|
|
|
ANDROID_API void cancelLayerUpdate(Layer* layer);
|
2012-09-21 00:39:43 -07:00
|
|
|
ANDROID_API void clearLayerUpdates();
|
2013-06-12 15:31:28 -07:00
|
|
|
ANDROID_API void flushLayerUpdates();
|
2012-09-21 00:39:43 -07:00
|
|
|
|
2014-02-05 16:47:00 -05:00
|
|
|
ANDROID_API virtual int saveLayer(float left, float top, float right, float bottom,
|
2014-04-15 16:18:08 -07:00
|
|
|
const SkPaint* paint, int flags) {
|
|
|
|
return saveLayer(left, top, right, bottom, paint, flags, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Specialized saveLayer implementation, which will pass the convexMask to an FBO layer, if
|
|
|
|
// created, which will in turn clip to that mask when drawn back/restored.
|
|
|
|
int saveLayer(float left, float top, float right, float bottom,
|
|
|
|
const SkPaint* paint, int flags, const SkPath* convexMask);
|
2010-06-26 00:13:53 -07:00
|
|
|
|
2013-03-19 15:03:48 -07:00
|
|
|
int saveLayerDeferred(float left, float top, float right, float bottom,
|
2014-02-05 16:47:00 -05:00
|
|
|
const SkPaint* paint, int flags);
|
2013-03-19 15:03:48 -07:00
|
|
|
|
2014-03-12 13:56:30 -07:00
|
|
|
virtual status_t drawDisplayList(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1);
|
2013-03-15 17:24:33 -07:00
|
|
|
virtual status_t drawLayer(Layer* layer, float x, float y);
|
2014-01-02 17:13:34 -08:00
|
|
|
virtual status_t drawBitmap(const SkBitmap* bitmap, float left, float top,
|
|
|
|
const SkPaint* paint);
|
|
|
|
status_t drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount,
|
|
|
|
TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint);
|
|
|
|
virtual status_t drawBitmap(const SkBitmap* bitmap, const SkMatrix* matrix,
|
|
|
|
const SkPaint* paint);
|
|
|
|
virtual status_t drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
|
2010-09-24 18:39:22 -07:00
|
|
|
float srcRight, float srcBottom, float dstLeft, float dstTop,
|
2014-01-02 17:13:34 -08:00
|
|
|
float dstRight, float dstBottom, const SkPaint* paint);
|
|
|
|
virtual status_t drawBitmapData(const SkBitmap* bitmap, float left, float top,
|
|
|
|
const SkPaint* paint);
|
|
|
|
virtual status_t drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
|
|
|
|
const float* vertices, const int* colors, const SkPaint* paint);
|
|
|
|
status_t drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
|
|
|
|
TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint);
|
|
|
|
virtual status_t drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
|
|
|
|
float left, float top, float right, float bottom, const SkPaint* paint);
|
|
|
|
status_t drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
|
|
|
|
float left, float top, float right, float bottom, const SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawColor(int color, SkXfermode::Mode mode);
|
2014-01-02 17:13:34 -08:00
|
|
|
virtual status_t drawRect(float left, float top, float right, float bottom,
|
|
|
|
const SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawRoundRect(float left, float top, float right, float bottom,
|
2014-01-02 17:13:34 -08:00
|
|
|
float rx, float ry, const SkPaint* paint);
|
|
|
|
virtual status_t drawCircle(float x, float y, float radius, const SkPaint* paint);
|
2014-05-01 21:27:37 -07:00
|
|
|
virtual status_t drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
|
|
|
|
CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) {
|
|
|
|
// TODO: Remove once android_view_GLES20Canvas uses DisplayListRenderer
|
|
|
|
// directly
|
|
|
|
return drawCircle(x->value, y->value, radius->value, &paint->value);
|
|
|
|
}
|
2014-01-02 17:13:34 -08:00
|
|
|
virtual status_t drawOval(float left, float top, float right, float bottom,
|
|
|
|
const SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawArc(float left, float top, float right, float bottom,
|
2014-01-02 17:13:34 -08:00
|
|
|
float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint);
|
|
|
|
virtual status_t drawPath(const SkPath* path, const SkPaint* paint);
|
|
|
|
virtual status_t drawLines(const float* points, int count, const SkPaint* paint);
|
|
|
|
virtual status_t drawPoints(const float* points, int count, const SkPaint* paint);
|
|
|
|
virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path,
|
|
|
|
float hOffset, float vOffset, const SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawPosText(const char* text, int bytesCount, int count,
|
2014-01-02 17:13:34 -08:00
|
|
|
const float* positions, const SkPaint* paint);
|
2012-07-27 16:41:22 -07:00
|
|
|
virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
|
2014-01-02 17:13:34 -08:00
|
|
|
const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds,
|
2013-03-04 10:19:31 -08:00
|
|
|
DrawOpMode drawOpMode = kDrawOpMode_Immediate);
|
2014-01-02 17:13:34 -08:00
|
|
|
virtual status_t drawRects(const float* rects, int count, const SkPaint* paint);
|
2010-06-22 13:11:24 -07:00
|
|
|
|
2014-03-11 12:20:17 -07:00
|
|
|
status_t drawShadow(const mat4& casterTransformXY, const mat4& casterTransformZ,
|
2014-03-26 13:19:14 -07:00
|
|
|
float casterAlpha, bool casterUnclipped, const SkPath* casterPerimeter);
|
2013-10-25 18:30:17 -07:00
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
virtual void resetShader();
|
|
|
|
virtual void setupShader(SkiaShader* shader);
|
2010-07-14 19:18:51 -07:00
|
|
|
|
2012-01-23 17:09:05 -08:00
|
|
|
virtual void resetPaintFilter();
|
|
|
|
virtual void setupPaintFilter(int clearBits, int setBits);
|
|
|
|
|
2013-03-29 10:59:59 -07:00
|
|
|
// If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer)
|
|
|
|
void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; }
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
const SkPaint* filterPaint(const SkPaint* paint);
|
2012-01-23 17:09:05 -08:00
|
|
|
|
2013-07-30 19:05:20 -07:00
|
|
|
/**
|
|
|
|
* Store the current display state (most importantly, the current clip and transform), and
|
|
|
|
* additionally map the state's bounds from local to window coordinates.
|
|
|
|
*
|
|
|
|
* Returns true if quick-rejected
|
|
|
|
*/
|
2013-03-08 13:12:16 -08:00
|
|
|
bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags);
|
2013-03-04 10:19:31 -08:00
|
|
|
void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false);
|
2013-05-31 11:38:03 -07:00
|
|
|
void setupMergedMultiDraw(const Rect* clipRect);
|
2013-02-04 16:16:33 -08:00
|
|
|
|
2013-03-19 15:03:48 -07:00
|
|
|
const DrawModifiers& getDrawModifiers() { return mDrawModifiers; }
|
|
|
|
void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; }
|
|
|
|
|
2013-01-04 19:05:13 -08:00
|
|
|
ANDROID_API bool isCurrentTransformSimple() {
|
2014-01-01 14:45:21 -08:00
|
|
|
return currentTransform()->isSimple();
|
2013-01-04 19:05:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-01 14:31:04 -08:00
|
|
|
Caches& getCaches() {
|
|
|
|
return mCaches;
|
|
|
|
}
|
|
|
|
|
2013-03-08 13:12:16 -08:00
|
|
|
// simple rect clip
|
|
|
|
bool isCurrentClipSimple() {
|
|
|
|
return mSnapshot->clipRegion->isEmpty();
|
|
|
|
}
|
|
|
|
|
2014-01-01 14:45:21 -08:00
|
|
|
int getViewportWidth() { return currentSnapshot()->viewport.getWidth(); }
|
|
|
|
int getViewportHeight() { return currentSnapshot()->viewport.getHeight(); }
|
2013-06-19 16:54:59 -07:00
|
|
|
|
2012-08-07 11:24:39 -07:00
|
|
|
/**
|
2013-03-15 17:24:33 -07:00
|
|
|
* Scales the alpha on the current snapshot. This alpha value will be modulated
|
2012-08-07 11:24:39 -07:00
|
|
|
* with other alpha values when drawing primitives.
|
|
|
|
*/
|
2013-03-15 17:24:33 -07:00
|
|
|
void scaleAlpha(float alpha) {
|
|
|
|
mSnapshot->alpha *= alpha;
|
2012-08-07 11:24:39 -07:00
|
|
|
}
|
|
|
|
|
2013-03-01 14:31:04 -08:00
|
|
|
/**
|
|
|
|
* Inserts a named event marker in the stream of GL commands.
|
|
|
|
*/
|
|
|
|
void eventMark(const char* name) const;
|
|
|
|
|
2012-08-07 11:24:39 -07:00
|
|
|
/**
|
|
|
|
* Inserts a named group marker in the stream of GL commands. This marker
|
|
|
|
* can be used by tools to group commands into logical groups. A call to
|
|
|
|
* this method must always be followed later on by a call to endMark().
|
|
|
|
*/
|
2012-01-30 17:41:55 -08:00
|
|
|
void startMark(const char* name) const;
|
2012-08-07 11:24:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the last group marker opened by startMark().
|
|
|
|
*/
|
2012-01-30 17:41:55 -08:00
|
|
|
void endMark() const;
|
|
|
|
|
2012-09-05 11:40:29 -07:00
|
|
|
/**
|
|
|
|
* Gets the alpha and xfermode out of a paint object. If the paint is null
|
|
|
|
* alpha will be 255 and the xfermode will be SRC_OVER. This method does
|
2013-03-29 10:59:59 -07:00
|
|
|
* not multiply the paint's alpha by the current snapshot's alpha, and does
|
|
|
|
* not replace the alpha with the overrideLayerAlpha
|
2012-09-05 11:40:29 -07:00
|
|
|
*
|
|
|
|
* @param paint The paint to extract values from
|
|
|
|
* @param alpha Where to store the resulting alpha
|
|
|
|
* @param mode Where to store the resulting xfermode
|
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
|
2013-03-04 10:19:31 -08:00
|
|
|
*mode = getXfermodeDirect(paint);
|
|
|
|
*alpha = getAlphaDirect(paint);
|
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) {
|
2013-03-04 10:19:31 -08:00
|
|
|
if (!paint) return SkXfermode::kSrcOver_Mode;
|
|
|
|
return getXfermode(paint->getXfermode());
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:23:37 -07:00
|
|
|
static inline int getAlphaDirect(const SkPaint* paint) {
|
2013-03-04 10:19:31 -08:00
|
|
|
if (!paint) return 255;
|
|
|
|
return paint->getAlpha();
|
2012-09-05 11:40:29 -07:00
|
|
|
}
|
|
|
|
|
2014-03-31 13:52:39 -04:00
|
|
|
struct TextShadow {
|
|
|
|
SkScalar radius;
|
|
|
|
float dx;
|
|
|
|
float dy;
|
|
|
|
SkColor color;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool getTextShadow(const SkPaint* paint, TextShadow* textShadow) {
|
|
|
|
SkDrawLooper::BlurShadowRec blur;
|
|
|
|
if (paint && paint->getLooper() && paint->getLooper()->asABlurShadow(&blur)) {
|
|
|
|
if (textShadow) {
|
|
|
|
textShadow->radius = Blur::convertSigmaToRadius(blur.fSigma);
|
|
|
|
textShadow->dx = blur.fOffset.fX;
|
|
|
|
textShadow->dy = blur.fOffset.fY;
|
|
|
|
textShadow->color = blur.fColor;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool hasTextShadow(const SkPaint* paint) {
|
|
|
|
return getTextShadow(paint, NULL);
|
|
|
|
}
|
|
|
|
|
2013-03-05 16:43:31 -08:00
|
|
|
/**
|
|
|
|
* Return the best transform to use to rasterize text given a full
|
|
|
|
* transform matrix.
|
|
|
|
*/
|
|
|
|
mat4 findBestFontTransform(const mat4& transform) const;
|
|
|
|
|
2013-03-04 10:19:31 -08:00
|
|
|
#if DEBUG_MERGE_BEHAVIOR
|
|
|
|
void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) {
|
|
|
|
mCaches.setScissorEnabled(false);
|
|
|
|
|
|
|
|
// should only be called outside of other draw ops, so stencil can only be in test state
|
|
|
|
bool stencilWasEnabled = mCaches.stencil.isTestEnabled();
|
|
|
|
mCaches.stencil.disable();
|
|
|
|
|
|
|
|
drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true);
|
|
|
|
|
|
|
|
if (stencilWasEnabled) mCaches.stencil.enableTest();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-24 18:39:22 -07:00
|
|
|
protected:
|
2012-09-18 15:40:58 -07:00
|
|
|
/**
|
|
|
|
* Computes the projection matrix, initialize the first snapshot
|
|
|
|
* and stores the dimensions of the render target.
|
|
|
|
*/
|
|
|
|
void initViewport(int width, int height);
|
|
|
|
|
2013-03-26 15:05:58 -07:00
|
|
|
/**
|
|
|
|
* Perform the setup specific to a frame. This method does not
|
|
|
|
* issue any OpenGL commands.
|
|
|
|
*/
|
|
|
|
void setupFrameState(float left, float top, float right, float bottom, bool opaque);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates the start of rendering. This method will setup the
|
|
|
|
* initial OpenGL state (viewport, clearing the buffer, etc.)
|
|
|
|
*/
|
|
|
|
status_t startFrame();
|
|
|
|
|
2012-10-18 15:05:02 -07:00
|
|
|
/**
|
|
|
|
* Clears the underlying surface if needed.
|
|
|
|
*/
|
|
|
|
virtual status_t clear(float left, float top, float right, float bottom, bool opaque);
|
|
|
|
|
2012-09-18 15:40:58 -07:00
|
|
|
/**
|
|
|
|
* Call this method after updating a layer during a drawing pass.
|
|
|
|
*/
|
|
|
|
void resumeAfterLayer();
|
|
|
|
|
2013-01-15 18:51:42 -08:00
|
|
|
/**
|
|
|
|
* This method is called whenever a stencil buffer is required. Subclasses
|
|
|
|
* should override this method and call attachStencilBufferToLayer() on the
|
|
|
|
* appropriate layer(s).
|
|
|
|
*/
|
|
|
|
virtual void ensureStencilBuffer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains a stencil render buffer (allocating it if necessary) and
|
|
|
|
* attaches it to the specified layer.
|
|
|
|
*/
|
|
|
|
void attachStencilBufferToLayer(Layer* layer);
|
|
|
|
|
2013-11-19 18:00:46 -08:00
|
|
|
bool quickRejectSetupScissor(float left, float top, float right, float bottom,
|
2014-01-02 17:13:34 -08:00
|
|
|
const SkPaint* paint = NULL);
|
|
|
|
bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = NULL) {
|
2013-11-19 18:00:46 -08:00
|
|
|
return quickRejectSetupScissor(bounds.left, bounds.top,
|
|
|
|
bounds.right, bounds.bottom, paint);
|
|
|
|
}
|
|
|
|
|
2010-09-24 18:39:22 -07:00
|
|
|
/**
|
|
|
|
* Compose the layer defined in the current snapshot with the layer
|
|
|
|
* defined by the previous snapshot.
|
|
|
|
*
|
|
|
|
* The current snapshot *must* be a layer (flag kFlagIsLayer set.)
|
|
|
|
*
|
|
|
|
* @param curent The current snapshot containing the layer to compose
|
|
|
|
* @param previous The previous snapshot to compose the current layer with
|
|
|
|
*/
|
2013-12-30 15:32:54 -08:00
|
|
|
virtual void composeLayer(const Snapshot& current, const Snapshot& previous);
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2011-01-13 12:13:20 -08:00
|
|
|
/**
|
2011-01-16 12:54:25 -08:00
|
|
|
* Marks the specified region as dirty at the specified bounds.
|
2011-01-13 12:13:20 -08:00
|
|
|
*/
|
2011-01-16 12:54:25 -08:00
|
|
|
void dirtyLayerUnchecked(Rect& bounds, Region* region);
|
2011-01-13 12:13:20 -08:00
|
|
|
|
2011-01-19 13:42:26 -08:00
|
|
|
/**
|
|
|
|
* Returns the region of the current layer.
|
|
|
|
*/
|
2013-03-05 16:43:31 -08:00
|
|
|
virtual Region* getRegion() const {
|
2011-01-16 12:54:25 -08:00
|
|
|
return mSnapshot->region;
|
|
|
|
}
|
|
|
|
|
2011-01-19 13:42:26 -08:00
|
|
|
/**
|
|
|
|
* Indicates whether rendering is currently targeted at a layer.
|
|
|
|
*/
|
2013-03-05 16:43:31 -08:00
|
|
|
virtual bool hasLayer() const {
|
2011-01-16 12:54:25 -08:00
|
|
|
return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
|
|
|
|
}
|
2011-01-14 20:07:20 -08:00
|
|
|
|
2011-01-19 13:42:26 -08:00
|
|
|
/**
|
|
|
|
* Returns the name of the FBO this renderer is rendering into.
|
|
|
|
*/
|
2013-12-30 15:32:54 -08:00
|
|
|
virtual GLuint getTargetFbo() const {
|
2011-01-19 13:42:26 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-14 16:45:55 -07:00
|
|
|
/**
|
|
|
|
* Renders the specified layer as a textured quad.
|
|
|
|
*
|
|
|
|
* @param layer The layer to render
|
|
|
|
* @param rect The bounds of the layer
|
|
|
|
*/
|
|
|
|
void drawTextureLayer(Layer* layer, const Rect& rect);
|
|
|
|
|
2012-07-16 12:41:17 -07:00
|
|
|
/**
|
|
|
|
* Gets the alpha and xfermode out of a paint object. If the paint is null
|
2013-03-29 10:59:59 -07:00
|
|
|
* alpha will be 255 and the xfermode will be SRC_OVER. Accounts for both
|
|
|
|
* snapshot alpha, and overrideLayerAlpha
|
2012-07-16 12:41:17 -07:00
|
|
|
*
|
|
|
|
* @param paint The paint to extract values from
|
|
|
|
* @param alpha Where to store the resulting alpha
|
|
|
|
* @param mode Where to store the resulting xfermode
|
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const;
|
2013-03-29 10:59:59 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the alpha from a layer, accounting for snapshot alpha and overrideLayerAlpha
|
|
|
|
*
|
|
|
|
* @param layer The layer from which the alpha is extracted
|
|
|
|
*/
|
2013-12-10 12:28:58 -05:00
|
|
|
inline float getLayerAlpha(const Layer* layer) const;
|
2012-07-16 12:41:17 -07:00
|
|
|
|
|
|
|
/**
|
2013-12-10 12:28:58 -05:00
|
|
|
* Safely retrieves the ColorFilter from the given Paint. If the paint is
|
|
|
|
* null then null is returned.
|
2012-07-16 12:41:17 -07:00
|
|
|
*/
|
2013-12-10 12:28:58 -05:00
|
|
|
static inline SkColorFilter* getColorFilter(const SkPaint* paint) {
|
|
|
|
return paint ? paint->getColorFilter() : NULL;
|
2012-07-16 12:41:17 -07:00
|
|
|
}
|
|
|
|
|
2012-09-21 00:39:43 -07:00
|
|
|
/**
|
|
|
|
* Set to true to suppress error checks at the end of a frame.
|
|
|
|
*/
|
2013-03-05 16:43:31 -08:00
|
|
|
virtual bool suppressErrorChecks() const {
|
2012-09-21 00:39:43 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-21 19:35:50 -07:00
|
|
|
private:
|
2013-01-03 13:08:57 -08:00
|
|
|
/**
|
|
|
|
* Discards the content of the framebuffer if supported by the driver.
|
|
|
|
* This method should be called at the beginning of a frame to optimize
|
|
|
|
* rendering on some tiler architectures.
|
|
|
|
*/
|
|
|
|
void discardFramebuffer(float left, float top, float right, float bottom);
|
|
|
|
|
2012-05-22 14:07:07 -07:00
|
|
|
/**
|
|
|
|
* Ensures the state of the renderer is the same as the state of
|
|
|
|
* the GL context.
|
|
|
|
*/
|
|
|
|
void syncState();
|
|
|
|
|
2012-09-19 17:25:38 -07:00
|
|
|
/**
|
|
|
|
* Tells the GPU what part of the screen is about to be redrawn.
|
2014-01-01 14:45:21 -08:00
|
|
|
* This method will use the current layer space clip rect.
|
2012-09-19 17:25:38 -07:00
|
|
|
* This method needs to be invoked every time getTargetFbo() is
|
|
|
|
* bound again.
|
|
|
|
*/
|
2014-01-01 14:45:21 -08:00
|
|
|
void startTilingCurrentClip(bool opaque = false);
|
2012-09-19 17:25:38 -07:00
|
|
|
|
2013-01-29 17:26:25 -08:00
|
|
|
/**
|
|
|
|
* Tells the GPU what part of the screen is about to be redrawn.
|
|
|
|
* This method needs to be invoked every time getTargetFbo() is
|
|
|
|
* bound again.
|
|
|
|
*/
|
|
|
|
void startTiling(const Rect& clip, int windowHeight, bool opaque = false);
|
|
|
|
|
2012-09-19 17:25:38 -07:00
|
|
|
/**
|
|
|
|
* Tells the GPU that we are done drawing the frame or that we
|
|
|
|
* are switching to another render target.
|
|
|
|
*/
|
|
|
|
void endTiling();
|
|
|
|
|
2013-12-30 15:32:54 -08:00
|
|
|
void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored);
|
2010-06-22 18:56:38 -07:00
|
|
|
|
2010-06-27 22:59:20 -07:00
|
|
|
/**
|
|
|
|
* Sets the clipping rectangle using glScissor. The clip is defined by
|
|
|
|
* the current snapshot's clipRect member.
|
|
|
|
*/
|
2010-06-22 18:56:38 -07:00
|
|
|
void setScissorFromClip();
|
|
|
|
|
2013-01-15 18:51:42 -08:00
|
|
|
/**
|
|
|
|
* Sets the clipping region using the stencil buffer. The clip region
|
|
|
|
* is defined by the current snapshot's clipRegion member.
|
|
|
|
*/
|
|
|
|
void setStencilFromClip();
|
|
|
|
|
2013-03-19 15:03:48 -07:00
|
|
|
/**
|
2013-03-26 18:55:15 -07:00
|
|
|
* Given the local bounds of the layer, calculates ...
|
2013-03-19 15:03:48 -07:00
|
|
|
*/
|
|
|
|
void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer);
|
|
|
|
|
2013-03-26 18:55:15 -07:00
|
|
|
/**
|
|
|
|
* Given the local bounds + clip of the layer, updates current snapshot's empty/invisible
|
|
|
|
*/
|
|
|
|
void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip,
|
|
|
|
bool fboLayer, int alpha);
|
|
|
|
|
2010-06-28 17:42:46 -07:00
|
|
|
/**
|
|
|
|
* Creates a new layer stored in the specified snapshot.
|
|
|
|
*
|
|
|
|
* @param snapshot The snapshot associated with the new layer
|
|
|
|
* @param left The left coordinate of the layer
|
|
|
|
* @param top The top coordinate of the layer
|
|
|
|
* @param right The right coordinate of the layer
|
|
|
|
* @param bottom The bottom coordinate of the layer
|
|
|
|
* @param alpha The translucency of the layer
|
|
|
|
* @param mode The blending mode of the layer
|
|
|
|
* @param flags The layer save flags
|
2014-04-15 16:18:08 -07:00
|
|
|
* @param mask A mask to use when drawing the layer back, may be empty
|
2010-06-28 17:42:46 -07:00
|
|
|
*
|
|
|
|
* @return True if the layer was successfully created, false otherwise
|
|
|
|
*/
|
2012-08-28 17:43:28 -07:00
|
|
|
bool createLayer(float left, float top, float right, float bottom,
|
2014-04-15 16:18:08 -07:00
|
|
|
const SkPaint* paint, int flags, const SkPath* convexMask);
|
2010-06-28 17:42:46 -07:00
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
/**
|
|
|
|
* Creates a new layer stored in the specified snapshot as an FBO.
|
|
|
|
*
|
|
|
|
* @param layer The layer to store as an FBO
|
|
|
|
* @param snapshot The snapshot associated with the new layer
|
|
|
|
* @param bounds The bounds of the layer
|
|
|
|
*/
|
2013-10-17 10:30:55 -07:00
|
|
|
bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip);
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compose the specified layer as a region.
|
|
|
|
*
|
|
|
|
* @param layer The layer to compose
|
|
|
|
* @param rect The layer's bounds
|
|
|
|
*/
|
|
|
|
void composeLayerRegion(Layer* layer, const Rect& rect);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compose the specified layer as a simple rectangle.
|
|
|
|
*
|
|
|
|
* @param layer The layer to compose
|
|
|
|
* @param rect The layer's bounds
|
|
|
|
* @param swap If true, the source and destination are swapped
|
|
|
|
*/
|
|
|
|
void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
|
|
|
|
|
2011-06-13 19:04:27 -07:00
|
|
|
/**
|
|
|
|
* Clears all the regions corresponding to the current list of layers.
|
|
|
|
* This method MUST be invoked before any drawing operation.
|
|
|
|
*/
|
|
|
|
void clearLayerRegions();
|
|
|
|
|
2011-01-16 12:54:25 -08:00
|
|
|
/**
|
|
|
|
* Mark the layer as dirty at the specified coordinates. The coordinates
|
|
|
|
* are transformed with the supplied matrix.
|
|
|
|
*/
|
|
|
|
void dirtyLayer(const float left, const float top,
|
|
|
|
const float right, const float bottom, const mat4 transform);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the layer as dirty at the specified coordinates.
|
|
|
|
*/
|
|
|
|
void dirtyLayer(const float left, const float top,
|
|
|
|
const float right, const float bottom);
|
|
|
|
|
2010-06-27 22:59:20 -07:00
|
|
|
/**
|
|
|
|
* Draws a colored rectangle with the specified color. The specified coordinates
|
2012-12-03 12:34:51 -08:00
|
|
|
* are transformed by the current snapshot's transform matrix unless specified
|
|
|
|
* otherwise.
|
2010-06-27 22:59:20 -07:00
|
|
|
*
|
|
|
|
* @param left The left coordinate of the rectangle
|
|
|
|
* @param top The top coordinate of the rectangle
|
|
|
|
* @param right The right coordinate of the rectangle
|
|
|
|
* @param bottom The bottom coordinate of the rectangle
|
2013-12-10 12:28:58 -05:00
|
|
|
* @param paint The paint containing the color, blending mode, etc.
|
2010-07-14 16:34:53 -07:00
|
|
|
* @param ignoreTransform True if the current transform should be ignored
|
2010-06-27 22:59:20 -07:00
|
|
|
*/
|
2010-06-28 17:12:22 -07:00
|
|
|
void drawColorRect(float left, float top, float right, float bottom,
|
2013-12-10 12:28:58 -05:00
|
|
|
const SkPaint* paint, bool ignoreTransform = false);
|
2010-06-27 22:59:20 -07:00
|
|
|
|
2012-12-03 12:34:51 -08:00
|
|
|
/**
|
|
|
|
* Draws a series of colored rectangles with the specified color. The specified
|
|
|
|
* coordinates are transformed by the current snapshot's transform matrix unless
|
|
|
|
* specified otherwise.
|
|
|
|
*
|
|
|
|
* @param rects A list of rectangles, 4 floats (left, top, right, bottom)
|
|
|
|
* per rectangle
|
2013-12-10 12:28:58 -05:00
|
|
|
* @param paint The paint containing the color, blending mode, etc.
|
2012-12-03 12:34:51 -08:00
|
|
|
* @param ignoreTransform True if the current transform should be ignored
|
2013-01-15 18:51:42 -08:00
|
|
|
* @param dirty True if calling this method should dirty the current layer
|
2013-02-06 16:51:04 -08:00
|
|
|
* @param clip True if the rects should be clipped, false otherwise
|
2012-12-03 12:34:51 -08:00
|
|
|
*/
|
2013-12-10 12:28:58 -05:00
|
|
|
status_t drawColorRects(const float* rects, int count, const SkPaint* paint,
|
|
|
|
bool ignoreTransform = false, bool dirty = true, bool clip = true);
|
2012-12-03 12:34:51 -08:00
|
|
|
|
2011-06-13 19:04:27 -07:00
|
|
|
/**
|
|
|
|
* Draws the shape represented by the specified path texture.
|
|
|
|
* This method invokes drawPathTexture() but takes into account
|
|
|
|
* the extra left/top offset and the texture offset to correctly
|
|
|
|
* position the final shape.
|
|
|
|
*
|
|
|
|
* @param left The left coordinate of the shape to render
|
|
|
|
* @param top The top coordinate of the shape to render
|
|
|
|
* @param texture The texture reprsenting the shape
|
|
|
|
* @param paint The paint to draw the shape with
|
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint);
|
2011-06-13 19:04:27 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
|
|
|
|
* different compositing rules.
|
|
|
|
*
|
|
|
|
* @param texture The texture to draw with
|
|
|
|
* @param left The x coordinate of the bitmap
|
|
|
|
* @param top The y coordinate of the bitmap
|
|
|
|
* @param paint The paint to render with
|
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
void drawAlphaBitmap(Texture* texture, float left, float top, const SkPaint* paint);
|
2011-03-18 16:50:13 -07:00
|
|
|
|
2012-12-10 17:56:27 -08:00
|
|
|
/**
|
|
|
|
* Renders a strip of polygons with the specified paint, used for tessellated geometry.
|
|
|
|
*
|
|
|
|
* @param vertexBuffer The VertexBuffer to be drawn
|
|
|
|
* @param paint The paint to render with
|
|
|
|
* @param useOffset Offset the vertexBuffer (used in drawing non-AA lines)
|
|
|
|
*/
|
2014-02-14 13:13:41 -08:00
|
|
|
status_t drawVertexBuffer(VertexBufferMode mode, const VertexBuffer& vertexBuffer,
|
|
|
|
const SkPaint* paint, bool useOffset = false);
|
2012-12-10 17:56:27 -08:00
|
|
|
|
2011-06-13 19:04:27 -07:00
|
|
|
/**
|
2012-09-17 17:25:49 -07:00
|
|
|
* Renders the convex hull defined by the specified path as a strip of polygons.
|
2011-06-13 19:04:27 -07:00
|
|
|
*
|
2012-09-17 17:25:49 -07:00
|
|
|
* @param path The hull of the path to draw
|
2012-09-25 12:00:29 -07:00
|
|
|
* @param paint The paint to render with
|
2011-06-13 19:04:27 -07:00
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t drawConvexPath(const SkPath& path, const SkPaint* paint);
|
2011-05-12 09:06:00 -07:00
|
|
|
|
2010-07-08 19:17:03 -07:00
|
|
|
/**
|
2010-07-09 13:25:56 -07:00
|
|
|
* Draws a textured rectangle with the specified texture. The specified coordinates
|
|
|
|
* are transformed by the current snapshot's transform matrix.
|
|
|
|
*
|
|
|
|
* @param left The left coordinate of the rectangle
|
|
|
|
* @param top The top coordinate of the rectangle
|
|
|
|
* @param right The right coordinate of the rectangle
|
|
|
|
* @param bottom The bottom coordinate of the rectangle
|
|
|
|
* @param texture The texture to use
|
|
|
|
* @param paint The paint containing the alpha, blending mode, etc.
|
|
|
|
*/
|
2010-07-13 11:37:54 -07:00
|
|
|
void drawTextureRect(float left, float top, float right, float bottom,
|
2014-01-02 17:13:34 -08:00
|
|
|
Texture* texture, const SkPaint* paint);
|
2010-07-09 13:25:56 -07:00
|
|
|
|
|
|
|
/**
|
2010-10-18 14:06:08 -07:00
|
|
|
* Draws a textured mesh with the specified texture. If the indices are omitted,
|
|
|
|
* the mesh is drawn as a simple quad. The mesh pointers become offsets when a
|
|
|
|
* VBO is bound.
|
2010-07-09 13:25:56 -07:00
|
|
|
*
|
|
|
|
* @param left The left coordinate of the rectangle
|
|
|
|
* @param top The top coordinate of the rectangle
|
|
|
|
* @param right The right coordinate of the rectangle
|
|
|
|
* @param bottom The bottom coordinate of the rectangle
|
|
|
|
* @param texture The texture name to map onto the rectangle
|
2013-12-10 12:28:58 -05:00
|
|
|
* @param paint The paint containing the alpha, blending mode, colorFilter, etc.
|
2010-07-09 13:25:56 -07:00
|
|
|
* @param blend True if the texture contains an alpha channel
|
|
|
|
* @param vertices The vertices that define the mesh
|
|
|
|
* @param texCoords The texture coordinates of each vertex
|
|
|
|
* @param elementsCount The number of elements in the mesh, required by indices
|
2010-09-10 19:20:06 -07:00
|
|
|
* @param swapSrcDst Whether or not the src and dst blending operations should be swapped
|
|
|
|
* @param ignoreTransform True if the current transform should be ignored
|
2010-10-18 14:06:08 -07:00
|
|
|
* @param vbo The VBO used to draw the mesh
|
2013-11-15 16:06:56 -08:00
|
|
|
* @param modelViewMode Defines whether the model view matrix should be scaled
|
2010-10-27 18:57:51 -07:00
|
|
|
* @param dirty True if calling this method should dirty the current layer
|
2010-07-08 19:17:03 -07:00
|
|
|
*/
|
|
|
|
void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
|
2013-12-10 12:28:58 -05:00
|
|
|
const SkPaint* paint, 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 = false, bool ignoreTransform = false, GLuint vbo = 0,
|
2013-11-15 16:06:56 -08:00
|
|
|
ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true);
|
2010-07-08 19:17:03 -07:00
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
void drawIndexedTextureMesh(float left, float top, float right, float bottom, GLuint texture,
|
2013-12-10 12:28:58 -05:00
|
|
|
const SkPaint* paint, bool blend,
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
|
|
|
|
bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
|
2013-11-15 16:06:56 -08:00
|
|
|
ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true);
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
|
2013-01-04 12:26:18 -08:00
|
|
|
void drawAlpha8TextureMesh(float left, float top, float right, float bottom,
|
2013-12-10 12:28:58 -05:00
|
|
|
GLuint texture, const SkPaint* paint,
|
2013-01-04 12:26:18 -08:00
|
|
|
GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
|
2013-11-15 16:06:56 -08:00
|
|
|
bool ignoreTransform, ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale,
|
|
|
|
bool dirty = true);
|
2013-01-04 12:26:18 -08:00
|
|
|
|
2013-07-22 13:57:50 -07:00
|
|
|
/**
|
|
|
|
* Draws the specified list of vertices as quads using indexed GL_TRIANGLES.
|
|
|
|
* If the number of vertices to draw exceeds the number of indices we have
|
|
|
|
* pre-allocated, this method will generate several glDrawElements() calls.
|
|
|
|
*/
|
2013-11-15 16:06:56 -08:00
|
|
|
void issueIndexedQuadDraw(Vertex* mesh, GLsizei quadsCount);
|
2013-07-22 13:57:50 -07:00
|
|
|
|
2010-08-16 20:26:20 -07:00
|
|
|
/**
|
|
|
|
* Draws text underline and strike-through if needed.
|
|
|
|
*
|
|
|
|
* @param text The text to decor
|
|
|
|
* @param bytesCount The number of bytes in the text
|
2013-05-03 16:35:54 -07:00
|
|
|
* @param totalAdvance The total advance in pixels, defines underline/strikethrough length
|
2010-08-16 20:26:20 -07:00
|
|
|
* @param x The x coordinate where the text will be drawn
|
|
|
|
* @param y The y coordinate where the text will be drawn
|
|
|
|
* @param paint The paint to draw the text with
|
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
void drawTextDecorations(float totalAdvance, float x, float y, const SkPaint* paint);
|
2010-08-13 19:39:53 -07:00
|
|
|
|
2012-07-19 22:48:17 -07:00
|
|
|
/**
|
|
|
|
* Draws shadow layer on text (with optional positions).
|
|
|
|
*
|
|
|
|
* @param paint The paint to draw the shadow with
|
|
|
|
* @param text The text to draw
|
|
|
|
* @param bytesCount The number of bytes in the text
|
|
|
|
* @param count The number of glyphs in the text
|
|
|
|
* @param positions The x, y positions of individual glyphs (or NULL)
|
|
|
|
* @param fontRenderer The font renderer object
|
|
|
|
* @param alpha The alpha value for drawing the shadow
|
|
|
|
* @param x The x coordinate where the shadow will be drawn
|
|
|
|
* @param y The y coordinate where the shadow will be drawn
|
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
void drawTextShadow(const SkPaint* paint, const char* text, int bytesCount, int count,
|
2013-12-10 12:28:58 -05:00
|
|
|
const float* positions, FontRenderer& fontRenderer, int alpha,
|
2012-07-19 22:48:17 -07:00
|
|
|
float x, float y);
|
|
|
|
|
2011-06-13 19:04:27 -07:00
|
|
|
/**
|
|
|
|
* Draws a path texture. Path textures are alpha8 bitmaps that need special
|
|
|
|
* compositing to apply colors/filters/etc.
|
|
|
|
*
|
|
|
|
* @param texture The texture to render
|
|
|
|
* @param x The x coordinate where the texture will be drawn
|
|
|
|
* @param y The y coordinate where the texture will be drawn
|
|
|
|
* @param paint The paint to draw the texture with
|
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
void drawPathTexture(const PathTexture* texture, float x, float y, const SkPaint* paint);
|
2011-01-19 21:54:02 -08:00
|
|
|
|
2010-06-28 17:12:22 -07:00
|
|
|
/**
|
2010-07-27 17:39:27 -07:00
|
|
|
* Resets the texture coordinates stored in mMeshVertices. Setting the values
|
2010-06-28 17:12:22 -07:00
|
|
|
* back to default is achieved by calling:
|
|
|
|
*
|
2010-06-30 19:21:21 -07:00
|
|
|
* resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
|
2010-06-28 17:12:22 -07:00
|
|
|
*
|
|
|
|
* @param u1 The left coordinate of the texture
|
|
|
|
* @param v1 The bottom coordinate of the texture
|
|
|
|
* @param u2 The right coordinate of the texture
|
|
|
|
* @param v2 The top coordinate of the texture
|
|
|
|
*/
|
|
|
|
void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
|
|
|
|
|
2013-02-27 13:50:45 -08:00
|
|
|
/**
|
|
|
|
* Returns true if the specified paint will draw invisible text.
|
|
|
|
*/
|
|
|
|
bool canSkipText(const SkPaint* paint) const;
|
|
|
|
|
2010-07-20 13:09:13 -07:00
|
|
|
/**
|
2010-10-26 16:27:31 -07:00
|
|
|
* Binds the specified texture. The texture unit must have been selected
|
|
|
|
* prior to calling this method.
|
2010-07-20 13:09:13 -07:00
|
|
|
*/
|
2010-10-26 16:27:31 -07:00
|
|
|
inline void bindTexture(GLuint texture) {
|
2013-06-04 18:00:09 -07:00
|
|
|
mCaches.bindTexture(texture);
|
2010-10-26 16:27:31 -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
|
|
|
/**
|
|
|
|
* Binds the specified EGLImage texture. The texture unit must have been selected
|
|
|
|
* prior to calling this method.
|
|
|
|
*/
|
|
|
|
inline void bindExternalTexture(GLuint texture) {
|
2013-06-04 18:00:09 -07:00
|
|
|
mCaches.bindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
|
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-07-09 13:25:56 -07:00
|
|
|
/**
|
|
|
|
* Enable or disable blending as necessary. This function sets the appropriate
|
|
|
|
* blend function based on the specified xfermode.
|
|
|
|
*/
|
2010-09-10 19:20:06 -07:00
|
|
|
inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
|
|
|
|
bool swapSrcDst = false);
|
2010-09-09 14:42:43 -07:00
|
|
|
|
2010-07-12 14:41:06 -07:00
|
|
|
/**
|
2010-07-14 19:18:51 -07:00
|
|
|
* Use the specified program with the current GL context. If the program is already
|
|
|
|
* in use, it will not be bound again. If it is not in use, the current program is
|
|
|
|
* marked unused and the specified program becomes used and becomes the new
|
|
|
|
* current program.
|
2010-07-12 20:20:03 -07:00
|
|
|
*
|
2010-07-14 19:18:51 -07:00
|
|
|
* @param program The program to use
|
|
|
|
*
|
|
|
|
* @return true If the specified program was already in use, false otherwise.
|
2010-07-12 14:41:06 -07:00
|
|
|
*/
|
2010-07-29 14:37:42 -07:00
|
|
|
inline bool useProgram(Program* program);
|
2010-07-12 14:41:06 -07:00
|
|
|
|
2010-10-26 16:27:31 -07:00
|
|
|
/**
|
|
|
|
* Invoked before any drawing operation. This sets required state.
|
|
|
|
*/
|
2011-06-13 19:04:27 -07:00
|
|
|
void setupDraw(bool clear = true);
|
2012-08-07 11:24:39 -07:00
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
/**
|
|
|
|
* Various methods to setup OpenGL rendering.
|
|
|
|
*/
|
|
|
|
void setupDrawWithTexture(bool isAlpha8 = false);
|
2013-02-13 18:39:43 -08:00
|
|
|
void setupDrawWithTextureAndColor(bool isAlpha8 = false);
|
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 setupDrawWithExternalTexture();
|
2011-12-13 13:11:32 -08:00
|
|
|
void setupDrawNoTexture();
|
2012-09-17 17:25:49 -07:00
|
|
|
void setupDrawAA();
|
2010-12-14 20:13:35 -08:00
|
|
|
void setupDrawColor(int color, int alpha);
|
2010-12-13 18:24:33 -08:00
|
|
|
void setupDrawColor(float r, float g, float b, float a);
|
2010-12-14 15:55:39 -08:00
|
|
|
void setupDrawAlpha8Color(int color, int alpha);
|
2012-07-16 17:04:24 -07:00
|
|
|
void setupDrawTextGamma(const SkPaint* paint);
|
2010-12-13 18:24:33 -08:00
|
|
|
void setupDrawShader();
|
2013-12-10 12:28:58 -05:00
|
|
|
void setupDrawColorFilter(const SkColorFilter* filter);
|
|
|
|
void setupDrawBlending(const Layer* layer, bool swapSrcDst = false);
|
|
|
|
void setupDrawBlending(const SkPaint* paint, bool blend = true, bool swapSrcDst = false);
|
2010-12-13 18:24:33 -08:00
|
|
|
void setupDrawProgram();
|
|
|
|
void setupDrawDirtyRegionsDisabled();
|
2013-11-15 16:06:56 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the current program matrices based upon the nature of the geometry.
|
|
|
|
*
|
|
|
|
* @param mode If kModelViewMode_Translate, the geometry must be translated by the left and top
|
|
|
|
* parameters. If kModelViewMode_TranslateAndScale, the geometry that exists in the (0,0, 1,1)
|
|
|
|
* space must be scaled up and translated to fill the quad provided in (l,t,r,b). These
|
|
|
|
* transformations are stored in the modelView matrix and uploaded to the shader.
|
|
|
|
*
|
|
|
|
* @param offset Set to true if the the matrix should be fudged (translated) slightly to disambiguate
|
2014-01-02 16:46:18 -08:00
|
|
|
* geometry pixel positioning. See Vertex::GeometryFudgeFactor().
|
2013-11-15 16:06:56 -08:00
|
|
|
*
|
|
|
|
* @param ignoreTransform Set to true if l,t,r,b coordinates already in layer space,
|
|
|
|
* currentTransform() will be ignored. (e.g. when drawing clip in layer coordinates to stencil,
|
|
|
|
* or when simple translation has been extracted)
|
|
|
|
*/
|
|
|
|
void setupDrawModelView(ModelViewMode mode, bool offset,
|
|
|
|
float left, float top, float right, float bottom, bool ignoreTransform = false);
|
2010-12-13 18:24:33 -08:00
|
|
|
void setupDrawColorUniforms();
|
2010-12-14 15:55:39 -08:00
|
|
|
void setupDrawPureColorUniforms();
|
2010-12-13 18:24:33 -08:00
|
|
|
void setupDrawShaderUniforms(bool ignoreTransform = false);
|
2013-12-10 12:28:58 -05:00
|
|
|
void setupDrawColorFilterUniforms(const SkColorFilter* paint);
|
2010-12-13 18:24:33 -08:00
|
|
|
void setupDrawSimpleMesh();
|
|
|
|
void setupDrawTexture(GLuint texture);
|
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 setupDrawExternalTexture(GLuint texture);
|
2011-05-02 17:24:22 -07:00
|
|
|
void setupDrawTextureTransform();
|
|
|
|
void setupDrawTextureTransformUniforms(mat4& transform);
|
2012-07-16 17:04:24 -07:00
|
|
|
void setupDrawTextGammaUniforms();
|
2014-01-02 16:46:18 -08:00
|
|
|
void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords = NULL, GLuint vbo = 0);
|
|
|
|
void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords, const GLvoid* colors);
|
|
|
|
void setupDrawMeshIndices(const GLvoid* vertices, const GLvoid* texCoords, GLuint vbo = 0);
|
2013-07-22 13:57:50 -07:00
|
|
|
void setupDrawIndexedVertices(GLvoid* vertices);
|
2011-05-27 11:43:46 -07:00
|
|
|
void accountForClear(SkXfermode::Mode mode);
|
2010-10-26 16:27:31 -07:00
|
|
|
|
2012-09-21 00:39:43 -07:00
|
|
|
bool updateLayer(Layer* layer, bool inFrame);
|
|
|
|
void updateLayers();
|
2013-03-26 15:05:58 -07:00
|
|
|
void flushLayers();
|
2012-09-21 00:39:43 -07:00
|
|
|
|
2013-10-17 10:30:55 -07:00
|
|
|
#if DEBUG_LAYERS_AS_REGIONS
|
2012-08-07 11:24:39 -07:00
|
|
|
/**
|
|
|
|
* Renders the specified region as a series of rectangles. This method
|
|
|
|
* is used for debugging only.
|
|
|
|
*/
|
2013-10-17 10:30:55 -07:00
|
|
|
void drawRegionRectsDebug(const Region& region);
|
|
|
|
#endif
|
2011-02-01 22:59:58 -08:00
|
|
|
|
2013-01-15 18:51:42 -08:00
|
|
|
/**
|
|
|
|
* Renders the specified region as a series of rectangles. The region
|
|
|
|
* must be in screen-space coordinates.
|
|
|
|
*/
|
2013-12-10 12:28:58 -05:00
|
|
|
void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false);
|
2013-01-15 18:51:42 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS
|
|
|
|
* is turned on.
|
|
|
|
*/
|
|
|
|
void debugClip();
|
|
|
|
|
2012-09-21 19:15:00 -07:00
|
|
|
void debugOverdraw(bool enable, bool clear);
|
|
|
|
void renderOverdraw();
|
2013-05-03 14:24:16 -07:00
|
|
|
void countOverdraw();
|
2012-09-21 19:15:00 -07:00
|
|
|
|
2010-10-26 16:27:31 -07:00
|
|
|
/**
|
|
|
|
* Should be invoked every time the glScissor is modified.
|
|
|
|
*/
|
|
|
|
inline void dirtyClip() {
|
|
|
|
mDirtyClip = true;
|
|
|
|
}
|
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
inline const UvMapper& getMapper(const Texture* texture) {
|
|
|
|
return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a texture object for the specified bitmap. The texture can
|
|
|
|
* come from the texture cache or an atlas. If this method returns
|
|
|
|
* NULL, the texture could not be found and/or allocated.
|
|
|
|
*/
|
2014-01-02 17:13:34 -08:00
|
|
|
Texture* getTexture(const SkBitmap* bitmap);
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
|
2013-11-15 16:06:56 -08:00
|
|
|
/**
|
|
|
|
* Model-view matrix used to position/size objects
|
|
|
|
*
|
|
|
|
* Stores operation-local modifications to the draw matrix that aren't incorporated into the
|
|
|
|
* currentTransform().
|
|
|
|
*
|
2014-05-08 14:28:26 -07:00
|
|
|
* If generated with kModelViewMode_Translate, mModelViewMatrix will reflect an x/y offset,
|
2013-11-15 16:06:56 -08:00
|
|
|
* e.g. the offset in drawLayer(). If generated with kModelViewMode_TranslateAndScale,
|
2014-05-08 14:28:26 -07:00
|
|
|
* mModelViewMatrix will reflect a translation and scale, e.g. the translation and scale
|
|
|
|
* required to make VBO 0 (a rect of (0,0,1,1)) scaled to match the x,y offset, and width/height
|
|
|
|
* of a bitmap.
|
2013-11-15 16:06:56 -08:00
|
|
|
*
|
|
|
|
* Used as input to SkiaShader transformation.
|
|
|
|
*/
|
2014-05-08 14:28:26 -07:00
|
|
|
mat4 mModelViewMatrix;
|
2010-06-25 13:41:57 -07:00
|
|
|
|
2012-09-19 17:25:38 -07:00
|
|
|
// State used to define the clipping region
|
2013-03-21 14:39:04 -07:00
|
|
|
Rect mTilingClip;
|
2013-03-26 15:05:58 -07:00
|
|
|
// Is the target render surface opaque
|
|
|
|
bool mOpaque;
|
|
|
|
// Is a frame currently being rendered
|
|
|
|
bool mFrameStarted;
|
2010-06-24 19:30:36 -07:00
|
|
|
|
2010-06-28 17:12:22 -07:00
|
|
|
// Used to draw textured quads
|
2010-07-27 17:39:27 -07:00
|
|
|
TextureVertex mMeshVertices[4];
|
2010-06-29 21:05:21 -07:00
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
// Default UV mapper
|
|
|
|
const UvMapper mUvMapper;
|
|
|
|
|
2013-02-04 16:16:33 -08:00
|
|
|
// shader, filters, and shadow
|
|
|
|
DrawModifiers mDrawModifiers;
|
2012-01-23 17:09:05 -08:00
|
|
|
SkPaint mFilteredPaint;
|
|
|
|
|
2010-07-09 13:25:56 -07:00
|
|
|
// Various caches
|
2010-08-23 21:05:08 -07:00
|
|
|
Caches& mCaches;
|
2013-02-06 16:51:04 -08:00
|
|
|
Extensions& mExtensions;
|
2010-09-12 13:02:16 -07:00
|
|
|
|
2012-03-27 16:33:45 -07:00
|
|
|
// List of rectangles to clear after saveLayer() is invoked
|
2011-06-13 19:04:27 -07:00
|
|
|
Vector<Rect*> mLayers;
|
2012-09-21 00:39:43 -07:00
|
|
|
// List of layers to update at the beginning of a frame
|
|
|
|
Vector<Layer*> mLayerUpdates;
|
2011-06-13 19:04:27 -07:00
|
|
|
|
2010-12-13 18:24:33 -08:00
|
|
|
// The following fields are used to setup drawing
|
|
|
|
// Used to describe the shaders to generate
|
|
|
|
ProgramDescription mDescription;
|
|
|
|
// Color description
|
|
|
|
bool mColorSet;
|
|
|
|
float mColorA, mColorR, mColorG, mColorB;
|
|
|
|
// Indicates that the shader should get a color
|
|
|
|
bool mSetShaderColor;
|
|
|
|
// Current texture unit
|
|
|
|
GLuint mTextureUnit;
|
|
|
|
// Track dirty regions, true by default
|
|
|
|
bool mTrackDirtyRegions;
|
2012-09-19 17:25:38 -07:00
|
|
|
// Indicate whether we are drawing an opaque frame
|
|
|
|
bool mOpaqueFrame;
|
2010-12-13 18:24:33 -08:00
|
|
|
|
2012-09-24 11:37:12 -07:00
|
|
|
// See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in
|
|
|
|
// Properties.h
|
|
|
|
bool mScissorOptimizationDisabled;
|
|
|
|
|
2012-09-27 17:55:46 -07:00
|
|
|
// No-ops start/endTiling when set
|
|
|
|
bool mSuppressTiling;
|
|
|
|
|
2013-05-03 14:24:16 -07:00
|
|
|
// If true, this renderer will setup drawing to emulate
|
|
|
|
// an increment stencil buffer in the color buffer
|
|
|
|
bool mCountOverdraw;
|
|
|
|
float mOverdraw;
|
|
|
|
|
2010-09-28 19:09:36 -07:00
|
|
|
friend class DisplayListRenderer;
|
2013-03-26 15:05:58 -07:00
|
|
|
friend class Layer;
|
2013-03-20 16:31:12 -07:00
|
|
|
friend class TextSetupFunctor;
|
2013-06-20 18:30:28 -07:00
|
|
|
friend class DrawBitmapOp;
|
|
|
|
friend class DrawPatchOp;
|
2010-09-28 19:09:36 -07:00
|
|
|
|
2010-06-22 18:56:38 -07:00
|
|
|
}; // class OpenGLRenderer
|
2010-06-16 18:44:05 -07:00
|
|
|
|
2010-06-24 19:30:36 -07:00
|
|
|
}; // namespace uirenderer
|
2010-06-16 18:44:05 -07:00
|
|
|
}; // namespace android
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif // ANDROID_HWUI_OPENGL_RENDERER_H
|