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

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 1476563002: Remove SkDrawProcs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add back skdraw Created 5 years 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 | « src/gpu/SkGpuDevice.h ('k') | 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 "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "GrBlurUtils.h" 10 #include "GrBlurUtils.h"
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "SkDraw.h"
12 #include "GrDrawContext.h" 13 #include "GrDrawContext.h"
13 #include "GrFontScaler.h" 14 #include "GrFontScaler.h"
14 #include "GrGpu.h" 15 #include "GrGpu.h"
15 #include "GrGpuResourcePriv.h" 16 #include "GrGpuResourcePriv.h"
16 #include "GrImageIDTextureAdjuster.h" 17 #include "GrImageIDTextureAdjuster.h"
17 #include "GrLayerHoister.h" 18 #include "GrLayerHoister.h"
18 #include "GrRecordReplaceDraw.h" 19 #include "GrRecordReplaceDraw.h"
19 #include "GrStrokeInfo.h" 20 #include "GrStrokeInfo.h"
20 #include "GrTextContext.h" 21 #include "GrTextContext.h"
21 #include "GrTracing.h" 22 #include "GrTracing.h"
22 #include "SkCanvasPriv.h" 23 #include "SkCanvasPriv.h"
23 #include "SkDrawProcs.h"
24 #include "SkErrorInternals.h" 24 #include "SkErrorInternals.h"
25 #include "SkGlyphCache.h" 25 #include "SkGlyphCache.h"
26 #include "SkGrTexturePixelRef.h" 26 #include "SkGrTexturePixelRef.h"
27 #include "SkGr.h" 27 #include "SkGr.h"
28 #include "SkGrPriv.h" 28 #include "SkGrPriv.h"
29 #include "SkImage_Base.h" 29 #include "SkImage_Base.h"
30 #include "SkImageFilter.h" 30 #include "SkImageFilter.h"
31 #include "SkLayerInfo.h" 31 #include "SkLayerInfo.h"
32 #include "SkMaskFilter.h" 32 #include "SkMaskFilter.h"
33 #include "SkNinePatchIter.h" 33 #include "SkNinePatchIter.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return fTexture.get(); 106 return fTexture.get();
107 } 107 }
108 } 108 }
109 109
110 private: 110 private:
111 SkAutoTUnref<GrTexture> fTexture; 111 SkAutoTUnref<GrTexture> fTexture;
112 }; 112 };
113 113
114 /////////////////////////////////////////////////////////////////////////////// 114 ///////////////////////////////////////////////////////////////////////////////
115 115
116 struct GrSkDrawProcs : public SkDrawProcs {
117 public:
118 GrContext* fContext;
119 GrTextContext* fTextContext;
120 GrFontScaler* fFontScaler; // cached in the skia glyphcache
121 };
122
123 ///////////////////////////////////////////////////////////////////////////////
124
125 /** Checks that the alpha type is legal and gets constructor flags. Returns fals e if device creation 116 /** Checks that the alpha type is legal and gets constructor flags. Returns fals e if device creation
126 should fail. */ 117 should fail. */
127 bool SkGpuDevice::CheckAlphaTypeAndGetFlags( 118 bool SkGpuDevice::CheckAlphaTypeAndGetFlags(
128 const SkImageInfo* info, SkGpuDevice::InitContents init, unsigned* flags) { 119 const SkImageInfo* info, SkGpuDevice::InitContents init, unsigned* flags) {
129 *flags = 0; 120 *flags = 0;
130 if (info) { 121 if (info) {
131 switch (info->alphaType()) { 122 switch (info->alphaType()) {
132 case kPremul_SkAlphaType: 123 case kPremul_SkAlphaType:
133 break; 124 break;
134 case kOpaque_SkAlphaType: 125 case kOpaque_SkAlphaType:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return nullptr; 165 return nullptr;
175 } 166 }
176 167
177 return new SkGpuDevice(rt, info.width(), info.height(), props, flags); 168 return new SkGpuDevice(rt, info.width(), info.height(), props, flags);
178 } 169 }
179 170
180 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, 171 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
181 const SkSurfaceProps* props, unsigned flags) 172 const SkSurfaceProps* props, unsigned flags)
182 : INHERITED(SkSurfacePropsCopyOrDefault(props)) 173 : INHERITED(SkSurfacePropsCopyOrDefault(props))
183 { 174 {
184 fDrawProcs = nullptr;
185
186 fContext = SkRef(rt->getContext()); 175 fContext = SkRef(rt->getContext());
187 fNeedClear = SkToBool(flags & kNeedClear_Flag); 176 fNeedClear = SkToBool(flags & kNeedClear_Flag);
188 fOpaque = SkToBool(flags & kIsOpaque_Flag); 177 fOpaque = SkToBool(flags & kIsOpaque_Flag);
189 178
190 fRenderTarget = SkRef(rt); 179 fRenderTarget = SkRef(rt);
191 180
192 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; 181 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
193 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); 182 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height);
194 SkPixelRef* pr = new SkGrPixelRef(info, rt); 183 SkPixelRef* pr = new SkGrPixelRef(info, rt);
195 fLegacyBitmap.setInfo(info); 184 fLegacyBitmap.setInfo(info);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 GrTexture* texture = context->textureProvider()->createTexture( 220 GrTexture* texture = context->textureProvider()->createTexture(
232 desc, SkToBool(budgeted), nullptr, 0); 221 desc, SkToBool(budgeted), nullptr, 0);
233 if (nullptr == texture) { 222 if (nullptr == texture) {
234 return nullptr; 223 return nullptr;
235 } 224 }
236 SkASSERT(nullptr != texture->asRenderTarget()); 225 SkASSERT(nullptr != texture->asRenderTarget());
237 return texture->asRenderTarget(); 226 return texture->asRenderTarget();
238 } 227 }
239 228
240 SkGpuDevice::~SkGpuDevice() { 229 SkGpuDevice::~SkGpuDevice() {
241 if (fDrawProcs) {
242 delete fDrawProcs;
243 }
244
245 fRenderTarget->unref(); 230 fRenderTarget->unref();
246 fContext->unref(); 231 fContext->unref();
247 } 232 }
248 233
249 /////////////////////////////////////////////////////////////////////////////// 234 ///////////////////////////////////////////////////////////////////////////////
250 235
251 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes, 236 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes,
252 int x, int y) { 237 int x, int y) {
253 DO_DEFERRED_CLEAR(); 238 DO_DEFERRED_CLEAR();
254 239
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 }; 382 };
398 383
399 // suppress antialiasing on axis-aligned integer-coordinate lines 384 // suppress antialiasing on axis-aligned integer-coordinate lines
400 static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkP oint pts[]) { 385 static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkP oint pts[]) {
401 if (mode == SkCanvas::PointMode::kPoints_PointMode) { 386 if (mode == SkCanvas::PointMode::kPoints_PointMode) {
402 return false; 387 return false;
403 } 388 }
404 if (count == 2) { 389 if (count == 2) {
405 // We do not antialias as long as the primary axis of the line is intege r-aligned, even if 390 // We do not antialias as long as the primary axis of the line is intege r-aligned, even if
406 // the other coordinates are not. This does mean the two end pixels of t he line will be 391 // the other coordinates are not. This does mean the two end pixels of t he line will be
407 // sharp even when they shouldn't be, but turning antialiasing on (as th ings stand 392 // sharp even when they shouldn't be, but turning antialiasing on (as th ings stand
408 // currently) means that the line will turn into a two-pixel-wide blur. While obviously a 393 // currently) means that the line will turn into a two-pixel-wide blur. While obviously a
409 // more complete fix is possible down the road, for the time being we ac cept the error on 394 // more complete fix is possible down the road, for the time being we ac cept the error on
410 // the two end pixels as being the lesser of two evils. 395 // the two end pixels as being the lesser of two evils.
411 if (pts[0].fX == pts[1].fX) { 396 if (pts[0].fX == pts[1].fX) {
412 return ((int) pts[0].fX) != pts[0].fX; 397 return ((int) pts[0].fX) != pts[0].fX;
413 } 398 }
414 if (pts[0].fY == pts[1].fY) { 399 if (pts[0].fY == pts[1].fY) {
415 return ((int) pts[0].fY) != pts[0].fY; 400 return ((int) pts[0].fY) != pts[0].fY;
416 } 401 }
417 } 402 }
418 return true; 403 return true;
419 } 404 }
(...skipping 17 matching lines...) Expand all
437 SkPath path; 422 SkPath path;
438 path.setIsVolatile(true); 423 path.setIsVolatile(true);
439 path.moveTo(pts[0]); 424 path.moveTo(pts[0]);
440 path.lineTo(pts[1]); 425 path.lineTo(pts[1]);
441 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, strokeInfo); 426 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, strokeInfo);
442 return; 427 return;
443 } 428 }
444 429
445 // we only handle non-antialiased hairlines and paints without path effects or mask filters, 430 // we only handle non-antialiased hairlines and paints without path effects or mask filters,
446 // else we let the SkDraw call our drawPath() 431 // else we let the SkDraw call our drawPath()
447 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || 432 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() ||
448 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { 433 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) {
449 draw.drawPoints(mode, count, pts, paint, true); 434 draw.drawPoints(mode, count, pts, paint, true);
450 return; 435 return;
451 } 436 }
452 437
453 GrPaint grPaint; 438 GrPaint grPaint;
454 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { 439 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
455 return; 440 return;
456 } 441 }
457 442
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 CHECK_FOR_ANNOTATION(paint); 603 CHECK_FOR_ANNOTATION(paint);
619 CHECK_SHOULD_DRAW(draw); 604 CHECK_SHOULD_DRAW(draw);
620 605
621 // Presumably the path effect warps this to something other than an oval 606 // Presumably the path effect warps this to something other than an oval
622 if (paint.getPathEffect()) { 607 if (paint.getPathEffect()) {
623 SkPath path; 608 SkPath path;
624 path.setIsVolatile(true); 609 path.setIsVolatile(true);
625 path.addOval(oval); 610 path.addOval(oval);
626 this->drawPath(draw, path, paint, nullptr, true); 611 this->drawPath(draw, path, paint, nullptr, true);
627 return; 612 return;
628 } 613 }
629 614
630 if (paint.getMaskFilter()) { 615 if (paint.getMaskFilter()) {
631 // The RRect path can handle special case blurring 616 // The RRect path can handle special case blurring
632 SkRRect rr = SkRRect::MakeOval(oval); 617 SkRRect rr = SkRRect::MakeOval(oval);
633 return this->drawRRect(draw, rr, paint); 618 return this->drawRRect(draw, rr, paint);
634 } 619 }
635 620
636 GrPaint grPaint; 621 GrPaint grPaint;
637 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { 622 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) {
638 return; 623 return;
639 } 624 }
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS Xform xform[], 1666 void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS Xform xform[],
1682 const SkRect texRect[], const SkColor colors[], int count, 1667 const SkRect texRect[], const SkColor colors[], int count,
1683 SkXfermode::Mode mode, const SkPaint& paint) { 1668 SkXfermode::Mode mode, const SkPaint& paint) {
1684 if (paint.isAntiAlias()) { 1669 if (paint.isAntiAlias()) {
1685 this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, m ode, paint); 1670 this->INHERITED::drawAtlas(draw, atlas, xform, texRect, colors, count, m ode, paint);
1686 return; 1671 return;
1687 } 1672 }
1688 1673
1689 CHECK_SHOULD_DRAW(draw); 1674 CHECK_SHOULD_DRAW(draw);
1690 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); 1675 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
1691 1676
1692 SkPaint p(paint); 1677 SkPaint p(paint);
1693 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode))->unref(); 1678 p.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode))->unref();
1694 1679
1695 GrPaint grPaint; 1680 GrPaint grPaint;
1696 if (colors) { 1681 if (colors) {
1697 if (!SkPaintToGrPaintWithXfermode(this->context(), p, *draw.fMatrix, mod e, true, 1682 if (!SkPaintToGrPaintWithXfermode(this->context(), p, *draw.fMatrix, mod e, true,
1698 &grPaint)) { 1683 &grPaint)) {
1699 return; 1684 return;
1700 } 1685 }
1701 } else { 1686 } else {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1867 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1883 } 1868 }
1884 1869
1885 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1870 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1886 // We always return a transient cache, so it is freed after each 1871 // We always return a transient cache, so it is freed after each
1887 // filter traversal. 1872 // filter traversal.
1888 return SkGpuDevice::NewImageFilterCache(); 1873 return SkGpuDevice::NewImageFilterCache();
1889 } 1874 }
1890 1875
1891 #endif 1876 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698