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

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

Issue 2163323002: Add desired width & height to drawContext (as opposed to using the width & height of the RT) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More Clean up 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 | « src/gpu/SkGpuDevice.h ('k') | src/image/SkSurface_Gpu.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 "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "GrBlurUtils.h" 10 #include "GrBlurUtils.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 default: // If it is unpremul or unknown don't try to render 120 default: // If it is unpremul or unknown don't try to render
121 return false; 121 return false;
122 } 122 }
123 } 123 }
124 if (kClear_InitContents == init) { 124 if (kClear_InitContents == init) {
125 *flags |= kNeedClear_Flag; 125 *flags |= kNeedClear_Flag;
126 } 126 }
127 return true; 127 return true;
128 } 128 }
129 129
130 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, const SkSurfacePr ops* props, 130 sk_sp<SkGpuDevice> SkGpuDevice::Make(int width, int height,
131 sk_sp<GrRenderTarget> rt, const SkSurfacePr ops* props,
131 InitContents init) { 132 InitContents init) {
132 if (!rt || rt->wasDestroyed() || !rt->getContext()) { 133 if (!rt || rt->wasDestroyed() || !rt->getContext()) {
133 return nullptr; 134 return nullptr;
134 } 135 }
135 unsigned flags; 136 unsigned flags;
136 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { 137 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) {
137 return nullptr; 138 return nullptr;
138 } 139 }
139 140
140 const int width = rt->width();
141 const int height = rt->height();
142
143 GrContext* context = rt->getContext(); 141 GrContext* context = rt->getContext();
144 142
145 sk_sp<GrDrawContext> drawContext(context->drawContext(std::move(rt), props)) ; 143 sk_sp<GrDrawContext> drawContext(context->drawContext(width, height, std::mo ve(rt), props));
146 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, hei ght, flags)); 144 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), flags));
147 } 145 }
148 146
149 sk_sp<SkBaseDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, 147 sk_sp<SkBaseDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext,
150 int width, int height,
151 InitContents init) { 148 InitContents init) {
152 if (!drawContext || drawContext->wasAbandoned()) { 149 if (!drawContext || drawContext->wasAbandoned()) {
153 return nullptr; 150 return nullptr;
154 } 151 }
155 unsigned flags; 152 unsigned flags;
156 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { 153 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) {
157 return nullptr; 154 return nullptr;
158 } 155 }
159 return sk_sp<SkBaseDevice>(new SkGpuDevice(std::move(drawContext), width, he ight, flags)); 156 return sk_sp<SkBaseDevice>(new SkGpuDevice(std::move(drawContext), flags));
160 } 157 }
161 158
162 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, 159 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted,
163 const SkImageInfo& info, int sampleCount, 160 const SkImageInfo& info, int sampleCount,
164 const SkSurfaceProps* props, InitContents i nit) { 161 const SkSurfaceProps* props, InitContents i nit) {
165 unsigned flags; 162 unsigned flags;
166 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { 163 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) {
167 return nullptr; 164 return nullptr;
168 } 165 }
169 166
170 sk_sp<GrDrawContext> drawContext(CreateDrawContext(context, budgeted, info, 167 sk_sp<GrDrawContext> drawContext(CreateDrawContext(context, budgeted, info,
171 sampleCount, props)); 168 sampleCount, props));
172 if (!drawContext) { 169 if (!drawContext) {
173 return nullptr; 170 return nullptr;
174 } 171 }
175 172
176 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), 173 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), flags));
177 info.width(), info.height(), flags ));
178 } 174 }
179 175
180 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height , unsigned flags) 176 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, unsigned flags)
181 : INHERITED(drawContext->surfaceProps()) 177 : INHERITED(drawContext->surfaceProps())
182 , fContext(SkRef(drawContext->accessRenderTarget()->getContext())) 178 , fContext(SkRef(drawContext->accessRenderTarget()->getContext()))
183 , fRenderTarget(drawContext->renderTarget()) 179 , fRenderTarget(drawContext->renderTarget())
184 , fDrawContext(std::move(drawContext)) { 180 , fDrawContext(std::move(drawContext)) {
185 fOpaque = SkToBool(flags & kIsOpaque_Flag); 181 fOpaque = SkToBool(flags & kIsOpaque_Flag);
186 182
187 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; 183 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
188 SkImageInfo info = fRenderTarget->surfacePriv().info(at).makeWH(width, heigh t); 184 SkImageInfo info = fRenderTarget->surfacePriv().info(at).makeWH(fDrawContext ->width(),
185 fDrawContext ->height());
189 SkPixelRef* pr = new SkGrPixelRef(info, fRenderTarget.get()); 186 SkPixelRef* pr = new SkGrPixelRef(info, fRenderTarget.get());
190 fLegacyBitmap.setInfo(info); 187 fLegacyBitmap.setInfo(info);
191 fLegacyBitmap.setPixelRef(pr)->unref(); 188 fLegacyBitmap.setPixelRef(pr)->unref();
192 189
193 if (flags & kNeedClear_Flag) { 190 if (flags & kNeedClear_Flag) {
194 this->clearAll(); 191 this->clearAll();
195 } 192 }
196 } 193 }
197 194
198 sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context, 195 sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context,
199 SkBudgeted budgeted, 196 SkBudgeted budgeted,
200 const SkImageInfo& origInfo, 197 const SkImageInfo& origInfo,
201 int sampleCount, 198 int sampleCount,
202 const SkSurfaceProps* surfac eProps) { 199 const SkSurfaceProps* surfac eProps) {
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 if (!dc) { 1876 if (!dc) {
1880 SkErrorInternals::SetError( kInternalError_SkError, 1877 SkErrorInternals::SetError( kInternalError_SkError,
1881 "---- failed to create gpu device texture [% d %d]\n", 1878 "---- failed to create gpu device texture [% d %d]\n",
1882 cinfo.fInfo.width(), cinfo.fInfo.height()); 1879 cinfo.fInfo.width(), cinfo.fInfo.height());
1883 return nullptr; 1880 return nullptr;
1884 } 1881 }
1885 1882
1886 // Skia's convention is to only clear a device if it is non-opaque. 1883 // Skia's convention is to only clear a device if it is non-opaque.
1887 InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_I nitContents; 1884 InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_I nitContents;
1888 1885
1889 return SkGpuDevice::Make(std::move(dc), 1886 return SkGpuDevice::Make(std::move(dc), init).release();
1890 cinfo.fInfo.width(), cinfo.fInfo.height(),
1891 init).release();
1892 } 1887 }
1893 1888
1894 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa ceProps& props) { 1889 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa ceProps& props) {
1895 ASSERT_SINGLE_OWNER 1890 ASSERT_SINGLE_OWNER
1896 // TODO: Change the signature of newSurface to take a budgeted parameter. 1891 // TODO: Change the signature of newSurface to take a budgeted parameter.
1897 static const SkBudgeted kBudgeted = SkBudgeted::kNo; 1892 static const SkBudgeted kBudgeted = SkBudgeted::kNo;
1898 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext-> desc().fSampleCnt, 1893 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext-> desc().fSampleCnt,
1899 &props); 1894 &props);
1900 } 1895 }
1901 1896
1902 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { 1897 SkImageFilterCache* SkGpuDevice::getImageFilterCache() {
1903 ASSERT_SINGLE_OWNER 1898 ASSERT_SINGLE_OWNER
1904 // We always return a transient cache, so it is freed after each 1899 // We always return a transient cache, so it is freed after each
1905 // filter traversal. 1900 // filter traversal.
1906 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); 1901 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize);
1907 } 1902 }
1908 1903
1909 #endif 1904 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698