1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*
* Copyright 2011, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "RasterRenderer.h"
#if USE(ACCELERATED_COMPOSITING)
#include "GLUtils.h"
#include "SkBitmap.h"
#include "SkBitmapRef.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "TilesManager.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <wtf/text/CString.h>
#ifdef DEBUG
#include <cutils/log.h>
#include <wtf/CurrentTime.h>
#undef XLOG
#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "RasterRenderer", __VA_ARGS__)
#else
#undef XLOG
#define XLOG(...)
#endif // DEBUG
namespace WebCore {
static const String TAG_CREATE_BITMAP = "create_bitmap";
static const String TAG_DRAW_PICTURE = "draw_picture";
static const String TAG_UPDATE_TEXTURE = "update_texture";
static const String TAG_RESET_BITMAP = "reset_bitmap";
#define TAG_COUNT 4
static const String TAGS[] = {
TAG_CREATE_BITMAP,
TAG_DRAW_PICTURE,
TAG_UPDATE_TEXTURE,
TAG_RESET_BITMAP
};
RasterRenderer::RasterRenderer()
{
#ifdef DEBUG_COUNT
ClassTracker::instance()->increment("RasterRenderer");
#endif
}
RasterRenderer::~RasterRenderer()
{
#ifdef DEBUG_COUNT
ClassTracker::instance()->decrement("RasterRenderer");
#endif
}
void RasterRenderer::drawTileInfo(SkCanvas* canvas,
BackedDoubleBufferedTexture* texture,
TiledPage* tiledPage,
int x, int y, float scale,
int pictureCount)
{
SkPaint paint;
char str[256];
snprintf(str, 256, "(%d,%d) %.2f, tl%x tx%x p%x c%d",
x, y, scale, this, texture, tiledPage, pictureCount);
paint.setARGB(255, 0, 0, 0);
canvas->drawText(str, strlen(str), 0, 10, paint);
paint.setARGB(255, 255, 0, 0);
canvas->drawText(str, strlen(str), 0, 11, paint);
float total = 0;
for (int i = 0; i < TAG_COUNT; i++) {
float tagDuration = m_perfMon.getAverageDuration(TAGS[i]);
total += tagDuration;
snprintf(str, 256, "%s: %.2f", TAGS[i].utf8().data(), tagDuration);
paint.setARGB(255, 0, 0, 0);
int textY = (i * 12) + 25;
canvas->drawText(str, strlen(str), 0, textY, paint);
paint.setARGB(255, 255, 0, 0);
canvas->drawText(str, strlen(str), 0, textY + 1, paint);
}
snprintf(str, 256, "total: %.2f", total);
paint.setARGB(255, 0, 0, 0);
int textY = (TAG_COUNT * 12) + 30;
canvas->drawText(str, strlen(str), 0, textY, paint);
paint.setARGB(255, 255, 0, 0);
canvas->drawText(str, strlen(str), 0, textY + 1, paint);
}
int RasterRenderer::renderContent(int x, int y, SkIRect rect, float tx, float ty,
float scale, BackedDoubleBufferedTexture* texture,
TextureInfo* textureInfo,
TiledPage* tiledPage, bool fullRepaint)
{
bool visualIndicator = TilesManager::instance()->getShowVisualIndicator();
bool measurePerf = fullRepaint && visualIndicator;
#ifdef DEBUG
visualIndicator = true;
measurePerf = true;
#endif
if (measurePerf)
m_perfMon.start(TAG_CREATE_BITMAP);
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height());
bitmap.allocPixels();
bitmap.eraseColor(0);
SkCanvas canvas(bitmap);
canvas.drawARGB(255, 255, 255, 255);
if (measurePerf) {
m_perfMon.stop(TAG_CREATE_BITMAP);
m_perfMon.start(TAG_DRAW_PICTURE);
}
if (visualIndicator)
canvas.save();
canvas.scale(scale, scale);
canvas.translate(-tx, -ty);
int pictureCount = tiledPage->paintBaseLayerContent(&canvas);
if (measurePerf) {
m_perfMon.stop(TAG_DRAW_PICTURE);
}
if (visualIndicator) {
canvas.restore();
int color = 20 + pictureCount % 100;
canvas.drawARGB(color, 0, 255, 0);
SkPaint paint;
paint.setARGB(128, 255, 0, 0);
paint.setStrokeWidth(3);
canvas.drawLine(0, 0, rect.width(), rect.height(), paint);
paint.setARGB(128, 0, 255, 0);
canvas.drawLine(0, rect.height(), rect.width(), 0, paint);
paint.setARGB(128, 0, 0, 255);
canvas.drawLine(0, 0, rect.width(), 0, paint);
canvas.drawLine(rect.width(), 0, rect.width(), rect.height(), paint);
drawTileInfo(&canvas, texture, tiledPage, x, y, scale, pictureCount);
}
if (measurePerf)
m_perfMon.start(TAG_UPDATE_TEXTURE);
GLUtils::paintTextureWithBitmap(textureInfo, &bitmap, rect.fLeft, rect.fTop, texture);
if (measurePerf)
m_perfMon.stop(TAG_UPDATE_TEXTURE);
if (measurePerf)
m_perfMon.start(TAG_RESET_BITMAP);
bitmap.reset();
if (measurePerf)
m_perfMon.stop(TAG_RESET_BITMAP);
return pictureCount;
}
} // namespace WebCore
#endif // USE(ACCELERATED_COMPOSITING)
|