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

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

Issue 2158383002: Start from DC rather than texture in GrTexutreParamsAdjuster copy code. (Closed) Base URL: https://chromium.googlesource.com/skia.git@readpixdc
Patch Set: Address comment Created 4 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
« 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 2015 Google Inc. 2 * Copyright 2015 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 "GrTextureParamsAdjuster.h" 8 #include "GrTextureParamsAdjuster.h"
9 9
10 #include "GrCaps.h" 10 #include "GrCaps.h"
(...skipping 17 matching lines...) Expand all
28 28
29 ////////////////////////////////////////////////////////////////////////////// 29 //////////////////////////////////////////////////////////////////////////////
30 30
31 static GrTexture* copy_on_gpu(GrTexture* inputTexture, const SkIRect* subset, 31 static GrTexture* copy_on_gpu(GrTexture* inputTexture, const SkIRect* subset,
32 const CopyParams& copyParams) { 32 const CopyParams& copyParams) {
33 SkASSERT(!subset || !subset->isEmpty()); 33 SkASSERT(!subset || !subset->isEmpty());
34 GrContext* context = inputTexture->getContext(); 34 GrContext* context = inputTexture->getContext();
35 SkASSERT(context); 35 SkASSERT(context);
36 const GrCaps* caps = context->caps(); 36 const GrCaps* caps = context->caps();
37 37
38 // Either it's a cache miss or the original wasn't cached to begin with. 38 GrPixelConfig config = GrMakePixelConfigUncompressed(inputTexture->config()) ;
39 GrSurfaceDesc rtDesc = inputTexture->desc();
40 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag;
41 rtDesc.fWidth = copyParams.fWidth;
42 rtDesc.fHeight = copyParams.fHeight;
43 rtDesc.fConfig = GrMakePixelConfigUncompressed(rtDesc.fConfig);
44 39
45 // If the config isn't renderable try converting to either A8 or an 32 bit c onfig. Otherwise, 40 // If the config isn't renderable try converting to either A8 or an 32 bit c onfig. Otherwise,
46 // fail. 41 // fail.
47 if (!caps->isConfigRenderable(rtDesc.fConfig, false)) { 42 if (!caps->isConfigRenderable(config, false)) {
48 if (GrPixelConfigIsAlphaOnly(rtDesc.fConfig)) { 43 if (GrPixelConfigIsAlphaOnly(config)) {
49 if (caps->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { 44 if (caps->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
50 rtDesc.fConfig = kAlpha_8_GrPixelConfig; 45 config = kAlpha_8_GrPixelConfig;
51 } else if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) { 46 } else if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
52 rtDesc.fConfig = kSkia8888_GrPixelConfig; 47 config = kSkia8888_GrPixelConfig;
53 } else { 48 } else {
54 return nullptr; 49 return nullptr;
55 } 50 }
56 } else if (kRGB_GrColorComponentFlags == 51 } else if (kRGB_GrColorComponentFlags ==
57 (kRGB_GrColorComponentFlags & GrPixelConfigComponentMask(rtDe sc.fConfig))) { 52 (kRGB_GrColorComponentFlags & GrPixelConfigComponentMask(config) )) {
58 if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) { 53 if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
59 rtDesc.fConfig = kSkia8888_GrPixelConfig; 54 config = kSkia8888_GrPixelConfig;
60 } else { 55 } else {
61 return nullptr; 56 return nullptr;
62 } 57 }
63 } else { 58 } else {
64 return nullptr; 59 return nullptr;
65 } 60 }
66 } 61 }
67 62
68 SkAutoTUnref<GrTexture> copy(context->textureProvider()->createTexture(rtDes c, 63 sk_sp<GrDrawContext> copyDC = context->newDrawContext(SkBackingFit::kExact, copyParams.fWidth,
69 SkBud geted::kYes)); 64 copyParams.fHeight, co nfig);
70 if (!copy) { 65 if (!copyDC) {
71 return nullptr; 66 return nullptr;
72 } 67 }
73 68
74 // TODO: If no scaling is being performed then use copySurface.
75
76 GrPaint paint; 69 GrPaint paint;
77 paint.setGammaCorrect(true); 70 paint.setGammaCorrect(true);
78 71
79 // TODO: Initializing these values for no reason cause the compiler is compl aining 72 SkScalar sx SK_INIT_TO_AVOID_WARNING;
80 SkScalar sx = 0.f; 73 SkScalar sy SK_INIT_TO_AVOID_WARNING;
81 SkScalar sy = 0.f;
82 if (subset) { 74 if (subset) {
83 sx = 1.f / inputTexture->width(); 75 sx = 1.f / inputTexture->width();
84 sy = 1.f / inputTexture->height(); 76 sy = 1.f / inputTexture->height();
85 } 77 }
86 78
87 if (copyParams.fFilter != GrTextureParams::kNone_FilterMode && subset && 79 if (copyParams.fFilter != GrTextureParams::kNone_FilterMode && subset &&
88 (subset->width() != copyParams.fWidth || subset->height() != copyParams. fHeight)) { 80 (subset->width() != copyParams.fWidth || subset->height() != copyParams. fHeight)) {
89 SkRect domain; 81 SkRect domain;
90 domain.fLeft = (subset->fLeft + 0.5f) * sx; 82 domain.fLeft = (subset->fLeft + 0.5f) * sx;
91 domain.fTop = (subset->fTop + 0.5f)* sy; 83 domain.fTop = (subset->fTop + 0.5f)* sy;
(...skipping 16 matching lines...) Expand all
108 if (subset) { 100 if (subset) {
109 localRect = SkRect::Make(*subset); 101 localRect = SkRect::Make(*subset);
110 localRect.fLeft *= sx; 102 localRect.fLeft *= sx;
111 localRect.fTop *= sy; 103 localRect.fTop *= sy;
112 localRect.fRight *= sx; 104 localRect.fRight *= sx;
113 localRect.fBottom *= sy; 105 localRect.fBottom *= sy;
114 } else { 106 } else {
115 localRect = SkRect::MakeWH(1.f, 1.f); 107 localRect = SkRect::MakeWH(1.f, 1.f);
116 } 108 }
117 109
118 sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(copy->asRend erTarget()))); 110 SkRect dstRect = SkRect::MakeIWH(copyParams.fWidth, copyParams.fHeight);
119 if (!drawContext) { 111 copyDC->fillRectToRect(GrNoClip(), paint, SkMatrix::I(), dstRect, localRect) ;
120 return nullptr; 112 return copyDC->asTexture().release();
121 }
122
123 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar( rtDesc.fHeight));
124 drawContext->fillRectToRect(GrNoClip(), paint, SkMatrix::I(), dstRect, local Rect);
125 return copy.release();
126 } 113 }
127 114
128 GrTextureAdjuster::GrTextureAdjuster(GrTexture* original, 115 GrTextureAdjuster::GrTextureAdjuster(GrTexture* original,
129 const SkIRect& contentArea, 116 const SkIRect& contentArea,
130 bool isAlphaOnly) 117 bool isAlphaOnly)
131 : INHERITED(contentArea.width(), contentArea.height(), isAlphaOnly) 118 : INHERITED(contentArea.width(), contentArea.height(), isAlphaOnly)
132 , fOriginal(original) { 119 , fOriginal(original) {
133 SkASSERT(SkIRect::MakeWH(original->width(), original->height()).contains(con tentArea)); 120 SkASSERT(SkIRect::MakeWH(original->width(), original->height()).contains(con tentArea));
134 if (contentArea.fLeft > 0 || contentArea.fTop > 0 || 121 if (contentArea.fLeft > 0 || contentArea.fTop > 0 ||
135 contentArea.fRight < original->width() || contentArea.fBottom < original ->height()) { 122 contentArea.fRight < original->width() || contentArea.fBottom < original ->height()) {
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } 516 }
530 517
531 GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams , bool willBeMipped, 518 GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams , bool willBeMipped,
532 SkSourceGammaTreatment gamma Treatment) { 519 SkSourceGammaTreatment gamma Treatment) {
533 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(willBeMipped, gamm aTreatment)); 520 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(willBeMipped, gamm aTreatment));
534 if (!original) { 521 if (!original) {
535 return nullptr; 522 return nullptr;
536 } 523 }
537 return copy_on_gpu(original, nullptr, copyParams); 524 return copy_on_gpu(original, nullptr, copyParams);
538 } 525 }
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