OpenGLRenderer.cpp revision f18fd99b5c182329cd8936a9611f0103d8ece44a
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
19#include <stdlib.h>
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <SkCanvas.h>
24
25#include <cutils/properties.h>
26#include <utils/Log.h>
27
28#include "OpenGLRenderer.h"
29
30namespace android {
31namespace uirenderer {
32
33///////////////////////////////////////////////////////////////////////////////
34// Defines
35///////////////////////////////////////////////////////////////////////////////
36
37// These properties are defined in mega-bytes
38#define PROPERTY_TEXTURE_CACHE_SIZE "ro.hwui.texture_cache_size"
39#define PROPERTY_LAYER_CACHE_SIZE "ro.hwui.layer_cache_size"
40
41#define DEFAULT_TEXTURE_CACHE_SIZE 20
42#define DEFAULT_LAYER_CACHE_SIZE 10
43
44// Converts a number of mega-bytes into bytes
45#define MB(s) s * 1024 * 1024
46
47// Generates simple and textured vertices
48#define SV(x, y) { { x, y } }
49#define FV(x, y, u, v) { { x, y }, { u, v } }
50
51///////////////////////////////////////////////////////////////////////////////
52// Globals
53///////////////////////////////////////////////////////////////////////////////
54
55static const SimpleVertex gDrawColorVertices[] = {
56        SV(0.0f, 0.0f),
57        SV(1.0f, 0.0f),
58        SV(0.0f, 1.0f),
59        SV(1.0f, 1.0f)
60};
61static const GLsizei gDrawColorVertexStride = sizeof(SimpleVertex);
62static const GLsizei gDrawColorVertexCount = 4;
63
64// This array is never used directly but used as a memcpy source in the
65// OpenGLRenderer constructor
66static const TextureVertex gDrawTextureVertices[] = {
67        FV(0.0f, 0.0f, 0.0f, 0.0f),
68        FV(1.0f, 0.0f, 1.0f, 0.0f),
69        FV(0.0f, 1.0f, 0.0f, 1.0f),
70        FV(1.0f, 1.0f, 1.0f, 1.0f)
71};
72static const GLsizei gDrawTextureVertexStride = sizeof(TextureVertex);
73static const GLsizei gDrawTextureVertexCount = 4;
74
75// In this array, the index of each Blender equals the value of the first
76// entry. For instance, gBlends[1] == gBlends[SkXfermode::kSrc_Mode]
77static const Blender gBlends[] = {
78        { SkXfermode::kClear_Mode,   GL_ZERO,                 GL_ZERO },
79        { SkXfermode::kSrc_Mode,     GL_ONE,                  GL_ZERO },
80        { SkXfermode::kDst_Mode,     GL_ZERO,                 GL_ONE },
81        { SkXfermode::kSrcOver_Mode, GL_ONE,                  GL_ONE_MINUS_SRC_ALPHA },
82        { SkXfermode::kDstOver_Mode, GL_ONE_MINUS_DST_ALPHA,  GL_ONE },
83        { SkXfermode::kSrcIn_Mode,   GL_DST_ALPHA,            GL_ZERO },
84        { SkXfermode::kDstIn_Mode,   GL_ZERO,                 GL_SRC_ALPHA },
85        { SkXfermode::kSrcOut_Mode,  GL_ONE_MINUS_DST_ALPHA,  GL_ZERO },
86        { SkXfermode::kDstOut_Mode,  GL_ZERO,                 GL_ONE_MINUS_SRC_ALPHA },
87        { SkXfermode::kSrcATop_Mode, GL_DST_ALPHA,            GL_ONE_MINUS_SRC_ALPHA },
88        { SkXfermode::kDstATop_Mode, GL_ONE_MINUS_DST_ALPHA,  GL_SRC_ALPHA },
89        { SkXfermode::kXor_Mode,     GL_ONE_MINUS_DST_ALPHA,  GL_ONE_MINUS_SRC_ALPHA }
90};
91
92///////////////////////////////////////////////////////////////////////////////
93// Constructors/destructor
94///////////////////////////////////////////////////////////////////////////////
95
96OpenGLRenderer::OpenGLRenderer():
97        mTextureCache(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
98        mLayerCache(MB(DEFAULT_LAYER_CACHE_SIZE)) {
99    LOGD("Create OpenGLRenderer");
100
101    char property[PROPERTY_VALUE_MAX];
102    if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
103        LOGD("  Setting texture cache size to %sMB", property);
104        mTextureCache.setMaxSize(MB(atoi(property)));
105    } else {
106        LOGD("  Using default texture cache size of %dMB", DEFAULT_TEXTURE_CACHE_SIZE);
107    }
108
109    if (property_get(PROPERTY_LAYER_CACHE_SIZE, property, NULL) > 0) {
110        LOGD("  Setting layer cache size to %sMB", property);
111        mLayerCache.setMaxSize(MB(atoi(property)));
112    } else {
113        LOGD("  Using default layer cache size of %dMB", DEFAULT_LAYER_CACHE_SIZE);
114    }
115
116    mDrawColorShader = new DrawColorProgram;
117    mDrawTextureShader = new DrawTextureProgram;
118
119    memcpy(mDrawTextureVertices, gDrawTextureVertices, sizeof(gDrawTextureVertices));
120}
121
122OpenGLRenderer::~OpenGLRenderer() {
123    LOGD("Destroy OpenGLRenderer");
124
125    mTextureCache.clear();
126    mLayerCache.clear();
127}
128
129///////////////////////////////////////////////////////////////////////////////
130// Setup
131///////////////////////////////////////////////////////////////////////////////
132
133void OpenGLRenderer::setViewport(int width, int height) {
134    glViewport(0, 0, width, height);
135
136    mat4 ortho;
137    ortho.loadOrtho(0, width, height, 0, -1, 1);
138    ortho.copyTo(mOrthoMatrix);
139
140    mWidth = width;
141    mHeight = height;
142    mFirstSnapshot.height = height;
143}
144
145void OpenGLRenderer::prepare() {
146    mSnapshot = &mFirstSnapshot;
147    mSaveCount = 0;
148
149    glDisable(GL_SCISSOR_TEST);
150
151    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
152    glClear(GL_COLOR_BUFFER_BIT);
153
154    glEnable(GL_SCISSOR_TEST);
155    glScissor(0, 0, mWidth, mHeight);
156
157    mSnapshot->clipRect.set(0.0f, 0.0f, mWidth, mHeight);
158}
159
160///////////////////////////////////////////////////////////////////////////////
161// State management
162///////////////////////////////////////////////////////////////////////////////
163
164int OpenGLRenderer::getSaveCount() const {
165    return mSaveCount;
166}
167
168int OpenGLRenderer::save(int flags) {
169    return saveSnapshot();
170}
171
172void OpenGLRenderer::restore() {
173    if (mSaveCount == 0) return;
174
175    if (restoreSnapshot()) {
176        setScissorFromClip();
177    }
178}
179
180void OpenGLRenderer::restoreToCount(int saveCount) {
181    if (saveCount <= 0 || saveCount > mSaveCount) return;
182
183    bool restoreClip = false;
184
185    while (mSaveCount != saveCount - 1) {
186        restoreClip |= restoreSnapshot();
187    }
188
189    if (restoreClip) {
190        setScissorFromClip();
191    }
192}
193
194int OpenGLRenderer::saveSnapshot() {
195    mSnapshot = new Snapshot(mSnapshot);
196    return ++mSaveCount;
197}
198
199bool OpenGLRenderer::restoreSnapshot() {
200    bool restoreClip = mSnapshot->flags & Snapshot::kFlagClipSet;
201    bool restoreLayer = mSnapshot->flags & Snapshot::kFlagIsLayer;
202    bool restoreOrtho = mSnapshot->flags & Snapshot::kFlagDirtyOrtho;
203
204    sp<Snapshot> current = mSnapshot;
205    sp<Snapshot> previous = mSnapshot->previous;
206
207    if (restoreOrtho) {
208        memcpy(mOrthoMatrix, current->orthoMatrix, sizeof(mOrthoMatrix));
209    }
210
211    if (restoreLayer) {
212        composeLayer(current, previous);
213    }
214
215    mSnapshot = previous;
216    mSaveCount--;
217
218    return restoreClip;
219}
220
221void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
222    if (!current->layer) {
223        LOGE("Attempting to compose a layer that does not exist");
224        return;
225    }
226
227    // Unbind current FBO and restore previous one
228    // Most of the time, previous->fbo will be 0 to bind the default buffer
229    glBindFramebuffer(GL_FRAMEBUFFER, previous->fbo);
230
231    // Restore the clip from the previous snapshot
232    const Rect& clip = previous->getMappedClip();
233    glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight());
234
235    Layer* layer = current->layer;
236
237    // Compute the correct texture coordinates for the FBO texture
238    // The texture is currently as big as the window but drawn with
239    // a quad of the appropriate size
240    const Rect& rect = layer->layer;
241
242    drawTextureRect(rect.left, rect.top, rect.right, rect.bottom,
243            layer->texture, layer->alpha, layer->mode, layer->blend, true);
244
245    LayerSize size(rect.getWidth(), rect.getHeight());
246    // Failing to add the layer to the cache should happen only if the
247    // layer is too large
248    if (!mLayerCache.put(size, layer)) {
249        LAYER_LOGD("Deleting layer");
250
251        glDeleteFramebuffers(1, &layer->fbo);
252        glDeleteTextures(1, &layer->texture);
253
254        delete layer;
255    }
256}
257
258///////////////////////////////////////////////////////////////////////////////
259// Layers
260///////////////////////////////////////////////////////////////////////////////
261
262int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
263        const SkPaint* p, int flags) {
264    int count = saveSnapshot();
265
266    int alpha = 255;
267    SkXfermode::Mode mode;
268
269    if (p) {
270        alpha = p->getAlpha();
271        const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
272        if (!isMode) {
273            // Assume SRC_OVER
274            mode = SkXfermode::kSrcOver_Mode;
275        }
276    } else {
277        mode = SkXfermode::kSrcOver_Mode;
278    }
279
280    createLayer(mSnapshot, left, top, right, bottom, alpha, mode, flags);
281
282    return count;
283}
284
285int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
286        int alpha, int flags) {
287    int count = saveSnapshot();
288    createLayer(mSnapshot, left, top, right, bottom, alpha, SkXfermode::kSrcOver_Mode, flags);
289    return count;
290}
291
292bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
293        float right, float bottom, int alpha, SkXfermode::Mode mode,int flags) {
294
295    LAYER_LOGD("Requesting layer %dx%d", size.width, size.height);
296    LAYER_LOGD("Layer cache size = %d", mLayerCache.getSize());
297
298    GLuint previousFbo = snapshot->previous.get() ? snapshot->previous->fbo : 0;
299    LayerSize size(right - left, bottom - top);
300
301    // TODO VERY IMPORTANT: Fix TextView to not call saveLayer() all the time
302    Layer* layer = mLayerCache.get(size, previousFbo);
303    if (!layer) {
304        return false;
305    }
306
307    glBindFramebuffer(GL_FRAMEBUFFER, layer->fbo);
308
309    // Clear the FBO
310    glDisable(GL_SCISSOR_TEST);
311    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
312    glClear(GL_COLOR_BUFFER_BIT);
313    glEnable(GL_SCISSOR_TEST);
314
315    // Save the layer in the snapshot
316    snapshot->flags |= Snapshot::kFlagIsLayer;
317    layer->mode = mode;
318    layer->alpha = alpha / 255.0f;
319    layer->layer.set(left, top, right, bottom);
320
321    snapshot->layer = layer;
322    snapshot->fbo = layer->fbo;
323
324    // Creates a new snapshot to draw into the FBO
325    saveSnapshot();
326    // TODO: This doesn't preserve other transformations (check Skia first)
327    mSnapshot->transform.loadTranslate(-left, -top, 0.0f);
328    mSnapshot->clipRect.set(left, top, right, bottom);
329    mSnapshot->height = bottom - top;
330    setScissorFromClip();
331
332    mSnapshot->flags = Snapshot::kFlagDirtyTransform | Snapshot::kFlagDirtyOrtho |
333            Snapshot::kFlagClipSet;
334    memcpy(mSnapshot->orthoMatrix, mOrthoMatrix, sizeof(mOrthoMatrix));
335
336    // Change the ortho projection
337    mat4 ortho;
338    ortho.loadOrtho(0.0f, right - left, bottom - top, 0.0f, 0.0f, 1.0f);
339    ortho.copyTo(mOrthoMatrix);
340
341    return true;
342}
343
344///////////////////////////////////////////////////////////////////////////////
345// Transforms
346///////////////////////////////////////////////////////////////////////////////
347
348void OpenGLRenderer::translate(float dx, float dy) {
349    mSnapshot->transform.translate(dx, dy, 0.0f);
350    mSnapshot->flags |= Snapshot::kFlagDirtyTransform;
351}
352
353void OpenGLRenderer::rotate(float degrees) {
354    mSnapshot->transform.rotate(degrees, 0.0f, 0.0f, 1.0f);
355    mSnapshot->flags |= Snapshot::kFlagDirtyTransform;
356}
357
358void OpenGLRenderer::scale(float sx, float sy) {
359    mSnapshot->transform.scale(sx, sy, 1.0f);
360    mSnapshot->flags |= Snapshot::kFlagDirtyTransform;
361}
362
363void OpenGLRenderer::setMatrix(SkMatrix* matrix) {
364    mSnapshot->transform.load(*matrix);
365    mSnapshot->flags |= Snapshot::kFlagDirtyTransform;
366}
367
368void OpenGLRenderer::getMatrix(SkMatrix* matrix) {
369    mSnapshot->transform.copyTo(*matrix);
370}
371
372void OpenGLRenderer::concatMatrix(SkMatrix* matrix) {
373    mat4 m(*matrix);
374    mSnapshot->transform.multiply(m);
375    mSnapshot->flags |= Snapshot::kFlagDirtyTransform;
376}
377
378///////////////////////////////////////////////////////////////////////////////
379// Clipping
380///////////////////////////////////////////////////////////////////////////////
381
382void OpenGLRenderer::setScissorFromClip() {
383    const Rect& clip = mSnapshot->getMappedClip();
384    glScissor(clip.left, mSnapshot->height - clip.bottom, clip.getWidth(), clip.getHeight());
385}
386
387const Rect& OpenGLRenderer::getClipBounds() {
388    return mSnapshot->clipRect;
389}
390
391bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
392    /*
393     * The documentation of quickReject() indicates that the specified rect
394     * is transformed before being compared to the clip rect. However, the
395     * clip rect is not stored transformed in the snapshot and can thus be
396     * compared directly
397     *
398     * The following code can be used instead to performed a mapped comparison:
399     *
400     *     mSnapshot->transform.mapRect(r);
401     *     const Rect& clip = mSnapshot->getMappedClip();
402     *     return !clip.intersects(r);
403     */
404    Rect r(left, top, right, bottom);
405    return !mSnapshot->clipRect.intersects(r);
406}
407
408bool OpenGLRenderer::clipRect(float left, float top, float right, float bottom) {
409    bool clipped = mSnapshot->clipRect.intersect(left, top, right, bottom);
410    if (clipped) {
411        mSnapshot->flags |= Snapshot::kFlagClipSet;
412        setScissorFromClip();
413    }
414    return clipped;
415}
416
417///////////////////////////////////////////////////////////////////////////////
418// Drawing
419///////////////////////////////////////////////////////////////////////////////
420
421void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint) {
422    const Texture* texture = mTextureCache.get(bitmap);
423
424    int alpha;
425    SkXfermode::Mode mode;
426    getAlphaAndMode(paint, &alpha, &mode);
427
428    drawTextureRect(left, top, left + texture->width, top + texture->height, texture->id,
429            alpha / 255.0f, mode, texture->blend, true);
430}
431
432void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint) {
433    Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
434    const mat4 transform(*matrix);
435    transform.mapRect(r);
436
437    const Texture* texture = mTextureCache.get(bitmap);
438
439    int alpha;
440    SkXfermode::Mode mode;
441    getAlphaAndMode(paint, &alpha, &mode);
442
443    drawTextureRect(r.left, r.top, r.right, r.bottom, texture->id,
444            alpha / 255.0f, mode, texture->blend, true);
445}
446
447void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
448         float srcLeft, float srcTop, float srcRight, float srcBottom,
449         float dstLeft, float dstTop, float dstRight, float dstBottom,
450         const SkPaint* paint) {
451    const Texture* texture = mTextureCache.get(bitmap);
452
453    int alpha;
454    SkXfermode::Mode mode;
455    getAlphaAndMode(paint, &alpha, &mode);
456
457    const float width = texture->width;
458    const float height = texture->height;
459
460    const float u1 = srcLeft / width;
461    const float v1 = srcTop / height;
462    const float u2 = srcRight / width;
463    const float v2 = srcBottom / height;
464
465    resetDrawTextureTexCoords(u1, v1, u2, v2);
466
467    drawTextureRect(dstLeft, dstTop, dstRight, dstBottom, texture->id,
468            alpha / 255.0f, mode, texture->blend, true);
469
470    resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
471}
472
473void OpenGLRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
474        float left, float top, float right, float bottom, const SkPaint* paint) {
475    // TODO: Implement
476    LOGD("Draw 9patch, paddingLeft=%d", patch->paddingLeft);
477}
478
479void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
480    const Rect& clip = mSnapshot->clipRect;
481    drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode);
482}
483
484void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, const SkPaint* p) {
485    SkXfermode::Mode mode;
486
487    const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
488    if (!isMode) {
489        // Assume SRC_OVER
490        mode = SkXfermode::kSrcOver_Mode;
491    }
492
493    // Skia draws using the color's alpha channel if < 255
494    // Otherwise, it uses the paint's alpha
495    int color = p->getColor();
496    if (((color >> 24) & 0xFF) == 255) {
497        color |= p->getAlpha() << 24;
498    }
499
500    drawColorRect(left, top, right, bottom, color, mode);
501}
502
503void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom,
504        int color, SkXfermode::Mode mode) {
505    const int alpha = (color >> 24) & 0xFF;
506    const bool blend = alpha < 255 || mode != SkXfermode::kSrcOver_Mode;
507
508    const GLfloat a = alpha                  / 255.0f;
509    const GLfloat r = ((color >> 16) & 0xFF) / 255.0f;
510    const GLfloat g = ((color >>  8) & 0xFF) / 255.0f;
511    const GLfloat b = ((color      ) & 0xFF) / 255.0f;
512
513    if (blend) {
514        glEnable(GL_BLEND);
515        glBlendFunc(gBlends[mode].src, gBlends[mode].dst);
516    }
517
518    mModelView.loadTranslate(left, top, 0.0f);
519    mModelView.scale(right - left, bottom - top, 1.0f);
520
521    mDrawColorShader->use(&mOrthoMatrix[0], &mModelView.data[0], &mSnapshot->transform.data[0]);
522
523    const GLvoid* p = &gDrawColorVertices[0].position[0];
524
525    glEnableVertexAttribArray(mDrawColorShader->position);
526    glVertexAttribPointer(mDrawColorShader->position, 2, GL_FLOAT, GL_FALSE,
527            gDrawColorVertexStride, p);
528    glVertexAttrib4f(mDrawColorShader->color, r, g, b, a);
529
530    glDrawArrays(GL_TRIANGLE_STRIP, 0, gDrawColorVertexCount);
531
532    glDisableVertexAttribArray(mDrawColorShader->position);
533
534    if (blend) {
535        glDisable(GL_BLEND);
536    }
537}
538
539void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
540        GLuint texture, float alpha, SkXfermode::Mode mode, bool blend, bool isPremultiplied) {
541    mModelView.loadTranslate(left, top, 0.0f);
542    mModelView.scale(right - left, bottom - top, 1.0f);
543
544    mDrawTextureShader->use(&mOrthoMatrix[0], &mModelView.data[0], &mSnapshot->transform.data[0]);
545
546    if (blend || alpha < 1.0f || mode != SkXfermode::kSrcOver_Mode) {
547        GLenum sourceMode = gBlends[mode].src;
548        if (!isPremultiplied && sourceMode == GL_ONE) {
549            sourceMode = GL_SRC_ALPHA;
550        }
551
552        glEnable(GL_BLEND);
553        glBlendFunc(sourceMode, gBlends[mode].dst);
554    }
555
556    glBindTexture(GL_TEXTURE_2D, texture);
557
558    // TODO handle tiling and filtering here
559
560    glActiveTexture(GL_TEXTURE0);
561    glUniform1i(mDrawTextureShader->sampler, 0);
562
563    const GLvoid* p = &mDrawTextureVertices[0].position[0];
564    const GLvoid* t = &mDrawTextureVertices[0].texture[0];
565
566    glEnableVertexAttribArray(mDrawTextureShader->position);
567    glVertexAttribPointer(mDrawTextureShader->position, 2, GL_FLOAT, GL_FALSE,
568            gDrawTextureVertexStride, p);
569
570    glEnableVertexAttribArray(mDrawTextureShader->texCoords);
571    glVertexAttribPointer(mDrawTextureShader->texCoords, 2, GL_FLOAT, GL_FALSE,
572            gDrawTextureVertexStride, t);
573
574    glVertexAttrib4f(mDrawTextureShader->color, 1.0f, 1.0f, 1.0f, alpha);
575
576    glDrawArrays(GL_TRIANGLE_STRIP, 0, gDrawTextureVertexCount);
577
578    glDisableVertexAttribArray(mDrawTextureShader->position);
579    glDisableVertexAttribArray(mDrawTextureShader->texCoords);
580
581    glBindTexture(GL_TEXTURE_2D, 0);
582    glDisable(GL_BLEND);
583}
584
585void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, float v2) {
586    mDrawTextureVertices[0].texture[0] = u1;
587    mDrawTextureVertices[0].texture[1] = v1;
588    mDrawTextureVertices[1].texture[0] = u2;
589    mDrawTextureVertices[1].texture[1] = v1;
590    mDrawTextureVertices[2].texture[0] = u1;
591    mDrawTextureVertices[2].texture[1] = v2;
592    mDrawTextureVertices[3].texture[0] = u2;
593    mDrawTextureVertices[3].texture[1] = v2;
594}
595
596void OpenGLRenderer::getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
597    if (paint) {
598        const bool isMode = SkXfermode::IsMode(paint->getXfermode(), mode);
599        if (!isMode) {
600            // Assume SRC_OVER
601            *mode = SkXfermode::kSrcOver_Mode;
602        }
603
604        // Skia draws using the color's alpha channel if < 255
605        // Otherwise, it uses the paint's alpha
606        int color = paint->getColor();
607        *alpha = (color >> 24) & 0xFF;
608        if (*alpha == 255) {
609            *alpha = paint->getAlpha();
610        }
611    } else {
612        *mode = SkXfermode::kSrcOver_Mode;
613        *alpha = 255;
614    }
615}
616
617}; // namespace uirenderer
618}; // namespace android
619