| OLD | NEW |
| 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 "SkWindow.h" | 8 #include "SkWindow.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkOSMenu.h" | 10 #include "SkOSMenu.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 fMatrix.reset(); | 23 fMatrix.reset(); |
| 24 | 24 |
| 25 fBitmap.allocN32Pixels(0, 0); | 25 fBitmap.allocN32Pixels(0, 0); |
| 26 } | 26 } |
| 27 | 27 |
| 28 SkWindow::~SkWindow() { | 28 SkWindow::~SkWindow() { |
| 29 fClicks.deleteAll(); | 29 fClicks.deleteAll(); |
| 30 fMenus.deleteAll(); | 30 fMenus.deleteAll(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 SkSurface* SkWindow::createSurface() { | 33 sk_sp<SkSurface> SkWindow::makeSurface() { |
| 34 const SkBitmap& bm = this->getBitmap(); | 34 const SkBitmap& bm = this->getBitmap(); |
| 35 return SkSurface::MakeRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(), | 35 return SkSurface::MakeRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(),
&fSurfaceProps); |
| 36 &fSurfaceProps).release(); | |
| 37 } | 36 } |
| 38 | 37 |
| 39 void SkWindow::setMatrix(const SkMatrix& matrix) { | 38 void SkWindow::setMatrix(const SkMatrix& matrix) { |
| 40 if (fMatrix != matrix) { | 39 if (fMatrix != matrix) { |
| 41 fMatrix = matrix; | 40 fMatrix = matrix; |
| 42 this->inval(nullptr); | 41 this->inval(nullptr); |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 | 44 |
| 46 void SkWindow::preConcat(const SkMatrix& matrix) { | 45 void SkWindow::preConcat(const SkMatrix& matrix) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 SkScalarCeilToInt(this->width()), | 98 SkScalarCeilToInt(this->width()), |
| 100 SkScalarCeilToInt(this->height())); | 99 SkScalarCeilToInt(this->height())); |
| 101 } | 100 } |
| 102 | 101 |
| 103 #ifdef SK_SIMULATE_FAILED_MALLOC | 102 #ifdef SK_SIMULATE_FAILED_MALLOC |
| 104 extern bool gEnableControlledThrow; | 103 extern bool gEnableControlledThrow; |
| 105 #endif | 104 #endif |
| 106 | 105 |
| 107 bool SkWindow::update(SkIRect* updateArea) { | 106 bool SkWindow::update(SkIRect* updateArea) { |
| 108 if (!fDirtyRgn.isEmpty()) { | 107 if (!fDirtyRgn.isEmpty()) { |
| 109 SkAutoTUnref<SkSurface> surface(this->createSurface()); | 108 sk_sp<SkSurface> surface(this->makeSurface()); |
| 110 SkCanvas* canvas = surface->getCanvas(); | 109 SkCanvas* canvas = surface->getCanvas(); |
| 111 | 110 |
| 112 canvas->clipRegion(fDirtyRgn); | 111 canvas->clipRegion(fDirtyRgn); |
| 113 if (updateArea) { | 112 if (updateArea) { |
| 114 *updateArea = fDirtyRgn.getBounds(); | 113 *updateArea = fDirtyRgn.getBounds(); |
| 115 } | 114 } |
| 116 | 115 |
| 117 SkAutoCanvasRestore acr(canvas, true); | 116 SkAutoCanvasRestore acr(canvas, true); |
| 118 canvas->concat(fMatrix); | 117 canvas->concat(fMatrix); |
| 119 | 118 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 return handled; | 314 return handled; |
| 316 } | 315 } |
| 317 | 316 |
| 318 #if SK_SUPPORT_GPU | 317 #if SK_SUPPORT_GPU |
| 319 | 318 |
| 320 #include "GrContext.h" | 319 #include "GrContext.h" |
| 321 #include "gl/GrGLInterface.h" | 320 #include "gl/GrGLInterface.h" |
| 322 #include "gl/GrGLUtil.h" | 321 #include "gl/GrGLUtil.h" |
| 323 #include "SkGr.h" | 322 #include "SkGr.h" |
| 324 | 323 |
| 325 GrRenderTarget* SkWindow::renderTarget(const AttachmentInfo& attachmentInfo, | 324 sk_sp<SkSurface> SkWindow::makeGpuBackedSurface(const AttachmentInfo& attachment
Info, |
| 326 const GrGLInterface* interface, GrContext* grContext) { | 325 const GrGLInterface* interface, |
| 326 GrContext* grContext) { |
| 327 GrBackendRenderTargetDesc desc; | 327 GrBackendRenderTargetDesc desc; |
| 328 desc.fWidth = SkScalarRoundToInt(this->width()); | 328 desc.fWidth = SkScalarRoundToInt(this->width()); |
| 329 desc.fHeight = SkScalarRoundToInt(this->height()); | 329 desc.fHeight = SkScalarRoundToInt(this->height()); |
| 330 if (0 == desc.fWidth || 0 == desc.fHeight) { |
| 331 return nullptr; |
| 332 } |
| 333 |
| 330 // TODO: Query the actual framebuffer for sRGB capable. However, to | 334 // TODO: Query the actual framebuffer for sRGB capable. However, to |
| 331 // preserve old (fake-linear) behavior, we don't do this. Instead, rely | 335 // preserve old (fake-linear) behavior, we don't do this. Instead, rely |
| 332 // on the flag (currently driven via 'C' mode in SampleApp). | 336 // on the flag (currently driven via 'C' mode in SampleApp). |
| 333 // | 337 // |
| 334 // Also, we may not have real sRGB support (ANGLE, in particular), so check
for | 338 // Also, we may not have real sRGB support (ANGLE, in particular), so check
for |
| 335 // that, and fall back to L32: | 339 // that, and fall back to L32: |
| 336 // | 340 // |
| 337 // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversi
on on write, | 341 // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversi
on on write, |
| 338 // so pretend that it's non-sRGB 8888: | 342 // so pretend that it's non-sRGB 8888: |
| 339 desc.fConfig = | 343 desc.fConfig = |
| 340 grContext->caps()->srgbSupport() && | 344 grContext->caps()->srgbSupport() && |
| 341 SkImageInfoIsGammaCorrect(info()) && | 345 SkImageInfoIsGammaCorrect(info()) && |
| 342 (attachmentInfo.fColorBits != 30) | 346 (attachmentInfo.fColorBits != 30) |
| 343 ? kSkiaGamma8888_GrPixelConfig : kSkia8888_GrPixelConfig; | 347 ? kSkiaGamma8888_GrPixelConfig : kSkia8888_GrPixelConfig; |
| 344 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 348 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 345 desc.fSampleCnt = attachmentInfo.fSampleCount; | 349 desc.fSampleCnt = attachmentInfo.fSampleCount; |
| 346 desc.fStencilBits = attachmentInfo.fStencilBits; | 350 desc.fStencilBits = attachmentInfo.fStencilBits; |
| 347 GrGLint buffer; | 351 GrGLint buffer; |
| 348 GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer); | 352 GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer); |
| 349 desc.fRenderTargetHandle = buffer; | 353 desc.fRenderTargetHandle = buffer; |
| 350 return grContext->textureProvider()->wrapBackendRenderTarget(desc); | 354 |
| 355 return SkSurface::MakeFromBackendRenderTarget(grContext, desc, &fSurfaceProp
s); |
| 351 } | 356 } |
| 352 | 357 |
| 353 #endif | 358 #endif |
| OLD | NEW |