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

Side by Side Diff: gm/image.cpp

Issue 583453002: SkCanvas::drawImage is the new way for drawing an SkImage to a Canvas (Closed) Base URL: https://skia.googlesource.com/skia.git@refactor_skImage
Patch Set: Make SkImage::draw public temporary for compatibility reasons Created 6 years, 2 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 | « gm/dftext.cpp ('k') | gm/multipicturedraw.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 * 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 "gm.h" 8 #include "gm.h"
9 #include "SkSurface.h" 9 #include "SkSurface.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 12 matching lines...) Expand all
23 SkAutoDataUnref data(SkData::NewFromFileName("/Users/mike/Downloads/skia.goo gle.jpeg")); 23 SkAutoDataUnref data(SkData::NewFromFileName("/Users/mike/Downloads/skia.goo gle.jpeg"));
24 if (NULL == data.get()) { 24 if (NULL == data.get()) {
25 return; 25 return;
26 } 26 }
27 SkImage* image = SkImage::NewFromGenerator( 27 SkImage* image = SkImage::NewFromGenerator(
28 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator: :Options())); 28 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator: :Options()));
29 if (image) { 29 if (image) {
30 SkAutoCanvasRestore acr(canvas, true); 30 SkAutoCanvasRestore acr(canvas, true);
31 canvas->scale(size.width() * 1.0f / image->width(), 31 canvas->scale(size.width() * 1.0f / image->width(),
32 size.height() * 1.0f / image->height()); 32 size.height() * 1.0f / image->height());
33 image->draw(canvas, 0, 0, NULL); 33 canvas->drawImage(image, 0, 0, NULL);
34 image->unref(); 34 image->unref();
35 } 35 }
36 } 36 }
37 37
38 static void drawContents(SkSurface* surface, SkColor fillC) { 38 static void drawContents(SkSurface* surface, SkColor fillC) {
39 SkSize size = SkSize::Make(SkIntToScalar(surface->width()), 39 SkSize size = SkSize::Make(SkIntToScalar(surface->width()),
40 SkIntToScalar(surface->height())); 40 SkIntToScalar(surface->height()));
41 SkCanvas* canvas = surface->getCanvas(); 41 SkCanvas* canvas = surface->getCanvas();
42 42
43 SkScalar stroke = size.fWidth / 10; 43 SkScalar stroke = size.fWidth / 10;
(...skipping 26 matching lines...) Expand all
70 70
71 // since we've drawn after we snapped imgR, imgG will be a different obj 71 // since we've drawn after we snapped imgR, imgG will be a different obj
72 SkASSERT(imgR != imgG); 72 SkASSERT(imgR != imgG);
73 73
74 drawContents(surf, SK_ColorBLUE); 74 drawContents(surf, SK_ColorBLUE);
75 75
76 SkPaint paint; 76 SkPaint paint;
77 // paint.setFilterBitmap(true); 77 // paint.setFilterBitmap(true);
78 // paint.setAlpha(0x80); 78 // paint.setAlpha(0x80);
79 79
80 imgR->draw(canvas, 0, 0, usePaint ? &paint : NULL); 80 canvas->drawImage(imgR, 0, 0, usePaint ? &paint : NULL);
81 imgG->draw(canvas, 0, 80, usePaint ? &paint : NULL); 81 canvas->drawImage(imgG, 0, 80, usePaint ? &paint : NULL);
82 surf->draw(canvas, 0, 160, usePaint ? &paint : NULL); 82 surf->draw(canvas, 0, 160, usePaint ? &paint : NULL);
83 83
84 SkRect src1, src2, src3; 84 SkRect src1, src2, src3;
85 src1.iset(0, 0, surf->width(), surf->height()); 85 src1.iset(0, 0, surf->width(), surf->height());
86 src2.iset(-surf->width() / 2, -surf->height() / 2, 86 src2.iset(-surf->width() / 2, -surf->height() / 2,
87 surf->width(), surf->height()); 87 surf->width(), surf->height());
88 src3.iset(0, 0, surf->width() / 2, surf->height() / 2); 88 src3.iset(0, 0, surf->width() / 2, surf->height() / 2);
89 89
90 SkRect dst1, dst2, dst3, dst4; 90 SkRect dst1, dst2, dst3, dst4;
91 dst1.set(0, 240, 65, 305); 91 dst1.set(0, 240, 65, 305);
92 dst2.set(0, 320, 65, 385); 92 dst2.set(0, 320, 65, 385);
93 dst3.set(0, 400, 65, 465); 93 dst3.set(0, 400, 65, 465);
94 dst4.set(0, 480, 65, 545); 94 dst4.set(0, 480, 65, 545);
95 95
96 imgR->draw(canvas, &src1, dst1, usePaint ? &paint : NULL); 96 canvas->drawImageRect(imgR, &src1, dst1, usePaint ? &paint : NULL);
97 imgG->draw(canvas, &src2, dst2, usePaint ? &paint : NULL); 97 canvas->drawImageRect(imgG, &src2, dst2, usePaint ? &paint : NULL);
98 imgR->draw(canvas, &src3, dst3, usePaint ? &paint : NULL); 98 canvas->drawImageRect(imgR, &src3, dst3, usePaint ? &paint : NULL);
99 imgG->draw(canvas, NULL, dst4, usePaint ? &paint : NULL); 99 canvas->drawImageRect(imgG, NULL, dst4, usePaint ? &paint : NULL);
100 100
101 imgG->unref(); 101 imgG->unref();
102 imgR->unref(); 102 imgR->unref();
103 } 103 }
104 104
105 class ImageGM : public skiagm::GM { 105 class ImageGM : public skiagm::GM {
106 void* fBuffer; 106 void* fBuffer;
107 size_t fBufferSize; 107 size_t fBufferSize;
108 SkSize fSize; 108 SkSize fSize;
109 enum { 109 enum {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 198 }
199 199
200 private: 200 private:
201 typedef skiagm::GM INHERITED; 201 typedef skiagm::GM INHERITED;
202 }; 202 };
203 203
204 ////////////////////////////////////////////////////////////////////////////// 204 //////////////////////////////////////////////////////////////////////////////
205 205
206 static skiagm::GM* MyFactory(void*) { return new ImageGM; } 206 static skiagm::GM* MyFactory(void*) { return new ImageGM; }
207 static skiagm::GMRegistry reg(MyFactory); 207 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « gm/dftext.cpp ('k') | gm/multipicturedraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698