1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc.
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SampleCode.h"
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkView.h"
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h"
119acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com#include "SkData.h"
129acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com#include "SkDecodingImageGenerator.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGradientShader.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGraphics.h"
15791f5a11f22abfa7f8f90c37c98a5f654c7fb4c5reed@android.com#include "SkImageDecoder.h"
16b08eb2b3bce45411494fe00258e4c91248ccd15ereed@android.com#include "SkImageEncoder.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h"
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkXfermode.h"
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h"
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorFilter.h"
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTime.h"
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypeface.h"
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkStream.h"
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
29a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.orgstatic void make_image(SkBitmap* bm, SkColorType ct, int configIndex) {
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const int   width = 98;
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const int   height = 100;
32a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org    const SkImageInfo info = SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType);
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
34a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org    SkBitmap    device;
35a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org    device.allocN32Pixels(width, height);
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas    canvas(device);
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPaint     paint;
38ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    paint.setAntiAlias(true);
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    canvas.drawColor(SK_ColorRED);
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    paint.setColor(SK_ColorBLUE);
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    canvas.drawCircle(SkIntToScalar(width)/2, SkIntToScalar(height)/2,
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      SkIntToScalar(width)/2, paint);
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
45a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org    switch (ct) {
4628fcae2ec77eb16a79e155f8d788b20457f1c951commit-bot@chromium.org        case kN32_SkColorType:
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            bm->swap(device);
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            break;
49a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org        case kRGB_565_SkColorType: {
50a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org            bm->allocPixels(info);
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            for (int y = 0; y < height; y++) {
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                for (int x = 0; x < width; x++) {
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    *bm->getAddr16(x, y) = SkPixel32ToPixel16(*device.getAddr32(x, y));
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                }
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            }
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            break;
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
58a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org        case kIndex_8_SkColorType: {
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkPMColor colors[256];
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            for (int i = 0; i < 256; i++) {
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                if (configIndex & 1) {
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    colors[i] = SkPackARGB32(255-i, 0, 0, 255-i);
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                } else {
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    colors[i] = SkPackARGB32(0xFF, i, 0, 255-i);
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                }
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            }
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkColorTable* ctable = new SkColorTable(colors, 256);
68a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org            bm->allocPixels(info, NULL, ctable);
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            ctable->unref();
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            for (int y = 0; y < height; y++) {
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                for (int x = 0; x < width; x++) {
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    *bm->getAddr8(x, y) = SkGetPackedR32(*device.getAddr32(x, y));
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                }
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            }
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            break;
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        default:
78a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org            SkASSERT(0);
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// configs to build the original bitmap in. Can be at most these 3
83a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.orgstatic const SkColorType gColorTypes[] = {
8428fcae2ec77eb16a79e155f8d788b20457f1c951commit-bot@chromium.org    kN32_SkColorType,
85a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org    kRGB_565_SkColorType,
86a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org    kIndex_8_SkColorType,   // opaque
87a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org    kIndex_8_SkColorType    // alpha
888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic const char* const gConfigLabels[] = {
918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    "8888", "565", "Index8",  "Index8 alpha"
928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// types to encode into. Can be at most these 3. Must match up with gExt[]
958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic const SkImageEncoder::Type gTypes[] = {
968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkImageEncoder::kJPEG_Type,
978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkImageEncoder::kPNG_Type
988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// must match up with gTypes[]
1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic const char* const gExt[] = {
1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ".jpg", ".png"
1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <sys/stat.h>
1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1070faac1e8579088a39f38d02ff675f14d7deb608dreed@google.comclass EncodeView : public SampleView {
1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
1099acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com    SkBitmap*        fBitmaps;
1109acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com    SkAutoDataUnref* fEncodedPNGs;
1119acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com    SkAutoDataUnref* fEncodedJPEGs;
1127fa2a65c0cfc714364490cb715171461143024e0reed@google.com    int              fBitmapCount;
1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
114ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com    EncodeView() {
115a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org        fBitmapCount = SK_ARRAY_COUNT(gColorTypes);
1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fBitmaps = new SkBitmap[fBitmapCount];
1179acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com        fEncodedPNGs = new SkAutoDataUnref[fBitmapCount];
1189acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com        fEncodedJPEGs = new SkAutoDataUnref[fBitmapCount];
1197fa2a65c0cfc714364490cb715171461143024e0reed@google.com        for (int i = 0; i < fBitmapCount; i++) {
120a8c183125f2861067daf432cada06d431a795cd0commit-bot@chromium.org            make_image(&fBitmaps[i], gColorTypes[i], i);
121ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1229acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com            for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) {
1239acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                SkAutoTDelete<SkImageEncoder> codec(
1249acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    SkImageEncoder::Create(gTypes[j]));
1259acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                if (NULL == codec.get()) {
1269acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    SkDebugf("[%s:%d] failed to encode %s%s\n",
1279acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                             __FILE__, __LINE__,gConfigLabels[i], gExt[j]);
1289acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    continue;
1299acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                }
1309acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                SkAutoDataUnref data(codec->encodeData(fBitmaps[i], 100));
1319acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                if (NULL == data.get()) {
1329acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    SkDebugf("[%s:%d] failed to encode %s%s\n",
1339acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                             __FILE__, __LINE__,gConfigLabels[i], gExt[j]);
1349acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    continue;
1359acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                }
1369acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                if (SkImageEncoder::kJPEG_Type == gTypes[j]) {
1379acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    fEncodedJPEGs[i].reset(data.detach());
1389acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                } else if (SkImageEncoder::kPNG_Type == gTypes[j]) {
1399acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    fEncodedPNGs[i].reset(data.detach());
1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                }
1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            }
1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
1430faac1e8579088a39f38d02ff675f14d7deb608dreed@google.com        this->setBGColor(0xFFDDDDDD);
1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
145ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~EncodeView() {
1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        delete[] fBitmaps;
1489acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com        delete[] fEncodedPNGs;
1499acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com        delete[] fEncodedJPEGs;
1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
151ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // overrides from SkEventSink
1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool onQuery(SkEvent* evt) {
1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        if (SampleCode::TitleQ(*evt)) {
1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SampleCode::TitleR(evt, "ImageEncoder");
1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            return true;
1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return this->INHERITED::onQuery(evt);
1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
161ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1620faac1e8579088a39f38d02ff675f14d7deb608dreed@google.com    virtual void onDrawContent(SkCanvas* canvas) {
1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        if (fBitmapCount == 0) {
1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            return;
1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
166ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint paint;
1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint.setAntiAlias(true);
1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint.setTextAlign(SkPaint::kCenter_Align);
170ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
172ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkScalar x = 0, y = 0, maxX = 0;
1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const int SPACER = 10;
175ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1767fa2a65c0cfc714364490cb715171461143024e0reed@google.com        for (int i = 0; i < fBitmapCount; i++) {
1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            canvas->drawText(gConfigLabels[i], strlen(gConfigLabels[i]),
1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             x + SkIntToScalar(fBitmaps[i].width()) / 2, 0,
1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             paint);
1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            y = paint.getTextSize();
1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            canvas->drawBitmap(fBitmaps[i], x, y);
183ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkScalar yy = y;
1859acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com            for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) {
1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                yy += SkIntToScalar(fBitmaps[i].height() + 10);
1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                SkBitmap bm;
1899acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                SkData* encoded = NULL;
1909acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                if (SkImageEncoder::kJPEG_Type == gTypes[j]) {
1919acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    encoded = fEncodedJPEGs[i].get();
1929acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                } else if (SkImageEncoder::kPNG_Type == gTypes[j]) {
1939acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    encoded = fEncodedPNGs[i].get();
1949acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                }
1959acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                if (encoded) {
1969acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    if (!SkInstallDiscardablePixelRef(
1979acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                            SkDecodingImageGenerator::Create(encoded,
1989acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                                SkDecodingImageGenerator::Options()),
1992d970b5128f7270cd01a93e4ce68d0c3ea67ac71commit-bot@chromium.org                            &bm)) {
2009acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    SkDebugf("[%s:%d] failed to decode %s%s\n",
2019acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                             __FILE__, __LINE__,gConfigLabels[i], gExt[j]);
2029acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    }
2039acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                    canvas->drawBitmap(bm, x, yy);
2049acb8cdf20423e80d5687ba3c8e11545e3bc8020halcanary@google.com                }
2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            }
206ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            x += SkIntToScalar(fBitmaps[i].width() + SPACER);
2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            if (x > maxX) {
2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                maxX = x;
2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            }
2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        y = (paint.getTextSize() + SkIntToScalar(fBitmaps[0].height())) * 3 / 2;
2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        x = maxX + SkIntToScalar(10);
2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint.setTextAlign(SkPaint::kLeft_Align);
2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        for (size_t j = 0; j < SK_ARRAY_COUNT(gExt); j++) {
2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            canvas->drawText(gExt[j], strlen(gExt[j]), x, y, paint);
2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            y += SkIntToScalar(fBitmaps[0].height() + SPACER);
2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
222ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
2234d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com    virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
2244d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com                                              unsigned modi) {
2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->inval(NULL);
2264d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com        return this->INHERITED::onFindClickHandler(x, y, modi);
2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
228ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
2300faac1e8579088a39f38d02ff675f14d7deb608dreed@google.com    typedef SampleView INHERITED;
2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////
2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic SkView* MyFactory() { return new EncodeView; }
2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic SkViewRegister reg(MyFactory);
237