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

Side by Side Diff: src/core/SkSpecialSurface.cpp

Issue 1925313002: Tighten up SkSpecialSurface factory functions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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/core/SkSpecialSurface.h ('k') | tests/ImageFilterTest.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 2016 Google Inc. 2 * Copyright 2016 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkSpecialImage.h" 9 #include "SkSpecialImage.h"
10 #include "SkSpecialSurface.h" 10 #include "SkSpecialSurface.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 #if SK_SUPPORT_GPU 108 #if SK_SUPPORT_GPU
109 /////////////////////////////////////////////////////////////////////////////// 109 ///////////////////////////////////////////////////////////////////////////////
110 #include "GrContext.h" 110 #include "GrContext.h"
111 #include "SkGpuDevice.h" 111 #include "SkGpuDevice.h"
112 112
113 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { 113 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
114 public: 114 public:
115 SkSpecialSurface_Gpu(sk_sp<GrTexture> texture, 115 SkSpecialSurface_Gpu(sk_sp<GrTexture> texture,
116 int width, int height,
116 const SkIRect& subset, 117 const SkIRect& subset,
117 const SkSurfaceProps* props) 118 const SkSurfaceProps* props)
118 : INHERITED(subset, props) 119 : INHERITED(subset, props)
119 , fTexture(std::move(texture)) { 120 , fTexture(std::move(texture)) {
120 121
121 SkASSERT(fTexture->asRenderTarget()); 122 SkASSERT(fTexture->asRenderTarget());
122 123
123 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT arget(), props, 124 sk_sp<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderTarget() , width, height,
124 SkGpuDevice::kUnini t_InitContents)); 125 props,
126 SkGpuDevice::kUninit_InitC ontents));
125 if (!device) { 127 if (!device) {
126 return; 128 return;
127 } 129 }
128 130
129 fCanvas.reset(new SkCanvas(device)); 131 fCanvas.reset(new SkCanvas(device.get()));
130 fCanvas->clipRect(SkRect::Make(subset)); 132 fCanvas->clipRect(SkRect::Make(subset));
131 } 133 }
132 134
133 ~SkSpecialSurface_Gpu() override { } 135 ~SkSpecialSurface_Gpu() override { }
134 136
135 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { 137 sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
136 // Note: we are intentionally zeroing out 'fTexture' here 138 // Note: we are intentionally zeroing out 'fTexture' here
137 return SkSpecialImage::MakeFromGpu(this->subset(), 139 return SkSpecialImage::MakeFromGpu(this->subset(),
138 kNeedNewImageUniqueID_SpecialImage, 140 kNeedNewImageUniqueID_SpecialImage,
139 std::move(fTexture), 141 std::move(fTexture),
140 &this->props()); 142 &this->props());
141 } 143 }
142 144
143 private: 145 private:
144 sk_sp<GrTexture> fTexture; 146 sk_sp<GrTexture> fTexture;
145 147
146 typedef SkSpecialSurface_Base INHERITED; 148 typedef SkSpecialSurface_Base INHERITED;
147 }; 149 };
148 150
149 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset, 151 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
150 sk_sp<GrTexture> textu re, 152 int width, int height ,
151 const SkSurfaceProps* props) { 153 GrPixelConfig config) {
152 if (!texture->asRenderTarget()) { 154 if (!context) {
153 return nullptr; 155 return nullptr;
154 } 156 }
155 157
156 return sk_make_sp<SkSpecialSurface_Gpu>(std::move(texture), subset, props); 158 GrSurfaceDesc desc;
157 } 159 desc.fFlags = kRenderTarget_GrSurfaceFlag;
160 desc.fWidth = width;
161 desc.fHeight = height;
162 desc.fConfig = config;
158 163
159 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, 164 sk_sp<GrTexture> tex(context->textureProvider()->createApproxTexture(desc));
160 const GrSurfaceDesc& desc, 165 if (!tex) {
161 const SkSurfaceProps* props) {
162 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
163 return nullptr; 166 return nullptr;
164 } 167 }
165 168
166 sk_sp<GrTexture> temp(context->textureProvider()->createApproxTexture(desc)) ; 169 const SkIRect subset = SkIRect::MakeWH(width, height);
167 if (!temp) {
168 return nullptr;
169 }
170 170
171 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 171 return sk_make_sp<SkSpecialSurface_Gpu>(std::move(tex), width, height, subse t, nullptr);
172
173 return sk_make_sp<SkSpecialSurface_Gpu>(std::move(temp), subset, props);
174 } 172 }
175 173
176 #endif 174 #endif
OLDNEW
« no previous file with comments | « src/core/SkSpecialSurface.h ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698