Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: gm/scalebitmap.cpp

Issue 271693002: remove dead mipmap code from SkBitmap (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/skia_for_chromium_defines.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9
10 #include "SkImageDecoder.h"
11 #include "SkStream.h"
12
13 class ScaleBitmapGM : public skiagm::GM {
14
15 public:
16
17 ScaleBitmapGM(const char filename[], float scale)
18 : fFilename(filename), fScale(scale)
19 {
20 this->setBGColor(0xFFDDDDDD);
21 fName.printf("scalebitmap_%s_%f", filename, scale);
22
23 SkString path(skiagm::GM::gResourcePath);
24 path.append("/");
25 path.append(fFilename);
26
27 SkImageDecoder *codec = NULL;
28 SkFILEStream stream(path.c_str());
29 if (stream.isValid()) {
30 codec = SkImageDecoder::Factory(&stream);
31 }
32 if (codec) {
33 stream.rewind();
34 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config,
35 SkImageDecoder::kDecodePixels_Mode);
36 SkDELETE(codec);
37 } else {
38 fBM.allocN32Pixels(1, 1);
39 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
40 }
41 fSize = fBM.height();
42 }
43
44 protected:
45
46
47 SkBitmap fBM;
48 SkString fName;
49 SkString fFilename;
50 int fSize;
51 float fScale;
52
53
54 virtual SkString onShortName() SK_OVERRIDE {
55 return fName;
56 }
57
58 virtual SkISize onISize() SK_OVERRIDE {
59 return SkISize::Make(fBM.width() * fScale, fBM.height() * fScale);
60 }
61
62 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
63 SkBitmap dst;
64 dst.allocN32Pixels(fBM.width() * fScale, fBM.height() * fScale);
65 fBM.scale(&dst);
66
67 canvas->drawBitmap(dst, 0, 0);
68 }
69
70 private:
71 typedef skiagm::GM INHERITED;
72 };
73
74 class ScaleBitmapMipmapGM: public ScaleBitmapGM {
75 SkMatrix fMatrix;
76
77 public:
78 ScaleBitmapMipmapGM(const char filename[], float scale)
79 : INHERITED(filename, scale)
80 {
81 fName.printf("scalebitmap_mipmap_%s_%f", filename, scale);
82 fBM.buildMipMap();
83 fMatrix.setScale(scale, scale);
84 }
85 protected:
86 virtual void onDraw(SkCanvas *canvas) SK_OVERRIDE {
87 SkPaint paint;
88
89 paint.setFilterBitmap(true);
90 canvas->drawBitmapMatrix(fBM, fMatrix, &paint);
91 }
92 private:
93 typedef ScaleBitmapGM INHERITED;
94 };
95
96 //////////////////////////////////////////////////////////////////////////////
97
98 DEF_GM( return new ScaleBitmapGM("mandrill_128.png", 2); )
99 DEF_GM( return new ScaleBitmapGM("mandrill_64.png", 4); )
100 DEF_GM( return new ScaleBitmapGM("mandrill_32.png", 8); )
101 DEF_GM( return new ScaleBitmapGM("mandrill_16.png", 16); )
102
103 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.5f); )
104 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.25f); )
105 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.125f); )
106 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.0625f); )
107
108 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.5f); )
109 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.25f); )
110 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.125f); )
111 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.0625f); )
OLDNEW
« no previous file with comments | « no previous file | gyp/skia_for_chromium_defines.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698