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

Side by Side Diff: samplecode/SampleMipMap.cpp

Issue 19789016: add mipmaps to scaledimagecache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | src/core/SkBitmapProcState.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 protected: 60 protected:
61 // overrides from SkEventSink 61 // overrides from SkEventSink
62 virtual bool onQuery(SkEvent* evt) { 62 virtual bool onQuery(SkEvent* evt) {
63 if (SampleCode::TitleQ(*evt)) { 63 if (SampleCode::TitleQ(*evt)) {
64 SampleCode::TitleR(evt, "MipMaps"); 64 SampleCode::TitleR(evt, "MipMaps");
65 return true; 65 return true;
66 } 66 }
67 return this->INHERITED::onQuery(evt); 67 return this->INHERITED::onQuery(evt);
68 } 68 }
69 69
70 void drawN(SkCanvas* canvas, const SkBitmap& bitmap) {
71 SkAutoCanvasRestore acr(canvas, true);
72 for (int i = N; i > 1; i >>= 1) {
73 canvas->drawBitmap(bitmap, 0, 0, NULL);
74 canvas->translate(SkIntToScalar(N + 8), 0);
75 canvas->scale(SK_ScalarHalf, SK_ScalarHalf);
76 }
77 }
78
79 void drawN2(SkCanvas* canvas, const SkBitmap& bitmap) {
80 SkBitmap bg;
81 bg.setConfig(SkBitmap::kARGB_8888_Config, N, N);
82 bg.allocPixels();
83
84 SkAutoCanvasRestore acr(canvas, true);
85 for (int i = 0; i < 6; i++) {
86 bg.eraseColor(SK_ColorTRANSPARENT);
87 SkCanvas c(bg);
88 c.scale(SK_Scalar1 / (1 << i), SK_Scalar1 / (1 << i));
89 c.drawBitmap(bitmap, 0, 0, NULL);
90
91 canvas->save();
92 canvas->scale(SkIntToScalar(1 << i), SkIntToScalar(1 << i));
93 canvas->drawBitmap(bg, 0, 0, NULL);
94 canvas->restore();
95 canvas->translate(SkIntToScalar(N + 8), 0);
96 }
97 }
98
99 virtual void onDrawContent(SkCanvas* canvas) { 70 virtual void onDrawContent(SkCanvas* canvas) {
100 this->init(); 71 this->init();
101 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); 72
102 73 static const SkPaint::FilterLevel gLevel[] = {
103 canvas->scale(1.00000001f, 0.9999999f); 74 SkPaint::kNone_FilterLevel,
104 75 SkPaint::kLow_FilterLevel,
105 drawN2(canvas, fBitmap); 76 SkPaint::kMedium_FilterLevel,
106 77 SkPaint::kHigh_FilterLevel,
107 canvas->translate(0, SkIntToScalar(N + 8)); 78 };
108 SkBitmap bitmap(fBitmap);
109 bitmap.buildMipMap();
110 drawN2(canvas, bitmap);
111
112 SkScalar time = SampleCode::GetAnimScalar(SkIntToScalar(1)/4,
113 SkIntToScalar(2));
114 if (time >= SK_Scalar1) {
115 time = SkIntToScalar(2) - time;
116 }
117 fWidth = 8 + SkScalarRound(N * time);
118
119 SkRect dst;
120 dst.set(0, 0, SkIntToScalar(fWidth), SkIntToScalar(fWidth));
121 79
122 SkPaint paint; 80 SkPaint paint;
123 paint.setFilterBitmap(true); 81
124 paint.setAntiAlias(true); 82 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevel); ++i) {
125 83 SkScalar x = 10 + i * 100;
126 canvas->translate(0, SkIntToScalar(N + 8)); 84 SkScalar y = 10;
127 canvas->drawBitmapRect(fBitmap, NULL, dst, NULL); 85
128 canvas->translate(SkIntToScalar(N + 8), 0); 86 paint.setFilterLevel(gLevel[i]);
129 canvas->drawBitmapRect(fBitmap, NULL, dst, &paint); 87
130 canvas->translate(-SkIntToScalar(N + 8), SkIntToScalar(N + 8)); 88 canvas->drawBitmap(fBitmap, x, y, &paint);
131 canvas->drawBitmapRect(bitmap, NULL, dst, NULL); 89 }
132 canvas->translate(SkIntToScalar(N + 8), 0);
133 canvas->drawBitmapRect(bitmap, NULL, dst, &paint);
134
135 SkShader* s = SkShader::CreateBitmapShader(bitmap,
136 SkShader::kRepeat_TileMode,
137 SkShader::kRepeat_TileMode);
138 paint.setShader(s)->unref();
139 SkMatrix m;
140 m.setScale(SkIntToScalar(fWidth) / N,
141 SkIntToScalar(fWidth) / N);
142 s->setLocalMatrix(m);
143 SkRect r;
144 r.set(0, 0, SkIntToScalar(4*N), SkIntToScalar(5*N/2));
145 r.offset(SkIntToScalar(N + 12), -SkIntToScalar(N + 4));
146 canvas->drawRect(r, paint);
147
148 this->inval(NULL); 90 this->inval(NULL);
149 } 91 }
150 92
151 private: 93 private:
152 int fWidth; 94 int fWidth;
153 95
154 typedef SampleView INHERITED; 96 typedef SampleView INHERITED;
155 }; 97 };
156 98
157 ////////////////////////////////////////////////////////////////////////////// 99 //////////////////////////////////////////////////////////////////////////////
158 100
159 static SkView* MyFactory() { return new MipMapView; } 101 static SkView* MyFactory() { return new MipMapView; }
160 static SkViewRegister reg(MyFactory); 102 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | src/core/SkBitmapProcState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698