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

Unified Diff: ui/surface/transport_dib_win.cc

Issue 12537014: Make SharedMemory track the size that was actually mapped (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/surface/transport_dib_mac.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/surface/transport_dib_win.cc
===================================================================
--- ui/surface/transport_dib_win.cc (revision 190994)
+++ ui/surface/transport_dib_win.cc (working copy)
@@ -13,22 +13,20 @@
#include "base/sys_info.h"
#include "skia/ext/platform_canvas.h"
-TransportDIB::TransportDIB() {
+TransportDIB::TransportDIB()
+ : size_(0) {
}
TransportDIB::~TransportDIB() {
}
TransportDIB::TransportDIB(HANDLE handle)
- : shared_memory_(handle, false /* read write */) {
+ : shared_memory_(handle, false /* read write */),
+ size_(0) {
}
// static
TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) {
- size_t allocation_granularity = base::SysInfo::VMAllocationGranularity();
- size = size / allocation_granularity + 1;
- size = size * allocation_granularity;
-
TransportDIB* dib = new TransportDIB;
if (!dib->shared_memory_.CreateAnonymous(size)) {
@@ -70,8 +68,18 @@
// will map it again.
DCHECK(!memory()) << "Mapped file twice in the same process.";
- return skia::CreatePlatformCanvas(w, h, true, handle(),
- skia::RETURN_NULL_ON_FAILURE);
+ // We can't check the canvas size before mapping, but it's safe because
+ // Windows will fail to map the section if the dimensions of the canvas
+ // are too large.
+ skia::PlatformCanvas* canvas =
+ skia::CreatePlatformCanvas(w, h, true, handle(),
+ skia::RETURN_NULL_ON_FAILURE);
+
+ // Calculate the size for the memory region backing the canvas.
+ if (canvas)
+ size_ = skia::PlatformCanvasStrideForWidth(w) * h;
+
+ return canvas;
}
bool TransportDIB::Map() {
@@ -87,11 +95,7 @@
return false;
}
- // There doesn't seem to be any way to find the size of the shared memory
- // region! GetFileSize indicates that the handle is invalid. Thus, we
- // conservatively set the size to the maximum and hope that the renderer
- // isn't about to ask us to read off the end of the array.
- size_ = std::numeric_limits<size_t>::max();
+ size_ = shared_memory_.mapped_size();
return true;
}
« no previous file with comments | « ui/surface/transport_dib_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698