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

Side by Side Diff: src/image/SkImageShader.cpp

Issue 1375673002: Revert of Revert[2] of add ImageShader, sharing code with its Bitmap cousin (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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 | « src/image/SkImageShader.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBitmapProcShader.h"
9 #include "SkBitmapProvider.h"
10 #include "SkImage_Base.h"
11 #include "SkImageShader.h"
12 #include "SkReadBuffer.h"
13 #include "SkWriteBuffer.h"
14
15 SkImageShader::SkImageShader(const SkImage* img, TileMode tmx, TileMode tmy, con st SkMatrix* matrix)
16 : INHERITED(matrix)
17 , fImage(SkRef(img))
18 , fTileModeX(tmx)
19 , fTileModeY(tmy)
20 {}
21
22 SkFlattenable* SkImageShader::CreateProc(SkReadBuffer& buffer) {
23 const TileMode tx = (TileMode)buffer.readUInt();
24 const TileMode ty = (TileMode)buffer.readUInt();
25 SkMatrix matrix;
26 buffer.readMatrix(&matrix);
27 SkAutoTUnref<SkImage> img(buffer.readImage());
28 if (!img) {
29 return nullptr;
30 }
31 return new SkImageShader(img, tx, ty, &matrix);
32 }
33
34 void SkImageShader::flatten(SkWriteBuffer& buffer) const {
35 buffer.writeUInt(fTileModeX);
36 buffer.writeUInt(fTileModeY);
37 buffer.writeMatrix(this->getLocalMatrix());
38 buffer.writeImage(fImage);
39 }
40
41 bool SkImageShader::isOpaque() const {
42 return fImage->isOpaque();
43 }
44
45 size_t SkImageShader::contextSize() const {
46 return SkBitmapProcShader::ContextSize();
47 }
48
49 SkShader::Context* SkImageShader::onCreateContext(const ContextRec& rec, void* s torage) const {
50 return SkBitmapProcShader::MakeContext(*this, fTileModeX, fTileModeY,
51 SkBitmapProvider(fImage), rec, storag e);
52 }
53
54 SkShader* SkImageShader::Create(const SkImage* image, TileMode tx, TileMode ty,
55 const SkMatrix* localMatrix) {
56 if (!image) {
57 return nullptr;
58 }
59 return new SkImageShader(image, tx, ty, localMatrix);
60 }
61
62 #ifndef SK_IGNORE_TO_STRING
63 void SkImageShader::toString(SkString* str) const {
64 const char* gTileModeName[SkShader::kTileModeCount] = {
65 "clamp", "repeat", "mirror"
66 };
67
68 str->appendf("ImageShader: ((%s %s) ", gTileModeName[fTileModeX], gTileModeN ame[fTileModeY]);
69 fImage->toString(str);
70 this->INHERITED::toString(str);
71 str->append(")");
72 }
73 #endif
74
75 //////////////////////////////////////////////////////////////////////////////// ///////////////////
76
77 #if SK_SUPPORT_GPU
78
79 #include "GrTextureAccess.h"
80 #include "SkGr.h"
81 #include "effects/GrSimpleTextureEffect.h"
82 #include "effects/GrBicubicEffect.h"
83 #include "effects/GrSimpleTextureEffect.h"
84
85 const GrFragmentProcessor* SkImageShader::asFragmentProcessor(GrContext* context ,
86 const SkMatrix& vi ewM,
87 const SkMatrix* lo calMatrix,
88 SkFilterQuality fi lterQuality,
89 GrProcessorDataMan ager* mgr) const {
90 SkMatrix matrix;
91 matrix.setIDiv(fImage->width(), fImage->height());
92
93 SkMatrix lmInverse;
94 if (!this->getLocalMatrix().invert(&lmInverse)) {
95 return nullptr;
96 }
97 if (localMatrix) {
98 SkMatrix inv;
99 if (!localMatrix->invert(&inv)) {
100 return nullptr;
101 }
102 lmInverse.postConcat(inv);
103 }
104 matrix.preConcat(lmInverse);
105
106 SkShader::TileMode tm[] = { fTileModeX, fTileModeY };
107
108 // Must set wrap and filter on the sampler before requesting a texture. In t wo places below
109 // we check the matrix scale factors to determine how to interpret the filte r quality setting.
110 // This completely ignores the complexity of the drawVertices case where exp licit local coords
111 // are provided by the caller.
112 bool doBicubic;
113 GrTextureParams::FilterMode textureFilterMode =
114 GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix() , &doBicubic);
115 GrTextureParams params(tm, textureFilterMode);
116
117 SkImageUsageType usageType;
118 if (kClamp_TileMode == fTileModeX && kClamp_TileMode == fTileModeY) {
119 usageType = kUntiled_SkImageUsageType;
120 } else if (GrTextureParams::kNone_FilterMode == textureFilterMode) {
121 usageType = kTiled_Unfiltered_SkImageUsageType;
122 } else {
123 usageType = kTiled_Filtered_SkImageUsageType;
124 }
125
126 SkAutoTUnref<GrTexture> texture(as_IB(fImage)->asTextureRef(context, usageTy pe));
127 if (!texture) {
128 return nullptr;
129 }
130
131 SkAutoTUnref<GrFragmentProcessor> inner;
132 if (doBicubic) {
133 inner.reset(GrBicubicEffect::Create(mgr, texture, matrix, tm));
134 } else {
135 inner.reset(GrSimpleTextureEffect::Create(mgr, texture, matrix, params)) ;
136 }
137
138 if (GrPixelConfigIsAlphaOnly(texture->config())) {
139 return SkRef(inner.get());
140 }
141 return GrFragmentProcessor::MulOuputByInputAlpha(inner);
142 }
143
144 #endif
OLDNEW
« no previous file with comments | « src/image/SkImageShader.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698