OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 if (!gr) | 54 if (!gr) |
55 return nullptr; | 55 return nullptr; |
56 gr->resetContext(); | 56 gr->resetContext(); |
57 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); | 57 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); |
58 return adoptRef(SkSurface::NewRenderTarget(gr, info, msaaSampleCount)); | 58 return adoptRef(SkSurface::NewRenderTarget(gr, info, msaaSampleCount)); |
59 } | 59 } |
60 | 60 |
61 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(const IntSize& size, OpacityMode opacityMode, int msaaSampleCount) | 61 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(const IntSize& size, OpacityMode opacityMode, int msaaSampleCount) |
62 { | 62 { |
63 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 63 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
64 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createSharedOffscreenGraphicsContext3DProvider()); | 64 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createSharedOffscreenGraphicsContext3DProvider()); |
dshwang
2014/08/16 15:21:28
chromium already did initial bind in createSharedO
| |
65 if (!contextProvider) | 65 if (!contextProvider) |
66 return nullptr; | 66 return nullptr; |
67 RefPtr<SkSurface> surface(createSkSurface(contextProvider->grContext(), size , msaaSampleCount)); | 67 RefPtr<SkSurface> surface(createSkSurface(contextProvider->grContext(), size , msaaSampleCount)); |
68 if (!surface) | 68 if (!surface) |
69 return nullptr; | 69 return nullptr; |
70 RefPtr<Canvas2DLayerBridge> layerBridge; | 70 RefPtr<Canvas2DLayerBridge> layerBridge; |
71 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surface. get())); | 71 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surface. get())); |
72 layerBridge = adoptRef(new Canvas2DLayerBridge(contextProvider.release(), ca nvas.release(), surface.release(), msaaSampleCount, opacityMode)); | 72 layerBridge = adoptRef(new Canvas2DLayerBridge(contextProvider.release(), ca nvas.release(), surface.release(), msaaSampleCount, opacityMode)); |
73 return layerBridge.release(); | 73 return layerBridge.release(); |
74 } | 74 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 { | 215 { |
216 ASSERT(!m_destructionInProgress); | 216 ASSERT(!m_destructionInProgress); |
217 ASSERT(m_layer); | 217 ASSERT(m_layer); |
218 if (!checkSurfaceValid()) { | 218 if (!checkSurfaceValid()) { |
219 if (m_canvas) { | 219 if (m_canvas) { |
220 // drop pending commands because there is no surface to draw to | 220 // drop pending commands because there is no surface to draw to |
221 m_canvas->silentFlush(); | 221 m_canvas->silentFlush(); |
222 } | 222 } |
223 return; | 223 return; |
224 } | 224 } |
225 context()->makeContextCurrent(); | |
226 } | 225 } |
227 | 226 |
228 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted) | 227 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted) |
229 { | 228 { |
230 ASSERT(!m_destructionInProgress); | 229 ASSERT(!m_destructionInProgress); |
231 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; | 230 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; |
232 m_bytesAllocated = bytesAllocated; | 231 m_bytesAllocated = bytesAllocated; |
233 Canvas2DLayerManager::get().layerTransientResourceAllocationChanged(this, de lta); | 232 Canvas2DLayerManager::get().layerTransientResourceAllocationChanged(this, de lta); |
234 } | 233 } |
235 | 234 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 return false; | 400 return false; |
402 } | 401 } |
403 if (!checkSurfaceValid()) | 402 if (!checkSurfaceValid()) |
404 return false; | 403 return false; |
405 | 404 |
406 WebGraphicsContext3D* webContext = context(); | 405 WebGraphicsContext3D* webContext = context(); |
407 | 406 |
408 // Release to skia textures that were previouosly released by the | 407 // Release to skia textures that were previouosly released by the |
409 // compositor. We do this before acquiring the next snapshot in | 408 // compositor. We do this before acquiring the next snapshot in |
410 // order to cap maximum gpu memory consumption. | 409 // order to cap maximum gpu memory consumption. |
411 webContext->makeContextCurrent(); | |
412 flush(); | 410 flush(); |
413 | 411 |
414 RefPtr<SkImage> image = adoptRef(m_canvas->newImageSnapshot()); | 412 RefPtr<SkImage> image = adoptRef(m_canvas->newImageSnapshot()); |
415 | 413 |
416 // Early exit if canvas was not drawn to since last prepareMailbox | 414 // Early exit if canvas was not drawn to since last prepareMailbox |
417 if (image->uniqueID() == m_lastImageId) | 415 if (image->uniqueID() == m_lastImageId) |
418 return false; | 416 return false; |
419 m_lastImageId = image->uniqueID(); | 417 m_lastImageId = image->uniqueID(); |
420 | 418 |
421 MailboxInfo* mailboxInfo = createMailboxInfo(); | 419 MailboxInfo* mailboxInfo = createMailboxInfo(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 565 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
568 // This copy constructor should only be used for Vector reallocation | 566 // This copy constructor should only be used for Vector reallocation |
569 // Assuming 'other' is to be destroyed, we transfer m_image ownership | 567 // Assuming 'other' is to be destroyed, we transfer m_image ownership |
570 // rather than do a refcount dance. | 568 // rather than do a refcount dance. |
571 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 569 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
572 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); | 570 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); |
573 m_status = other.m_status; | 571 m_status = other.m_status; |
574 } | 572 } |
575 | 573 |
576 } // namespace blink | 574 } // namespace blink |
OLD | NEW |