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

Side by Side Diff: samplecode/SampleApp.cpp

Issue 1295483003: show LCD on max fat-zoom (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | no next file » | 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 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SampleApp.h" 8 #include "SampleApp.h"
9 9
10 #include "OverView.h" 10 #include "OverView.h"
(...skipping 26 matching lines...) Expand all
37 #if SK_SUPPORT_GPU 37 #if SK_SUPPORT_GPU
38 #include "gl/GrGLInterface.h" 38 #include "gl/GrGLInterface.h"
39 #include "gl/GrGLUtil.h" 39 #include "gl/GrGLUtil.h"
40 #include "GrRenderTarget.h" 40 #include "GrRenderTarget.h"
41 #include "GrContext.h" 41 #include "GrContext.h"
42 #include "SkGpuDevice.h" 42 #include "SkGpuDevice.h"
43 #else 43 #else
44 class GrContext; 44 class GrContext;
45 #endif 45 #endif
46 46
47 // Should be 3x + 1
48 #define kMaxFatBitsScale 28
49
47 extern SampleView* CreateSamplePictFileView(const char filename[]); 50 extern SampleView* CreateSamplePictFileView(const char filename[]);
48 51
49 class PictFileFactory : public SkViewFactory { 52 class PictFileFactory : public SkViewFactory {
50 SkString fFilename; 53 SkString fFilename;
51 public: 54 public:
52 PictFileFactory(const SkString& filename) : fFilename(filename) {} 55 PictFileFactory(const SkString& filename) : fFilename(filename) {}
53 SkView* operator() () const override { 56 SkView* operator() () const override {
54 return CreateSamplePictFileView(fFilename.c_str()); 57 return CreateSamplePictFileView(fFilename.c_str());
55 } 58 }
56 }; 59 };
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 } 630 }
628 631
629 bool SampleWindow::sendAnimatePulse() { 632 bool SampleWindow::sendAnimatePulse() {
630 SkView* view = curr_view(this); 633 SkView* view = curr_view(this);
631 if (SampleView::IsSampleView(view)) { 634 if (SampleView::IsSampleView(view)) {
632 return ((SampleView*)view)->animate(gAnimTimer); 635 return ((SampleView*)view)->animate(gAnimTimer);
633 } 636 }
634 return false; 637 return false;
635 } 638 }
636 639
637 void SampleWindow::setZoomCenter(float x, float y) 640 void SampleWindow::setZoomCenter(float x, float y) {
638 {
639 fZoomCenterX = x; 641 fZoomCenterX = x;
640 fZoomCenterY = y; 642 fZoomCenterY = y;
641 } 643 }
642 644
643 bool SampleWindow::zoomIn() 645 bool SampleWindow::zoomIn() {
644 {
645 // Arbitrarily decided 646 // Arbitrarily decided
646 if (fFatBitsScale == 25) return false; 647 if (fFatBitsScale == kMaxFatBitsScale) return false;
647 fFatBitsScale++; 648 fFatBitsScale++;
648 this->inval(NULL); 649 this->inval(NULL);
649 return true; 650 return true;
650 } 651 }
651 652
652 bool SampleWindow::zoomOut() 653 bool SampleWindow::zoomOut() {
653 {
654 if (fFatBitsScale == 1) return false; 654 if (fFatBitsScale == 1) return false;
655 fFatBitsScale--; 655 fFatBitsScale--;
656 this->inval(NULL); 656 this->inval(NULL);
657 return true; 657 return true;
658 } 658 }
659 659
660 void SampleWindow::updatePointer(int x, int y) 660 void SampleWindow::updatePointer(int x, int y) {
661 {
662 fMouseX = x; 661 fMouseX = x;
663 fMouseY = y; 662 fMouseY = y;
664 if (fShowZoomer) { 663 if (fShowZoomer) {
665 this->inval(NULL); 664 this->inval(NULL);
666 } 665 }
667 } 666 }
668 667
669 static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) { 668 static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) {
670 static const SampleWindow::DeviceType gCT[] = { 669 static const SampleWindow::DeviceType gCT[] = {
671 SampleWindow::kPicture_DeviceType, 670 SampleWindow::kPicture_DeviceType,
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 m.setTranslate(-center.fX, -center.fY); 1071 m.setTranslate(-center.fX, -center.fY);
1073 m.postScale(0.5f * fFatBitsScale, 0.5f * fFatBitsScale); 1072 m.postScale(0.5f * fFatBitsScale, 0.5f * fFatBitsScale);
1074 m.postTranslate(center.fX, center.fY); 1073 m.postTranslate(center.fX, center.fY);
1075 canvas->concat(m); 1074 canvas->concat(m);
1076 1075
1077 this->INHERITED::draw(canvas); 1076 this->INHERITED::draw(canvas);
1078 1077
1079 canvas->restoreToCount(count); 1078 canvas->restoreToCount(count);
1080 } 1079 }
1081 1080
1081 static SkPaint& set_color_ref(SkPaint& paint, SkColor c) {
1082 paint.setColor(c);
1083 return paint;
1084 }
1085
1086 static void show_lcd_box(SkCanvas* canvas, SkScalar x, SkScalar y, SkColor c,
1087 SkScalar sx, SkScalar sy) {
1088 const SkScalar w = (1 - 1/sx) / 3;
1089 SkPaint paint;
1090 SkRect r = SkRect::MakeXYWH(x, y, w, 1 - 1/sy);
1091 canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(SkColorGetR(c), 0, 0) ));
1092 r.offset(w, 0);
1093 canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(0, SkColorGetG(c), 0) ));
1094 r.offset(w, 0);
1095 canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(0, 0, SkColorGetB(c)) ));
1096 }
1097
1098 static void show_lcd_circle(SkCanvas* canvas, SkScalar x, SkScalar y, SkColor c,
1099 SkScalar, SkScalar) {
1100 const SkRect r = SkRect::MakeXYWH(x, y, 1, 1);
1101 const SkScalar cx = x + 0.5f;
1102 const SkScalar cy = y + 0.5f;
1103
1104 SkPaint paint;
1105 paint.setAntiAlias(true);
1106
1107 SkPath path;
1108 path.addArc(r, 0, 120); path.lineTo(cx, cy);
1109 canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(SkColorGetR(c), 0, 0)));
1110
1111 path.reset(); path.addArc(r, 120, 120); path.lineTo(cx, cy);
1112 canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(0, SkColorGetG(c), 0)));
1113
1114 path.reset(); path.addArc(r, 240, 120); path.lineTo(cx, cy);
1115 canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(0, 0, SkColorGetB( c))));
1116 }
1117
1118 typedef void (*ShowLCDProc)(SkCanvas*, SkScalar, SkScalar, SkColor, SkScalar, Sk Scalar);
1119
1120 /*
1121 * Like drawBitmapRect but we manually draw each pixels in RGB
1122 */
1123 static void show_lcd_grid(SkCanvas* canvas, const SkBitmap& bitmap,
1124 const SkIRect& origSrc, const SkRect& dst) {
1125 SkIRect src;
1126 if (!src.intersect(origSrc, bitmap.bounds())) {
1127 return;
1128 }
1129 const SkScalar sx = dst.width() / src.width();
1130 const SkScalar sy = dst.height() / src.height();
1131
1132 SkAutoCanvasRestore acr(canvas, true);
1133 canvas->translate(dst.left(), dst.top());
1134 canvas->scale(sx, sy);
1135
1136 ShowLCDProc proc = show_lcd_box;
1137 if (true) {
1138 proc = show_lcd_circle;
1139 }
1140
1141 for (int y = 0; y < src.height(); ++y) {
1142 for (int x = 0; x < src.width(); ++x) {
1143 proc(canvas, SkIntToScalar(x), SkIntToScalar(y),
1144 bitmap.getColor(src.left() + x, src.top() + y), sx, sy);
1145 }
1146 }
1147 }
1148
1082 void SampleWindow::showZoomer(SkCanvas* canvas) { 1149 void SampleWindow::showZoomer(SkCanvas* canvas) {
1083 int count = canvas->save(); 1150 int count = canvas->save();
1084 canvas->resetMatrix(); 1151 canvas->resetMatrix();
1085 // Ensure the mouse position is on screen. 1152 // Ensure the mouse position is on screen.
1086 int width = SkScalarRoundToInt(this->width()); 1153 int width = SkScalarRoundToInt(this->width());
1087 int height = SkScalarRoundToInt(this->height()); 1154 int height = SkScalarRoundToInt(this->height());
1088 if (fMouseX >= width) fMouseX = width - 1; 1155 if (fMouseX >= width) fMouseX = width - 1;
1089 else if (fMouseX < 0) fMouseX = 0; 1156 else if (fMouseX < 0) fMouseX = 0;
1090 if (fMouseY >= height) fMouseY = height - 1; 1157 if (fMouseY >= height) fMouseY = height - 1;
1091 else if (fMouseY < 0) fMouseY = 0; 1158 else if (fMouseY < 0) fMouseY = 0;
1092 1159
1093 SkBitmap bitmap = capture_bitmap(canvas); 1160 SkBitmap bitmap = capture_bitmap(canvas);
1094 bitmap.lockPixels(); 1161 bitmap.lockPixels();
1095 1162
1096 // Find the size of the zoomed in view, forced to be odd, so the examine d pixel is in the middle. 1163 // Find the size of the zoomed in view, forced to be odd, so the examined pi xel is in the middle.
1097 int zoomedWidth = (width >> 1) | 1; 1164 int zoomedWidth = (width >> 1) | 1;
1098 int zoomedHeight = (height >> 1) | 1; 1165 int zoomedHeight = (height >> 1) | 1;
1099 SkIRect src; 1166 SkIRect src;
1100 src.set(0, 0, zoomedWidth / fFatBitsScale, zoomedHeight / fFatBitsScale) ; 1167 src.set(0, 0, zoomedWidth / fFatBitsScale, zoomedHeight / fFatBitsScale);
1101 src.offset(fMouseX - (src.width()>>1), fMouseY - (src.height()>>1)); 1168 src.offset(fMouseX - (src.width()>>1), fMouseY - (src.height()>>1));
1102 SkRect dest; 1169 SkRect dest;
1103 dest.set(0, 0, SkIntToScalar(zoomedWidth), SkIntToScalar(zoomedHeight)); 1170 dest.set(0, 0, SkIntToScalar(zoomedWidth), SkIntToScalar(zoomedHeight));
1104 dest.offset(SkIntToScalar(width - zoomedWidth), SkIntToScalar(height - z oomedHeight)); 1171 dest.offset(SkIntToScalar(width - zoomedWidth), SkIntToScalar(height - zoome dHeight));
1105 SkPaint paint; 1172 SkPaint paint;
1106 // Clear the background behind our zoomed in view 1173 // Clear the background behind our zoomed in view
1107 paint.setColor(SK_ColorWHITE); 1174 paint.setColor(SK_ColorWHITE);
1108 canvas->drawRect(dest, paint); 1175 canvas->drawRect(dest, paint);
1176 if (fFatBitsScale < kMaxFatBitsScale) {
1109 canvas->drawBitmapRect(bitmap, src, dest, NULL); 1177 canvas->drawBitmapRect(bitmap, src, dest, NULL);
1110 paint.setColor(SK_ColorBLACK); 1178 } else {
1111 paint.setStyle(SkPaint::kStroke_Style); 1179 show_lcd_grid(canvas, bitmap, src, dest);
1112 // Draw a border around the pixel in the middle 1180 }
1113 SkRect originalPixel; 1181
1114 originalPixel.set(SkIntToScalar(fMouseX), SkIntToScalar(fMouseY), SkIntT oScalar(fMouseX + 1), SkIntToScalar(fMouseY + 1)); 1182 paint.setColor(SK_ColorBLACK);
1115 SkMatrix matrix; 1183 paint.setStyle(SkPaint::kStroke_Style);
1116 SkRect scalarSrc; 1184 // Draw a border around the pixel in the middle
1117 scalarSrc.set(src); 1185 SkRect originalPixel;
1118 SkColor color = bitmap.getColor(fMouseX, fMouseY); 1186 originalPixel.set(SkIntToScalar(fMouseX), SkIntToScalar(fMouseY), SkIntToSca lar(fMouseX + 1), SkIntToScalar(fMouseY + 1));
1119 if (matrix.setRectToRect(scalarSrc, dest, SkMatrix::kFill_ScaleToFit)) { 1187 SkMatrix matrix;
1120 SkRect pixel; 1188 SkRect scalarSrc;
1121 matrix.mapRect(&pixel, originalPixel); 1189 scalarSrc.set(src);
1122 // TODO Perhaps measure the values and make the outline white if it' s "dark" 1190 SkColor color = bitmap.getColor(fMouseX, fMouseY);
1123 if (color == SK_ColorBLACK) { 1191 if (matrix.setRectToRect(scalarSrc, dest, SkMatrix::kFill_ScaleToFit)) {
1124 paint.setColor(SK_ColorWHITE); 1192 SkRect pixel;
1125 } 1193 matrix.mapRect(&pixel, originalPixel);
1126 canvas->drawRect(pixel, paint); 1194 // TODO Perhaps measure the values and make the outline white if it's "d ark"
1195 if (color == SK_ColorBLACK) {
1196 paint.setColor(SK_ColorWHITE);
1127 } 1197 }
1128 paint.setColor(SK_ColorBLACK); 1198 canvas->drawRect(pixel, paint);
1129 // Draw a border around the destination rectangle 1199 }
1130 canvas->drawRect(dest, paint); 1200 paint.setColor(SK_ColorBLACK);
1131 paint.setStyle(SkPaint::kStrokeAndFill_Style); 1201 // Draw a border around the destination rectangle
1132 // Identify the pixel and its color on screen 1202 canvas->drawRect(dest, paint);
1133 paint.setTypeface(fTypeface); 1203 paint.setStyle(SkPaint::kStrokeAndFill_Style);
1134 paint.setAntiAlias(true); 1204 // Identify the pixel and its color on screen
1135 SkScalar lineHeight = paint.getFontMetrics(NULL); 1205 paint.setTypeface(fTypeface);
1136 SkString string; 1206 paint.setAntiAlias(true);
1137 string.appendf("(%i, %i)", fMouseX, fMouseY); 1207 SkScalar lineHeight = paint.getFontMetrics(NULL);
1138 SkScalar left = dest.fLeft + SkIntToScalar(3); 1208 SkString string;
1139 SkScalar i = SK_Scalar1; 1209 string.appendf("(%i, %i)", fMouseX, fMouseY);
1140 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); 1210 SkScalar left = dest.fLeft + SkIntToScalar(3);
1141 // Alpha 1211 SkScalar i = SK_Scalar1;
1142 i += SK_Scalar1; 1212 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), pai nt);
1143 string.reset(); 1213 // Alpha
1144 string.appendf("A: %X", SkColorGetA(color)); 1214 i += SK_Scalar1;
1145 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); 1215 string.reset();
1146 // Red 1216 string.appendf("A: %X", SkColorGetA(color));
1147 i += SK_Scalar1; 1217 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), pai nt);
1148 string.reset(); 1218 // Red
1149 string.appendf("R: %X", SkColorGetR(color)); 1219 i += SK_Scalar1;
1150 paint.setColor(SK_ColorRED); 1220 string.reset();
1151 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); 1221 string.appendf("R: %X", SkColorGetR(color));
1152 // Green 1222 paint.setColor(SK_ColorRED);
1153 i += SK_Scalar1; 1223 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), pai nt);
1154 string.reset(); 1224 // Green
1155 string.appendf("G: %X", SkColorGetG(color)); 1225 i += SK_Scalar1;
1156 paint.setColor(SK_ColorGREEN); 1226 string.reset();
1157 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); 1227 string.appendf("G: %X", SkColorGetG(color));
1158 // Blue 1228 paint.setColor(SK_ColorGREEN);
1159 i += SK_Scalar1; 1229 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), pai nt);
1160 string.reset(); 1230 // Blue
1161 string.appendf("B: %X", SkColorGetB(color)); 1231 i += SK_Scalar1;
1162 paint.setColor(SK_ColorBLUE); 1232 string.reset();
1163 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); 1233 string.appendf("B: %X", SkColorGetB(color));
1164 canvas->restoreToCount(count); 1234 paint.setColor(SK_ColorBLUE);
1235 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), pai nt);
1236 canvas->restoreToCount(count);
1165 } 1237 }
1166 1238
1167 void SampleWindow::onDraw(SkCanvas* canvas) { 1239 void SampleWindow::onDraw(SkCanvas* canvas) {
1168 } 1240 }
1169 1241
1170 #include "SkColorPriv.h" 1242 #include "SkColorPriv.h"
1171 1243
1172 void SampleWindow::saveToPdf() 1244 void SampleWindow::saveToPdf()
1173 { 1245 {
1174 #if SK_SUPPORT_PDF 1246 #if SK_SUPPORT_PDF
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 setenv("ANDROID_ROOT", "/android/device/data", 0); 2376 setenv("ANDROID_ROOT", "/android/device/data", 0);
2305 #endif 2377 #endif
2306 SkGraphics::Init(); 2378 SkGraphics::Init();
2307 SkEvent::Init(); 2379 SkEvent::Init();
2308 } 2380 }
2309 2381
2310 void application_term() { 2382 void application_term() {
2311 SkEvent::Term(); 2383 SkEvent::Term();
2312 SkGraphics::Term(); 2384 SkGraphics::Term();
2313 } 2385 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698