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

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

Issue 1121813002: new image from backend desc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: reviewer comments Created 5 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/image/SkImage_Gpu.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 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 "SkImage_Gpu.h" 8 #include "SkImage_Gpu.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "GrContext.h" 10 #include "GrContext.h"
11 #include "SkGpuDevice.h"
11 12
12 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap, int sampleCountForNewSurfaces, 13 SkImage_Gpu::SkImage_Gpu(int w, int h, GrTexture* tex, int sampleCountForNewSurf aces,
13 SkSurface::Budgeted budgeted) 14 SkSurface::Budgeted budgeted)
14 : INHERITED(bitmap.width(), bitmap.height(), NULL) 15 : INHERITED(w, h, NULL)
15 , fBitmap(bitmap) 16 , fTexture(SkRef(tex))
16 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) 17 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces)
17 , fBudgeted(budgeted) 18 , fBudgeted(budgeted)
18 { 19 {}
19 SkASSERT(fBitmap.getTexture()); 20
21 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro ps& props) const {
22 GrTexture* tex = this->getTexture();
23 SkASSERT(tex);
24 GrContext* ctx = tex->getContext();
25 if (!ctx) {
26 // the texture may have been abandoned, so we have to check
27 return NULL;
28 }
29 // TODO: Change signature of onNewSurface to take a budgeted param.
30 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted;
31 return SkSurface::NewRenderTarget(ctx, budgeted, info, fSampleCountForNewSur faces, &props);
20 } 32 }
21 33
22 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, 34 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
23 SkShader::TileMode tileY, 35 if (image->getTexture()) {
24 const SkMatrix* localMatrix) const 36 ((SkImage_Gpu*)image)->applyBudgetDecision();
25 { 37 }
26 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix);
27 } 38 }
28 39
29 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro ps& props) const { 40 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
30 GrContext* ctx = this->getTexture()->getContext(); 41 const SkMatrix* localMatrix) const {
31 // TODO: Change signature of onNewSurface to take a budgeted param. 42 SkBitmap bm;
32 static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; 43 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu e(), &bm);
33 return SkSurface::NewRenderTarget(ctx, kBudgeted, info, fSampleCountForNewSu rfaces, &props); 44 return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix);
34 }
35
36 GrTexture* SkImage_Gpu::onGetTexture() const {
37 return fBitmap.getTexture();
38 } 45 }
39 46
40 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { 47 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
41 return fBitmap.copyTo(dst, kN32_SkColorType); 48 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e;
49 if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(), at))) {
50 return false;
51 }
52 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix elConfig,
53 dst->getPixels(), dst->rowBytes())) {
54 return false;
55 }
56 return true;
42 } 57 }
43 58
44 bool SkImage_Gpu::isOpaque() const { 59 bool SkImage_Gpu::isOpaque() const {
45 return fBitmap.isOpaque(); 60 return GrPixelConfigIsOpaque(fTexture->config());
46 } 61 }
47 62
48 /////////////////////////////////////////////////////////////////////////////// 63 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des c) {
49 64 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
50 SkImage* SkNewImageFromBitmapTexture(const SkBitmap& bitmap, int sampleCountForN ewSurfaces,
51 SkSurface::Budgeted budgeted) {
52 if (0 == bitmap.width() || 0 == bitmap.height() || NULL == bitmap.getTexture ()) {
53 return NULL; 65 return NULL;
54 } 66 }
55 return SkNEW_ARGS(SkImage_Gpu, (bitmap, sampleCountForNewSurfaces, budgeted) ); 67 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc) );
68 if (!tex) {
69 return NULL;
70 }
71 return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, tex, 0, SkSurface ::kNo_Budgeted));
56 } 72 }
57 73
58 GrTexture* SkTextureImageGetTexture(SkImage* image) { 74 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& srcDesc) {
59 return ((SkImage_Gpu*)image)->getTexture(); 75 if (srcDesc.fWidth <= 0 || srcDesc.fHeight <= 0) {
76 return NULL;
77 }
78 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture(srcDe sc));
79 if (!src) {
80 return NULL;
81 }
82
83 GrSurfaceDesc dstDesc;
84 dstDesc.fFlags = kNone_GrSurfaceFlags;
85 dstDesc.fOrigin = srcDesc.fOrigin;
86 dstDesc.fWidth = srcDesc.fWidth;
87 dstDesc.fHeight = srcDesc.fHeight;
88 dstDesc.fConfig = srcDesc.fConfig;
89 dstDesc.fSampleCnt = srcDesc.fSampleCnt;
90
91 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, t rue, NULL, 0));
92 if (!dst) {
93 return NULL;
94 }
95 if (!ctx->copySurface(dst, src)) {
bsalomon 2015/05/07 17:57:29 I think you want to pass kFlushWrites_PixelOp to e
reed1 2015/05/07 19:39:29 Done.
96 return NULL;
97 }
98 return SkNEW_ARGS(SkImage_Gpu,
99 (dstDesc.fWidth, dstDesc.fHeight, dst, 0, SkSurface::kYes_ Budgeted));
60 } 100 }
61
62 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
63 ((SkImage_Gpu*)image)->applyBudgetDecision();
64 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.h ('k') | src/image/SkSurface_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698