OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkSurface_Gpu.h" | 8 #include "SkSurface_Gpu.h" |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkGpuDevice.h" | 11 #include "SkGpuDevice.h" |
12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
13 #include "SkImage_Gpu.h" | 13 #include "SkImage_Gpu.h" |
14 #include "SkImagePriv.h" | 14 #include "SkImagePriv.h" |
15 #include "SkSurface_Base.h" | 15 #include "SkSurface_Base.h" |
16 | 16 |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
18 | 18 |
19 /////////////////////////////////////////////////////////////////////////////// | |
20 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) | 19 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) |
21 : INHERITED(device->width(), device->height(), &device->surfaceProps()) | 20 : INHERITED(device->width(), device->height(), &device->surfaceProps()) |
22 , fDevice(SkRef(device)) { | 21 , fDevice(SkRef(device)) { |
23 } | 22 } |
24 | 23 |
25 SkSurface_Gpu::~SkSurface_Gpu() { | 24 SkSurface_Gpu::~SkSurface_Gpu() { |
26 fDevice->unref(); | 25 fDevice->unref(); |
27 } | 26 } |
28 | 27 |
29 static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, | 28 static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 72 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
74 int sampleCount = rt->numColorSamples(); | 73 int sampleCount = rt->numColorSamples(); |
75 // TODO: Make caller specify this (change virtual signature of onNewSurface)
. | 74 // TODO: Make caller specify this (change virtual signature of onNewSurface)
. |
76 static const Budgeted kBudgeted = kNo_Budgeted; | 75 static const Budgeted kBudgeted = kNo_Budgeted; |
77 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl
eCount, | 76 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl
eCount, |
78 &this->props()); | 77 &this->props()); |
79 } | 78 } |
80 | 79 |
81 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) { | 80 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) { |
82 const SkImageInfo info = fDevice->imageInfo(); | 81 const SkImageInfo info = fDevice->imageInfo(); |
83 const int sampleCount = fDevice->accessRenderTarget()->numColorSamples(); | |
84 SkImage* image = nullptr; | 82 SkImage* image = nullptr; |
85 GrTexture* tex = fDevice->accessRenderTarget()->asTexture(); | 83 GrTexture* tex = fDevice->accessRenderTarget()->asTexture(); |
86 if (tex) { | 84 if (tex) { |
87 image = new SkImage_Gpu(info.width(), info.height(), kNeedNewImageUnique
ID, | 85 image = new SkImage_Gpu(info.width(), info.height(), kNeedNewImageUnique
ID, |
88 info.alphaType(), tex, sampleCount, budgeted); | 86 info.alphaType(), tex, budgeted); |
89 } | 87 } |
90 if (image) { | 88 if (image) { |
91 as_IB(image)->initWithProps(this->props()); | 89 as_IB(image)->initWithProps(this->props()); |
92 } | 90 } |
93 return image; | 91 return image; |
94 } | 92 } |
95 | 93 |
96 // Create a new render target and, if necessary, copy the contents of the old | 94 // Create a new render target and, if necessary, copy the contents of the old |
97 // render target into it. Note that this flushes the SkGpuDevice but | 95 // render target into it. Note that this flushes the SkGpuDevice but |
98 // doesn't force an OpenGL flush. | 96 // doesn't force an OpenGL flush. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 166 } |
169 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, | 167 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, |
170 SkGpuDevice::kUninit_In
itContents)); | 168 SkGpuDevice::kUninit_In
itContents)); |
171 if (!device) { | 169 if (!device) { |
172 return nullptr; | 170 return nullptr; |
173 } | 171 } |
174 return new SkSurface_Gpu(device); | 172 return new SkSurface_Gpu(device); |
175 } | 173 } |
176 | 174 |
177 #endif | 175 #endif |
OLD | NEW |